summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_comparator_test.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2016-12-01 12:49:59 -0500
committerDavid Storch <david.storch@10gen.com>2016-12-06 12:58:40 -0500
commit6bee18129c27a82ebcbd316c7900afb04c6f69dc (patch)
treedc980c0ebd7fb41d18ebfe825941ef7c7d3b6628 /src/mongo/db/pipeline/document_comparator_test.cpp
parente30e39ce1a4a55c46db13ad85f6c1000297ea6ff (diff)
downloadmongo-6bee18129c27a82ebcbd316c7900afb04c6f69dc.tar.gz
SERVER-27200 fix CodeWScope comparison to not use collator
Diffstat (limited to 'src/mongo/db/pipeline/document_comparator_test.cpp')
-rw-r--r--src/mongo/db/pipeline/document_comparator_test.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_comparator_test.cpp b/src/mongo/db/pipeline/document_comparator_test.cpp
index 40229e982c1..27e73f7edd6 100644
--- a/src/mongo/db/pipeline/document_comparator_test.cpp
+++ b/src/mongo/db/pipeline/document_comparator_test.cpp
@@ -30,6 +30,8 @@
#include "mongo/db/pipeline/document_comparator.h"
+#include "mongo/bson/bsonmisc.h"
+#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
#include "mongo/unittest/unittest.h"
@@ -165,5 +167,35 @@ TEST(DocumentComparatorTest, NestedArrayEqualityRespectsCollator) {
ASSERT_FALSE(DocumentComparator(&collator).evaluate(doc3 == doc1));
}
+TEST(DocumentComparatorTest, ComparingCodeWScopeShouldNotRespectCollation) {
+ const CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
+ const DocumentComparator comparator(&collator);
+ const Document doc1{{"a",
+ BSONCodeWScope("js code",
+ BSON("foo"
+ << "bar"))}};
+ const Document doc2{{"a",
+ BSONCodeWScope("js code",
+ BSON("foo"
+ << "not bar"))}};
+ ASSERT_TRUE(comparator.evaluate(doc1 != doc2));
+}
+
+TEST(DocumentComparatorTest, HashingCodeWScopeShouldNotRespectCollation) {
+ const CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
+ const Document doc1{{"a",
+ BSONCodeWScope("js code",
+ BSON("foo"
+ << "bar"))}};
+ const Document doc2{{"a",
+ BSONCodeWScope("js code",
+ BSON("foo"
+ << "not bar"))}};
+ size_t seed1, seed2 = 0;
+ doc1.hash_combine(seed1, &collator);
+ doc2.hash_combine(seed2, &collator);
+ ASSERT_NE(seed1, seed2);
+}
+
} // namespace
} // namespace mongo