summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_parser_test.cpp
diff options
context:
space:
mode:
authorBlake Oler <blake.oler@10gen.com>2017-10-09 11:48:26 -0400
committerBlake Oler <blake.oler@10gen.com>2017-10-09 11:48:40 -0400
commit95fedb251673c87b5172269e1f8c116b5e05fb16 (patch)
treec0fbd29a89addfb6bf54d4630c76772abf6c1564 /src/mongo/db/matcher/expression_parser_test.cpp
parentd7a30a716243db13644a16618a939df6bc1344fc (diff)
downloadmongo-95fedb251673c87b5172269e1f8c116b5e05fb16.tar.gz
SERVER-31029 Add support for top-level $expr within $or and $and
Diffstat (limited to 'src/mongo/db/matcher/expression_parser_test.cpp')
-rw-r--r--src/mongo/db/matcher/expression_parser_test.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/mongo/db/matcher/expression_parser_test.cpp b/src/mongo/db/matcher/expression_parser_test.cpp
index 3c8796833b6..e25a322248f 100644
--- a/src/mongo/db/matcher/expression_parser_test.cpp
+++ b/src/mongo/db/matcher/expression_parser_test.cpp
@@ -385,9 +385,49 @@ TEST(MatchExpressionParserTest, ExprParsesSuccessfullyWithAdditionalTopLevelPred
ASSERT_OK(MatchExpressionParser::parse(query, expCtx).getStatus());
}
-TEST(MatchExpressionParserTest, ExprFailsToParseWithinTopLevelOr) {
+TEST(MatchExpressionParserTest, ExprParsesSuccessfullyWithinTopLevelOr) {
auto query = fromjson("{$or: [{x: 1}, {$expr: {$eq: ['$a', 5]}}]}");
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
- ASSERT_NOT_OK(MatchExpressionParser::parse(query, expCtx).getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(
+ query, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::AllowedFeatures::kExpr)
+ .getStatus());
+}
+
+TEST(MatchExpressionParserTest, ExprParsesSuccessfullyWithinTopLevelAnd) {
+ auto query = fromjson("{$and: [{x: 1}, {$expr: {$eq: ['$a', 5]}}]}");
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_OK(
+ MatchExpressionParser::parse(
+ query, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::AllowedFeatures::kExpr)
+ .getStatus());
+}
+
+TEST(MatchExpressionParserTest, ExprFailsToParseWithinElemMatch) {
+ auto query = fromjson("{a: {$elemMatch: {$expr: {$eq: ['$foo', '$bar']}}}}");
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(
+ query, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::AllowedFeatures::kExpr)
+ .getStatus());
+}
+
+TEST(MatchExpressionParserTest, ExprNestedFailsToParseWithinElemMatch) {
+ auto query =
+ fromjson("{a: {$elemMatch: {b: 1, $or: [{$expr: {$eq: ['$foo', '$bar']}}, {c: 1}]}}}");
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(
+ query, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::AllowedFeatures::kExpr)
+ .getStatus());
+}
+
+TEST(MatchExpressionParserTest, ExprFailsToParseWithinInternalSchemaObjectMatch) {
+ auto query = fromjson("{a: {$_internalSchemaObjectMatch: {$expr: {$eq: ['$foo', '$bar']}}}}");
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(
+ query, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::AllowedFeatures::kExpr)
+ .getStatus());
}
}