diff options
| author | Benety Goh <benety@mongodb.com> | 2014-03-06 19:24:59 -0500 |
|---|---|---|
| committer | Benety Goh <benety@mongodb.com> | 2014-03-07 12:26:44 -0500 |
| commit | 765409253203229a2c3577d1d8a3964f7a0d1554 (patch) | |
| tree | 02f4aae294869192ee40328b376fb661698b3946 /src/mongo/db/matcher/expression_parser_array_test.cpp | |
| parent | 0e63bed927440d1531e0a2e26cf5cb79d6b52138 (diff) | |
| download | mongo-765409253203229a2c3577d1d8a3964f7a0d1554.tar.gz | |
SERVER-12981 handle $and/$nor/$or under $elemMatch
Diffstat (limited to 'src/mongo/db/matcher/expression_parser_array_test.cpp')
| -rw-r--r-- | src/mongo/db/matcher/expression_parser_array_test.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_parser_array_test.cpp b/src/mongo/db/matcher/expression_parser_array_test.cpp index e4f2cf23a5e..9230298a019 100644 --- a/src/mongo/db/matcher/expression_parser_array_test.cpp +++ b/src/mongo/db/matcher/expression_parser_array_test.cpp @@ -94,6 +94,51 @@ namespace mongo { } + TEST( MatchExpressionParserArrayTest, ElemMatchAnd ) { + BSONObj query = BSON( "x" << + BSON( "$elemMatch" << + BSON( "$and" << BSON_ARRAY( BSON( "x" << 1 << "y" << 2 ) ) ) ) ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); + ASSERT_TRUE( result.isOK() ); + + ASSERT( !result.getValue()->matchesBSON( BSON( "x" << 1 ) ) ); + ASSERT( !result.getValue()->matchesBSON( BSON( "x" << BSON_ARRAY( 1 << 2 ) ) ) ); + ASSERT( !result.getValue()->matchesBSON( BSON( "x" << BSON_ARRAY( BSON( "x" << 1 ) ) ) ) ); + ASSERT( result.getValue()->matchesBSON( BSON( "x" << + BSON_ARRAY( BSON( "x" << 1 << "y" << 2 ) ) ) ) ); + + } + + TEST( MatchExpressionParserArrayTest, ElemMatchNor ) { + BSONObj query = BSON( "x" << + BSON( "$elemMatch" << + BSON( "$nor" << BSON_ARRAY( BSON( "x" << 1 ) ) ) ) ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); + ASSERT_TRUE( result.isOK() ); + + ASSERT( !result.getValue()->matchesBSON( BSON( "x" << 1 ) ) ); + ASSERT( !result.getValue()->matchesBSON( BSON( "x" << BSON_ARRAY( 1 << 2 ) ) ) ); + ASSERT( !result.getValue()->matchesBSON( BSON( "x" << BSON_ARRAY( BSON( "x" << 1 ) ) ) ) ); + ASSERT( result.getValue()->matchesBSON( BSON( "x" << + BSON_ARRAY( BSON( "x" << 2 << "y" << 2 ) ) ) ) ); + + } + + TEST( MatchExpressionParserArrayTest, ElemMatchOr ) { + BSONObj query = BSON( "x" << + BSON( "$elemMatch" << + BSON( "$or" << BSON_ARRAY( BSON( "x" << 1 << "y" << 2 ) ) ) ) ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); + ASSERT_TRUE( result.isOK() ); + + ASSERT( !result.getValue()->matchesBSON( BSON( "x" << 1 ) ) ); + ASSERT( !result.getValue()->matchesBSON( BSON( "x" << BSON_ARRAY( 1 << 2 ) ) ) ); + ASSERT( !result.getValue()->matchesBSON( BSON( "x" << BSON_ARRAY( BSON( "x" << 1 ) ) ) ) ); + ASSERT( result.getValue()->matchesBSON( BSON( "x" << + BSON_ARRAY( BSON( "x" << 1 << "y" << 2 ) ) ) ) ); + + } + TEST( MatchExpressionParserArrayTest, ElemMatchVal1 ) { BSONObj query = BSON( "x" << BSON( "$elemMatch" << BSON( "$gt" << 5 ) ) ); StatusWithMatchExpression result = MatchExpressionParser::parse( query ); |
