summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_with_placeholder_test.cpp
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2017-08-07 16:50:41 -0400
committerKyle Suarez <kyle.suarez@mongodb.com>2017-08-08 08:53:15 -0400
commitd4ce0f7427e137f1a12b39a0889a468dc2169b6b (patch)
treed2ae23ae0a5530e6c4561044078eda1e6bb4fecb /src/mongo/db/matcher/expression_with_placeholder_test.cpp
parent8962beb1b8f8ca869a9f7ccdc4a7eeab2b84c2f4 (diff)
downloadmongo-d4ce0f7427e137f1a12b39a0889a468dc2169b6b.tar.gz
SERVER-30034 create a $_internalSchemaMatchArrayIndex match expression
Diffstat (limited to 'src/mongo/db/matcher/expression_with_placeholder_test.cpp')
-rw-r--r--src/mongo/db/matcher/expression_with_placeholder_test.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_with_placeholder_test.cpp b/src/mongo/db/matcher/expression_with_placeholder_test.cpp
index a5ee2b45d7a..8fd5f4e456f 100644
--- a/src/mongo/db/matcher/expression_with_placeholder_test.cpp
+++ b/src/mongo/db/matcher/expression_with_placeholder_test.cpp
@@ -178,5 +178,43 @@ TEST(ExpressionWithPlaceholderTest, WhereExpressionFailsToParse) {
ASSERT_NOT_OK(status.getStatus());
}
+TEST(ExpressionWithPlaceholderTest, EquivalentIfPlaceholderAndExpressionMatch) {
+ constexpr auto collator = nullptr;
+ auto rawFilter1 = fromjson("{i: 5}}");
+ auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, collator);
+ ASSERT_OK(expressionWithPlaceholder1.getStatus());
+
+ auto rawFilter2 = fromjson("{i: 5}");
+ auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, collator);
+ ASSERT_OK(expressionWithPlaceholder2.getStatus());
+ ASSERT_TRUE(expressionWithPlaceholder1.getValue()->equivalent(
+ expressionWithPlaceholder2.getValue().get()));
+}
+
+TEST(ExpressionWithPlaceholderTest, NotEquivalentIfPlaceholderDoesNotMatch) {
+ constexpr auto collator = nullptr;
+ auto rawFilter1 = fromjson("{i: {$type: 'array'}}");
+ auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, collator);
+ ASSERT_OK(expressionWithPlaceholder1.getStatus());
+
+ auto rawFilter2 = fromjson("{j: {$type: 'array'}}");
+ auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, collator);
+ ASSERT_OK(expressionWithPlaceholder2.getStatus());
+ ASSERT_FALSE(expressionWithPlaceholder1.getValue()->equivalent(
+ expressionWithPlaceholder2.getValue().get()));
+}
+
+TEST(ExpressionWithPlaceholderTest, NotEquivalentIfExpressionDoesNotMatch) {
+ constexpr auto collator = nullptr;
+ auto rawFilter1 = fromjson("{i: {$lte: 5}}");
+ auto expressionWithPlaceholder1 = ExpressionWithPlaceholder::parse(rawFilter1, collator);
+ ASSERT_OK(expressionWithPlaceholder1.getStatus());
+
+ auto rawFilter2 = fromjson("{i: {$gte: 5}}");
+ auto expressionWithPlaceholder2 = ExpressionWithPlaceholder::parse(rawFilter2, collator);
+ ASSERT_OK(expressionWithPlaceholder2.getStatus());
+ ASSERT_FALSE(expressionWithPlaceholder1.getValue()->equivalent(
+ expressionWithPlaceholder2.getValue().get()));
+}
} // namespace
} // namespace mongo