diff options
author | Blake Oler <blake.oler@10gen.com> | 2017-10-09 11:48:26 -0400 |
---|---|---|
committer | Blake Oler <blake.oler@10gen.com> | 2017-10-09 11:48:40 -0400 |
commit | 95fedb251673c87b5172269e1f8c116b5e05fb16 (patch) | |
tree | c0fbd29a89addfb6bf54d4630c76772abf6c1564 /src/mongo/db/matcher/expression_with_placeholder_test.cpp | |
parent | d7a30a716243db13644a16618a939df6bc1344fc (diff) | |
download | mongo-95fedb251673c87b5172269e1f8c116b5e05fb16.tar.gz |
SERVER-31029 Add support for top-level $expr within $or and $and
Diffstat (limited to 'src/mongo/db/matcher/expression_with_placeholder_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_with_placeholder_test.cpp | 173 |
1 files changed, 86 insertions, 87 deletions
diff --git a/src/mongo/db/matcher/expression_with_placeholder_test.cpp b/src/mongo/db/matcher/expression_with_placeholder_test.cpp index 27a2a1d549c..5644f3e7ac6 100644 --- a/src/mongo/db/matcher/expression_with_placeholder_test.cpp +++ b/src/mongo/db/matcher/expression_with_placeholder_test.cpp @@ -30,6 +30,7 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression_always_boolean.h" +#include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/expression_with_placeholder.h" #include "mongo/db/pipeline/expression_context_for_test.h" #include "mongo/db/query/collation/collator_interface_mock.h" @@ -44,7 +45,8 @@ using unittest::assertGet; TEST(ExpressionWithPlaceholderTest, ParseBasic) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{i: 0}"); - auto filter = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto filter = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT(filter->getPlaceholder()); ASSERT_EQ(*filter->getPlaceholder(), "i"); ASSERT_TRUE(filter->getFilter()->matchesBSON(fromjson("{i: 0}"))); @@ -54,7 +56,8 @@ TEST(ExpressionWithPlaceholderTest, ParseBasic) { TEST(ExpressionWithPlaceholderTest, ParseDottedField) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{'i.a': 0, 'i.b': 1}"); - auto filter = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto filter = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT(filter->getPlaceholder()); ASSERT_EQ(*filter->getPlaceholder(), "i"); ASSERT_TRUE(filter->getFilter()->matchesBSON(fromjson("{i: {a: 0, b: 1}}"))); @@ -64,7 +67,8 @@ TEST(ExpressionWithPlaceholderTest, ParseDottedField) { TEST(ExpressionWithPlaceholderTest, ParseLogicalQuery) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{$and: [{i: {$gte: 0}}, {i: {$lte: 0}}]}"); - auto filter = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto filter = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT(filter->getPlaceholder()); ASSERT_EQ(*filter->getPlaceholder(), "i"); ASSERT_TRUE(filter->getFilter()->matchesBSON(fromjson("{i: 0}"))); @@ -74,7 +78,8 @@ TEST(ExpressionWithPlaceholderTest, ParseLogicalQuery) { TEST(ExpressionWithPlaceholderTest, ParseElemMatch) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{i: {$elemMatch: {a: 0}}}"); - auto filter = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto filter = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT(filter->getPlaceholder()); ASSERT_EQ(*filter->getPlaceholder(), "i"); ASSERT_TRUE(filter->getFilter()->matchesBSON(fromjson("{i: [{a: 0}]}"))); @@ -86,7 +91,8 @@ TEST(ExpressionWithPlaceholderTest, ParseCollation) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); expCtx->setCollator(&collator); auto rawFilter = fromjson("{i: 'abc'}"); - auto filter = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto filter = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT(filter->getPlaceholder()); ASSERT_EQ(*filter->getPlaceholder(), "i"); ASSERT_TRUE(filter->getFilter()->matchesBSON(fromjson("{i: 'cba'}"))); @@ -96,31 +102,27 @@ TEST(ExpressionWithPlaceholderTest, ParseCollation) { TEST(ExpressionWithPlaceholderTest, ParseIdContainsNumbersAndCapitals) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{iA3: 0}"); - auto filter = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto filter = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT(filter->getPlaceholder()); ASSERT_EQ(*filter->getPlaceholder(), "iA3"); ASSERT_TRUE(filter->getFilter()->matchesBSON(fromjson("{'iA3': 0}"))); ASSERT_FALSE(filter->getFilter()->matchesBSON(fromjson("{'iA3': 1}"))); } -TEST(ExpressionWithPlaceholderTest, BadMatchExpressionFailsToParse) { - boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - auto rawFilter = fromjson("{$and: 0}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); - ASSERT_NOT_OK(status.getStatus()); -} - TEST(ExpressionWithPlaceholderTest, EmptyMatchExpressionParsesSuccessfully) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{}"); - auto result = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto result = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT_FALSE(result->getPlaceholder()); } TEST(ExpressionWithPlaceholderTest, NestedEmptyMatchExpressionParsesSuccessfully) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{$or: [{$and: [{}]}]}"); - auto result = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto result = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT_FALSE(result->getPlaceholder()); } @@ -128,7 +130,8 @@ TEST(ExpressionWithPlaceholderTest, NestedMatchExpressionParsesSuccessfullyWhenSomeClausesHaveNoFieldName) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{$or: [{$and: [{}]}, {i: 0}, {i: 1}, {$and: [{}]}]}"); - auto result = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto result = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT(result->getPlaceholder()); ASSERT_EQ(*result->getPlaceholder(), "i"_sd); } @@ -137,133 +140,115 @@ TEST(ExpressionWithPlaceholderTest, SuccessfullyParsesExpressionsWithTypeOther) boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{a: {$_internalSchemaObjectMatch: {$_internalSchemaMinProperties: 5}}}"); - auto result = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto result = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT(result->getPlaceholder()); ASSERT_EQ(*result->getPlaceholder(), "a"_sd); rawFilter = fromjson("{a: {$_internalSchemaType: 'string'}}"); - result = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + result = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT(result->getPlaceholder()); ASSERT_EQ(*result->getPlaceholder(), "a"_sd); rawFilter = fromjson("{$_internalSchemaMinProperties: 1}}"); - result = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + result = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT_FALSE(result->getPlaceholder()); rawFilter = fromjson("{$_internalSchemaCond: [{a: {$exists: true}}, {b: 1}, {c: 1}]}"); - result = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + result = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT_FALSE(result->getPlaceholder()); } TEST(ExpressionWithPlaceholderTest, SuccessfullyParsesAlwaysTrue) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = BSON(AlwaysTrueMatchExpression::kName << 1); - auto result = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = + assertGet(MatchExpressionParser::parse(rawFilter, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::kBanAllSpecialFeatures)); + auto result = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT_FALSE(result->getPlaceholder()); } TEST(ExpressionWithPlaceholderTest, SuccessfullyParsesAlwaysFalse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = BSON(AlwaysFalseMatchExpression::kName << 1); - auto result = assertGet(ExpressionWithPlaceholder::parse(rawFilter, expCtx)); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto result = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter))); ASSERT_FALSE(result->getPlaceholder()); } TEST(ExpressionWithPlaceholderTest, EmptyFieldNameFailsToParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{'': 0}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto status = ExpressionWithPlaceholder::make(std::move(parsedFilter)); ASSERT_NOT_OK(status.getStatus()); } TEST(ExpressionWithPlaceholderTest, EmptyElemMatchFieldNameFailsToParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{'': {$elemMatch: {a: 0}}}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto status = ExpressionWithPlaceholder::make(std::move(parsedFilter)); ASSERT_NOT_OK(status.getStatus()); } TEST(ExpressionWithPlaceholderTest, EmptyTopLevelFieldNameFailsToParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{'.i': 0}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto status = ExpressionWithPlaceholder::make(std::move(parsedFilter)); ASSERT_NOT_OK(status.getStatus()); } TEST(ExpressionWithPlaceholderTest, MultipleTopLevelFieldsFailsToParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{$and: [{i: 0}, {j: 0}]}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto status = ExpressionWithPlaceholder::make(std::move(parsedFilter)); ASSERT_NOT_OK(status.getStatus()); } TEST(ExpressionWithPlaceholderTest, SpecialCharactersInFieldNameFailsToParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{'i&': 0}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto status = ExpressionWithPlaceholder::make(std::move(parsedFilter)); ASSERT_NOT_OK(status.getStatus()); } TEST(ExpressionWithPlaceholderTest, FieldNameStartingWithNumberFailsToParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{'3i': 0}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto status = ExpressionWithPlaceholder::make(std::move(parsedFilter)); ASSERT_NOT_OK(status.getStatus()); } TEST(ExpressionWithPlaceholderTest, FieldNameStartingWithCapitalFailsToParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter = fromjson("{'Ai': 0}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); - ASSERT_NOT_OK(status.getStatus()); -} - -TEST(ExpressionWithPlaceholderTest, TextSearchExpressionFailsToParse) { - boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - auto rawFilter = fromjson("{$text: {$search: 'search terms'}}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); + auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx)); + auto status = ExpressionWithPlaceholder::make(std::move(parsedFilter)); ASSERT_NOT_OK(status.getStatus()); -} - -TEST(ExpressionWithPlaceholderTest, WhereExpressionFailsToParse) { - boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - auto rawFilter = fromjson("{$where: 'sleep(100)'}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); - ASSERT_NOT_OK(status.getStatus()); -} - -TEST(ExpressionWithPlaceholderTest, GeoNearExpressionFailsToParse) { - boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - auto rawFilter = - fromjson("{i: {$nearSphere: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); - ASSERT_NOT_OK(status.getStatus()); -} - -TEST(ExpressionWithPlaceholderTest, ExprExpressionFailsToParse) { - boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - auto rawFilter = fromjson("{$expr: {$eq: ['$i', 5]}}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); - ASSERT_NOT_OK(status.getStatus()); - ASSERT_EQ(status.getStatus().code(), ErrorCodes::QueryFeatureNotAllowed); -} - -TEST(ExpressionWithPlaceholderTest, JSONSchemaExpressionFailsToParse) { - boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - auto rawFilter = fromjson("{$jsonSchema: {}}"); - auto status = ExpressionWithPlaceholder::parse(rawFilter, expCtx); - ASSERT_NOT_OK(status.getStatus()); - ASSERT_EQ(status.getStatus().code(), ErrorCodes::QueryFeatureNotAllowed); + ASSERT_EQ(status.getStatus().code(), ErrorCodes::BadValue); } TEST(ExpressionWithPlaceholderTest, EquivalentIfPlaceholderAndExpressionMatch) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter1 = fromjson("{i: 5}}"); - auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, expCtx); + auto parsedFilter1 = assertGet(MatchExpressionParser::parse(rawFilter1, expCtx)); + auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::make(std::move(parsedFilter1)); ASSERT_OK(expressionWithPlaceholder1.getStatus()); auto rawFilter2 = fromjson("{i: 5}"); - auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, expCtx); + auto parsedFilter2 = assertGet(MatchExpressionParser::parse(rawFilter2, expCtx)); + auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::make(std::move(parsedFilter2)); ASSERT_OK(expressionWithPlaceholder2.getStatus()); ASSERT_TRUE(expressionWithPlaceholder1.getValue()->equivalent( expressionWithPlaceholder2.getValue().get())); @@ -272,26 +257,30 @@ TEST(ExpressionWithPlaceholderTest, EquivalentIfPlaceholderAndExpressionMatch) { TEST(ExpressionWithPlaceholderTest, EmptyMatchExpressionsAreEquivalent) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter1 = fromjson("{}"); - auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, expCtx); + auto parsedFilter1 = assertGet(MatchExpressionParser::parse(rawFilter1, expCtx)); + auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::make(std::move(parsedFilter1)); ASSERT_OK(expressionWithPlaceholder1.getStatus()); auto rawFilter2 = fromjson("{}"); - auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, expCtx); + auto parsedFilter2 = assertGet(MatchExpressionParser::parse(rawFilter2, expCtx)); + auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::make(std::move(parsedFilter2)); ASSERT_OK(expressionWithPlaceholder2.getStatus()); - ASSERT(expressionWithPlaceholder1.getValue()->equivalent( + ASSERT_TRUE(expressionWithPlaceholder1.getValue()->equivalent( expressionWithPlaceholder2.getValue().get())); } TEST(ExpressionWithPlaceholderTest, NestedEmptyMatchExpressionsAreEquivalent) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter1 = fromjson("{$or: [{$and: [{}]}]}"); - auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, expCtx); + auto parsedFilter1 = assertGet(MatchExpressionParser::parse(rawFilter1, expCtx)); + auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::make(std::move(parsedFilter1)); ASSERT_OK(expressionWithPlaceholder1.getStatus()); auto rawFilter2 = fromjson("{$or: [{$and: [{}]}]}"); - auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, expCtx); + auto parsedFilter2 = assertGet(MatchExpressionParser::parse(rawFilter2, expCtx)); + auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::make(std::move(parsedFilter2)); ASSERT_OK(expressionWithPlaceholder2.getStatus()); - ASSERT(expressionWithPlaceholder1.getValue()->equivalent( + ASSERT_TRUE(expressionWithPlaceholder1.getValue()->equivalent( expressionWithPlaceholder2.getValue().get())); } @@ -299,38 +288,44 @@ TEST(ExpressionWithPlaceholderTest, SameObjectMatchesAreEquivalent) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter1 = fromjson("{a: {$_internalSchemaObjectMatch: {$_internalSchemaMaxProperties: 2}}}"); - auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, expCtx); + auto parsedFilter1 = assertGet(MatchExpressionParser::parse(rawFilter1, expCtx)); + auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::make(std::move(parsedFilter1)); ASSERT_OK(expressionWithPlaceholder1.getStatus()); auto rawFilter2 = fromjson("{a: {$_internalSchemaObjectMatch: {$_internalSchemaMaxProperties: 2}}}"); - auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, expCtx); + auto parsedFilter2 = assertGet(MatchExpressionParser::parse(rawFilter2, expCtx)); + auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::make(std::move(parsedFilter2)); ASSERT_OK(expressionWithPlaceholder2.getStatus()); - ASSERT(expressionWithPlaceholder1.getValue()->equivalent( + ASSERT_TRUE(expressionWithPlaceholder1.getValue()->equivalent( expressionWithPlaceholder2.getValue().get())); } TEST(ExpressionWithPlaceholderTest, AlwaysTruesAreEquivalent) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter1 = BSON(AlwaysTrueMatchExpression::kName << 1); - auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, expCtx); + auto parsedFilter1 = assertGet(MatchExpressionParser::parse(rawFilter1, expCtx)); + auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::make(std::move(parsedFilter1)); ASSERT_OK(expressionWithPlaceholder1.getStatus()); auto rawFilter2 = BSON(AlwaysTrueMatchExpression::kName << 1); - auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, expCtx); + auto parsedFilter2 = assertGet(MatchExpressionParser::parse(rawFilter2, expCtx)); + auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::make(std::move(parsedFilter2)); ASSERT_OK(expressionWithPlaceholder2.getStatus()); - ASSERT(expressionWithPlaceholder1.getValue()->equivalent( + ASSERT_TRUE(expressionWithPlaceholder1.getValue()->equivalent( expressionWithPlaceholder2.getValue().get())); } TEST(ExpressionWithPlaceholderTest, NotEquivalentIfPlaceholderDoesNotMatch) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter1 = fromjson("{i: {$type: 'array'}}"); - auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, expCtx); + auto parsedFilter1 = assertGet(MatchExpressionParser::parse(rawFilter1, expCtx)); + auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::make(std::move(parsedFilter1)); ASSERT_OK(expressionWithPlaceholder1.getStatus()); auto rawFilter2 = fromjson("{j: {$type: 'array'}}"); - auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, expCtx); + auto parsedFilter2 = assertGet(MatchExpressionParser::parse(rawFilter2, expCtx)); + auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::make(std::move(parsedFilter2)); ASSERT_OK(expressionWithPlaceholder2.getStatus()); ASSERT_FALSE(expressionWithPlaceholder1.getValue()->equivalent( expressionWithPlaceholder2.getValue().get())); @@ -339,11 +334,13 @@ TEST(ExpressionWithPlaceholderTest, NotEquivalentIfPlaceholderDoesNotMatch) { TEST(ExpressionWithPlaceholder, NotEquivalentIfOnePlaceholderIsEmpty) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter1 = fromjson("{}"); - auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, expCtx); + auto parsedFilter1 = assertGet(MatchExpressionParser::parse(rawFilter1, expCtx)); + auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::make(std::move(parsedFilter1)); ASSERT_OK(expressionWithPlaceholder1.getStatus()); auto rawFilter2 = fromjson("{i: 5}"); - auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, expCtx); + auto parsedFilter2 = assertGet(MatchExpressionParser::parse(rawFilter2, expCtx)); + auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::make(std::move(parsedFilter2)); ASSERT_OK(expressionWithPlaceholder2.getStatus()); ASSERT_FALSE(expressionWithPlaceholder1.getValue()->equivalent( expressionWithPlaceholder2.getValue().get())); @@ -352,11 +349,13 @@ TEST(ExpressionWithPlaceholder, NotEquivalentIfOnePlaceholderIsEmpty) { TEST(ExpressionWithPlaceholderTest, NotEquivalentIfExpressionDoesNotMatch) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto rawFilter1 = fromjson("{i: {$lte: 5}}"); - auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, expCtx); + auto parsedFilter1 = assertGet(MatchExpressionParser::parse(rawFilter1, expCtx)); + auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::make(std::move(parsedFilter1)); ASSERT_OK(expressionWithPlaceholder1.getStatus()); auto rawFilter2 = fromjson("{i: {$gte: 5}}"); - auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, expCtx); + auto parsedFilter2 = assertGet(MatchExpressionParser::parse(rawFilter2, expCtx)); + auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::make(std::move(parsedFilter2)); ASSERT_OK(expressionWithPlaceholder2.getStatus()); ASSERT_FALSE(expressionWithPlaceholder1.getValue()->equivalent( expressionWithPlaceholder2.getValue().get())); |