summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_parser_test.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2017-07-12 13:37:24 -0400
committerDavid Storch <david.storch@10gen.com>2017-07-17 16:21:14 -0400
commitb86c6bcba36785122e4ad1d228e7a2a8602c40b4 (patch)
treee6573db10f1a603669eb121e4c4fc22e23a43882 /src/mongo/db/matcher/expression_parser_test.cpp
parentd85cadf3e1bede6c726699e0dc81d3dbe2daefb7 (diff)
downloadmongo-b86c6bcba36785122e4ad1d228e7a2a8602c40b4.tar.gz
SERVER-29571 Parse a subset of $jsonSchema into a MatchExpression.
Adds support for $jsonSchema containing only the following JSON Schema keywords: - type - properties - maximum
Diffstat (limited to 'src/mongo/db/matcher/expression_parser_test.cpp')
-rw-r--r--src/mongo/db/matcher/expression_parser_test.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_parser_test.cpp b/src/mongo/db/matcher/expression_parser_test.cpp
index 16b66cce0f7..bc047818622 100644
--- a/src/mongo/db/matcher/expression_parser_test.cpp
+++ b/src/mongo/db/matcher/expression_parser_test.cpp
@@ -192,6 +192,29 @@ TEST(MatchExpressionParserTest, ParseIntegerElementToLongAcceptsThree) {
ASSERT_EQ(result.getValue(), 3LL);
}
+TEST(MatchExpressionParserTest, ParseTypeFromAliasCanParseNumberAlias) {
+ auto result = MatchExpressionParser::parseTypeFromAlias("a", "number");
+ ASSERT_OK(result.getStatus());
+ ASSERT_EQ(result.getValue()->path(), "a");
+ ASSERT_TRUE(result.getValue()->getType().allNumbers);
+ ASSERT_TRUE(result.getValue()->matchesAllNumbers());
+}
+
+TEST(MatchExpressionParserTest, ParseTypeFromAliasCanParseLongAlias) {
+ auto result = MatchExpressionParser::parseTypeFromAlias("a", "long");
+ ASSERT_OK(result.getStatus());
+ ASSERT_EQ(result.getValue()->path(), "a");
+ ASSERT_FALSE(result.getValue()->getType().allNumbers);
+ ASSERT_FALSE(result.getValue()->matchesAllNumbers());
+ ASSERT_EQ(result.getValue()->getType().bsonType, BSONType::NumberLong);
+ ASSERT_EQ(result.getValue()->getBSONType(), BSONType::NumberLong);
+}
+
+TEST(MatchExpressionParserTest, ParseTypeFromAliasFailsToParseUnknownAlias) {
+ auto result = MatchExpressionParser::parseTypeFromAlias("a", "unknown");
+ ASSERT_NOT_OK(result.getStatus());
+}
+
StatusWith<int> fib(int n) {
if (n < 0)
return StatusWith<int>(ErrorCodes::BadValue, "paramter to fib has to be >= 0");