diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2017-08-24 15:13:53 -0400 |
---|---|---|
committer | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2017-08-30 14:02:40 -0400 |
commit | d6bf4c26878a61513b0a1cc92e2955330a02d0a8 (patch) | |
tree | 03b98812bc154708157e370b167386cd0eed27a2 /src/mongo/db/matcher/expression_serialization_test.cpp | |
parent | 292a7016e0896c93a740c8535de5418633c13148 (diff) | |
download | mongo-d6bf4c26878a61513b0a1cc92e2955330a02d0a8.tar.gz |
SERVER-30664: extend ExpressionWithPlaceholder to accept more expressions
Diffstat (limited to 'src/mongo/db/matcher/expression_serialization_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_serialization_test.cpp | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/src/mongo/db/matcher/expression_serialization_test.cpp b/src/mongo/db/matcher/expression_serialization_test.cpp index a7e8b4403e3..2fb9fd6dc22 100644 --- a/src/mongo/db/matcher/expression_serialization_test.cpp +++ b/src/mongo/db/matcher/expression_serialization_test.cpp @@ -1585,14 +1585,13 @@ TEST(SerializeInternalSchema, ExpressionInternalSchemaCondSerializesCorrectly) { TEST(SerializeInternalSchema, ExpressionInternalSchemaMinPropertiesSerializesCorrectly) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - const CollatorInterface* collator = nullptr; Matcher original(fromjson("{$_internalSchemaMinProperties: 1}"), - collator, + kSimpleCollator, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::kAllowAllSpecialFeatures); Matcher reserialized(serialize(original.getMatchExpression()), - collator, + kSimpleCollator, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::kAllowAllSpecialFeatures); @@ -1602,14 +1601,13 @@ TEST(SerializeInternalSchema, ExpressionInternalSchemaMinPropertiesSerializesCor TEST(SerializeInternalSchema, ExpressionInternalSchemaMaxPropertiesSerializesCorrectly) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - const CollatorInterface* collator = nullptr; Matcher original(fromjson("{$_internalSchemaMaxProperties: 1}"), - collator, + kSimpleCollator, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::kAllowAllSpecialFeatures); Matcher reserialized(serialize(original.getMatchExpression()), - collator, + kSimpleCollator, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::kAllowAllSpecialFeatures); @@ -1643,15 +1641,14 @@ TEST(SerializeInternalSchema, ExpressionInternalSchemaFmodSerializesCorrectly) { TEST(SerializeInternalSchema, ExpressionInternalSchemaMatchArrayIndexSerializesCorrectly) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - constexpr CollatorInterface* collator = nullptr; Matcher original(fromjson("{a: {$_internalSchemaMatchArrayIndex:" "{index: 2, namePlaceholder: 'i', expression: {i: {$lt: 3}}}}}"), - collator, + kSimpleCollator, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::kAllowAllSpecialFeatures); Matcher reserialized(serialize(original.getMatchExpression()), - collator, + kSimpleCollator, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::kAllowAllSpecialFeatures); @@ -1662,14 +1659,22 @@ TEST(SerializeInternalSchema, ExpressionInternalSchemaMatchArrayIndexSerializesC } TEST(SerializeInternalSchema, ExpressionInternalSchemaAllowedPropertiesSerializesCorrectly) { + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); Matcher original(fromjson(R"({$_internalSchemaAllowedProperties: { properties: ['a'], otherwise: {i: {$gt: 10}}, namePlaceholder: 'i', patternProperties: [{regex: /b/, expression: {i: {$type: 'number'}}}] }})"), - kSimpleCollator); - Matcher reserialized(serialize(original.getMatchExpression()), kSimpleCollator); + kSimpleCollator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::kAllowAllSpecialFeatures); + Matcher reserialized(serialize(original.getMatchExpression()), + kSimpleCollator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::kAllowAllSpecialFeatures); ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson(R"({$_internalSchemaAllowedProperties: { properties: ['a'], namePlaceholder: 'i', @@ -1678,5 +1683,32 @@ TEST(SerializeInternalSchema, ExpressionInternalSchemaAllowedPropertiesSerialize }})")); ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression())); } + +TEST(SerializeInternalSchema, + ExpressionInternalSchemaAllowedPropertiesEmptyOtherwiseSerializesCorrectly) { + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + Matcher original(fromjson(R"({$_internalSchemaAllowedProperties: { + properties: [], + otherwise: {}, + namePlaceholder: 'i', + patternProperties: [] + }})"), + kSimpleCollator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::kAllowAllSpecialFeatures); + Matcher reserialized(serialize(original.getMatchExpression()), + kSimpleCollator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::kAllowAllSpecialFeatures); + ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson(R"({$_internalSchemaAllowedProperties: { + properties: [], + namePlaceholder: 'i', + patternProperties: [], + otherwise: {} + }})")); + ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression())); +} } // namespace } // namespace mongo |