Skip to content

Commit

Permalink
Unittest Antlr Parser for Stdev Agg Expression
Browse files Browse the repository at this point in the history
  • Loading branch information
ullingerc committed Nov 12, 2024
1 parent c85701c commit 091806e
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions test/SparqlAntlrParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,22 @@ ::testing::Matcher<const SparqlExpression::Ptr&> matchAggregate(
AD_PROPERTY(Exp, children, ElementsAre(variableExpressionMatcher(child))),
WhenDynamicCastTo<const AggregateExpr&>(innerMatcher)));
}

// Return a matcher that checks whether a given `SparqlExpression::Ptr` actually
// points to an `AggregateExpr` and that the distinctness of the aggregate
// expression matches. It does not check the child. This is required to test
// aggregates that implicitly replace their child, like `StdevExpression`.
template <typename AggregateExpr>
::testing::Matcher<const SparqlExpression::Ptr&> matchAggregateWithoutChild(
bool distinct) {
using namespace ::testing;
using namespace builtInCallTestHelpers;
using Exp = SparqlExpression;

using enum SparqlExpression::AggregateStatus;
auto aggregateStatus = distinct ? DistinctAggregate : NonDistinctAggregate;
return Pointee(AD_PROPERTY(Exp, isAggregate, Eq(aggregateStatus)));
}
} // namespace aggregateTestHelpers

// ___________________________________________________________
Expand Down Expand Up @@ -1927,14 +1943,15 @@ TEST(SparqlParser, aggregateExpressions) {
matchAggregate<GroupConcatExpression>(true, V{"?x"}, separator(";")));

// The STDEV expression
// TODO<ullingec> Test failing because StdevExpression replaces its child

// expectAggregate("STDEV(?x)", matchAggregate<StdevExpression>(false,
// V{"?x"})); expectAggregate("stdev(?x)",
// matchAggregate<StdevExpression>(false, V{"?x"})); A distinct stdev is
// probably not very useful, but should be possible anyway
// expectAggregate("STDEV(DISTINCT ?x)",
// matchAggregate<StdevExpression>(true, V{"?x"}));
// Here we don't match the child, because StdevExpression replaces it with a
// DeviationExpression.
expectAggregate("STDEV(?x)",
matchAggregateWithoutChild<StdevExpression>(false));
expectAggregate("stdev(?x)",
matchAggregateWithoutChild<StdevExpression>(false));
// A distinct stdev is probably not very useful, but should be possible anyway
expectAggregate("STDEV(DISTINCT ?x)",
matchAggregateWithoutChild<StdevExpression>(true));
}

TEST(SparqlParser, Quads) {
Expand Down

0 comments on commit 091806e

Please sign in to comment.