diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-10-02 17:24:03 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-10-05 16:47:26 -0400 |
commit | cb9f7cdcb7eb6ad9077ac8af3a4c0d7275c7e34f (patch) | |
tree | 24fea4c596a4652a457bc496d34a5590b7882190 /src/mongo/db/matcher/expression_expr_test.cpp | |
parent | e02285559b5f15be6afbf876f169874bd9008b0b (diff) | |
download | mongo-cb9f7cdcb7eb6ad9077ac8af3a4c0d7275c7e34f.tar.gz |
SERVER-30731 Add expr support in MatchExpression outside of aggregation
Diffstat (limited to 'src/mongo/db/matcher/expression_expr_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_expr_test.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_expr_test.cpp b/src/mongo/db/matcher/expression_expr_test.cpp index 3ad0ac4340e..e89ef9a5c39 100644 --- a/src/mongo/db/matcher/expression_expr_test.cpp +++ b/src/mongo/db/matcher/expression_expr_test.cpp @@ -32,12 +32,15 @@ #include "mongo/db/matcher/expression_expr.h" #include "mongo/db/matcher/matcher.h" #include "mongo/db/pipeline/expression_context_for_test.h" +#include "mongo/db/query/collation/collator_interface_mock.h" #include "mongo/unittest/unittest.h" namespace mongo { namespace { +using unittest::assertGet; + TEST(ExprMatchExpression, ComparisonToConstantMatchesCorrectly) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto match = BSON("a" << 5); @@ -148,5 +151,25 @@ TEST(ExprMatchExpression, ShallowClonedExpressionIsEquivalentToOriginal) { ASSERT_TRUE(pipelineExpr.equivalent(shallowClone.get())); } +TEST(ExprMatchExpression, SetCollatorChangesCollationUsedForComparisons) { + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + auto match = BSON("a" + << "abc"); + auto notMatch = BSON("a" + << "ABC"); + + auto expression = BSON("$expr" << BSON("$eq" << BSON_ARRAY("$a" + << "abc"))); + auto matchExpression = assertGet(MatchExpressionParser::parse(expression, expCtx)); + ASSERT_TRUE(matchExpression->matchesBSON(match)); + ASSERT_FALSE(matchExpression->matchesBSON(notMatch)); + + CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); + matchExpression->setCollator(&collator); + + ASSERT_TRUE(matchExpression->matchesBSON(match)); + ASSERT_TRUE(matchExpression->matchesBSON(notMatch)); +} + } // namespace } // namespace mongo |