diff options
author | David Storch <david.storch@10gen.com> | 2016-02-16 10:19:08 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2016-02-22 09:57:10 -0500 |
commit | 379a6993695c0468b0e08704aa46760db986744f (patch) | |
tree | bf43baf3016ee7c68ab82ff83498d73b089c0755 | |
parent | cedea56a9fbd65ad8ecf42828ceb9cc639e03bc8 (diff) | |
download | mongo-379a6993695c0468b0e08704aa46760db986744f.tar.gz |
SERVER-22626 fix $type unit tests
(cherry picked from commit 3862a9dbaf9a2c6a8131f674f5bde70793255049)
Conflicts:
src/mongo/db/matcher/expression_leaf_test.cpp
src/mongo/db/matcher/expression_parser_leaf_test.cpp
-rw-r--r-- | src/mongo/bson/bsontypes.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/matcher/expression_leaf_test.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/matcher/expression_parser_leaf_test.cpp | 11 |
3 files changed, 8 insertions, 16 deletions
diff --git a/src/mongo/bson/bsontypes.cpp b/src/mongo/bson/bsontypes.cpp index 7b94028e996..29b0207c992 100644 --- a/src/mongo/bson/bsontypes.cpp +++ b/src/mongo/bson/bsontypes.cpp @@ -114,7 +114,9 @@ bool isValidBSONType(int type) { case NumberInt: case bsonTimestamp: case NumberLong: +#ifdef MONGO_CONFIG_EXPERIMENTAL_DECIMAL_SUPPORT case NumberDecimal: +#endif case MaxKey: return true; default: diff --git a/src/mongo/db/matcher/expression_leaf_test.cpp b/src/mongo/db/matcher/expression_leaf_test.cpp index 0a9088826e6..b2946f5f546 100644 --- a/src/mongo/db/matcher/expression_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_leaf_test.cpp @@ -1373,16 +1373,9 @@ TEST(TypeMatchExpression, MatchesElementNumber) { ASSERT_FALSE(type.matchesSingleElement(notMatch["a"])); } -TEST(TypeMatchExpression, InvalidTypeMatchExpressionerand) { - // If the provided type number is not a valid BSONType, it is not a parse error. The - // operator will simply not match anything. - BSONObj notMatch1 = BSON("a" << BSONNULL); - BSONObj notMatch2 = BSON("a" - << "abc"); +TEST(TypeMatchExpression, InvalidTypeMatchExpressionTypeCode) { TypeMatchExpression type; - ASSERT(type.initWithBSONType("", BSONType(JSTypeMax + 1)).isOK()); - ASSERT(!type.matchesSingleElement(notMatch1["a"])); - ASSERT(!type.matchesSingleElement(notMatch2["a"])); + ASSERT_NOT_OK(type.initWithBSONType("", JSTypeMax + 1)); } TEST(TypeMatchExpression, MatchesScalar) { diff --git a/src/mongo/db/matcher/expression_parser_leaf_test.cpp b/src/mongo/db/matcher/expression_parser_leaf_test.cpp index 6efc994a86b..0430d6c9442 100644 --- a/src/mongo/db/matcher/expression_parser_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_parser_leaf_test.cpp @@ -637,10 +637,7 @@ TEST(MatchExpressionParserLeafTest, TypeBadType) { b.append("$type", (JSTypeMax + 1)); BSONObj query = BSON("x" << b.obj()); StatusWithMatchExpression result = MatchExpressionParser::parse(query); - ASSERT_TRUE(result.isOK()); - - ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5.3))); - ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5))); + ASSERT_NOT_OK(result.getStatus()); } TEST(MatchExpressionParserLeafTest, TypeBad) { @@ -796,9 +793,9 @@ TEST(MatchExpressionParserLeafTest, InvalidTypeCodeUnusedBetweenMinAndMaxFailsTo TEST(MatchExpressionParserLeafTest, ValidTypeCodesParseSuccessfully) { std::vector<BSONType> validTypes{ - MinKey, EOO, NumberDouble, String, Object, Array, BinData, Undefined, - jstOID, Bool, Date, jstNULL, RegEx, DBRef, Code, Symbol, - CodeWScope, NumberInt, bsonTimestamp, NumberLong, NumberDecimal, MaxKey}; + MinKey, EOO, NumberDouble, String, Object, Array, BinData, + Undefined, jstOID, Bool, Date, jstNULL, RegEx, DBRef, + Code, Symbol, CodeWScope, NumberInt, bsonTimestamp, NumberLong, MaxKey}; for (auto type : validTypes) { BSONObj predicate = BSON("a" << BSON("$type" << type)); |