diff options
Diffstat (limited to 'src/mongo/db/matcher/expression_parser_leaf_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_parser_leaf_test.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_parser_leaf_test.cpp b/src/mongo/db/matcher/expression_parser_leaf_test.cpp index cb1cd8ff375..c5650c25d67 100644 --- a/src/mongo/db/matcher/expression_parser_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_parser_leaf_test.cpp @@ -38,6 +38,7 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression.h" #include "mongo/db/matcher/expression_leaf.h" +#include "mongo/platform/decimal128.h" #include "mongo/util/log.h" namespace mongo { @@ -608,6 +609,17 @@ TEST(MatchExpressionParserLeafTest, TypeDoubleOperator) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5))); } +TEST(MatchExpressionParserLeafTest, TypeDecimalOperator) { + if (Decimal128::enabled) { + BSONObj query = BSON("x" << BSON("$type" << mongo::NumberDecimal)); + StatusWithMatchExpression result = MatchExpressionParser::parse(query); + ASSERT_TRUE(result.isOK()); + + ASSERT_FALSE(result.getValue()->matchesBSON(BSON("x" << 5.3))); + ASSERT_TRUE(result.getValue()->matchesBSON(BSON("x" << mongo::Decimal128("1")))); + } +} + TEST(MatchExpressionParserLeafTest, TypeNull) { BSONObj query = BSON("x" << BSON("$type" << jstNULL)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); @@ -657,6 +669,19 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameDouble) { ASSERT_FALSE(tmeNumberDouble->matchesBSON(fromjson("{a: NumberInt(5)}"))); } +TEST(MatchExpressionParserLeafTest, TypeStringNameNumberDecimal) { + if (Decimal128::enabled) { + StatusWithMatchExpression typeNumberDecimal = + MatchExpressionParser::parse(fromjson("{a: {$type: 'decimal'}}")); + ASSERT_OK(typeNumberDecimal.getStatus()); + TypeMatchExpression* tmeNumberDecimal = + static_cast<TypeMatchExpression*>(typeNumberDecimal.getValue().get()); + ASSERT(tmeNumberDecimal->getType() == NumberDecimal); + ASSERT_TRUE(tmeNumberDecimal->matchesBSON(BSON("a" << mongo::Decimal128("1")))); + ASSERT_FALSE(tmeNumberDecimal->matchesBSON(fromjson("{a: true}"))); + } +} + TEST(MatchExpressionParserLeafTest, TypeStringnameNumberInt) { StatusWithMatchExpression typeNumberInt = MatchExpressionParser::parse(fromjson("{a: {$type: 'int'}}")); |