diff options
Diffstat (limited to 'src/mongo/db/matcher/expression_leaf_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_leaf_test.cpp | 682 |
1 files changed, 341 insertions, 341 deletions
diff --git a/src/mongo/db/matcher/expression_leaf_test.cpp b/src/mongo/db/matcher/expression_leaf_test.cpp index be3255b0838..f6db53166c9 100644 --- a/src/mongo/db/matcher/expression_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_leaf_test.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/** Unit tests for MatchExpression operator implementations in match_operators.{h,cpp}. */ +/** Unit tests for MatchMatchExpression operator implementations in match_operators.{h,cpp}. */ #include "mongo/unittest/unittest.h" @@ -30,8 +30,8 @@ namespace mongo { BSONObj match = BSON( "a" << 5.0 ); BSONObj notMatch = BSON( "a" << 6 ); - ComparisonExpression eq; - eq.init( "", ComparisonExpression::EQ, operand["a"] ); + ComparisonMatchExpression eq; + eq.init( "", ComparisonMatchExpression::EQ, operand["a"] ); ASSERT( eq.matchesSingleElement( match.firstElement() ) ); ASSERT( !eq.matchesSingleElement( notMatch.firstElement() ) ); } @@ -39,30 +39,30 @@ namespace mongo { TEST( EqOp, InvalidEooOperand ) { BSONObj operand; - ComparisonExpression eq; - ASSERT( !eq.init( "", ComparisonExpression::EQ, operand.firstElement() ).isOK() ); + ComparisonMatchExpression eq; + ASSERT( !eq.init( "", ComparisonMatchExpression::EQ, operand.firstElement() ).isOK() ); } TEST( EqOp, MatchesScalar ) { BSONObj operand = BSON( "a" << 5 ); - ComparisonExpression eq; - eq.init( "a", ComparisonExpression::EQ, operand[ "a" ] ); + ComparisonMatchExpression eq; + eq.init( "a", ComparisonMatchExpression::EQ, operand[ "a" ] ); ASSERT( eq.matches( BSON( "a" << 5.0 ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << 4 ), NULL ) ); } TEST( EqOp, MatchesArrayValue ) { BSONObj operand = BSON( "a" << 5 ); - ComparisonExpression eq; - eq.init( "a", ComparisonExpression::EQ, operand[ "a" ] ); + ComparisonMatchExpression eq; + eq.init( "a", ComparisonMatchExpression::EQ, operand[ "a" ] ); ASSERT( eq.matches( BSON( "a" << BSON_ARRAY( 5.0 << 6 ) ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << BSON_ARRAY( 6 << 7 ) ), NULL ) ); } TEST( EqOp, MatchesReferencedObjectValue ) { BSONObj operand = BSON( "a.b" << 5 ); - ComparisonExpression eq; - eq.init( "a.b", ComparisonExpression::EQ, operand[ "a.b" ] ); + ComparisonMatchExpression eq; + eq.init( "a.b", ComparisonMatchExpression::EQ, operand[ "a.b" ] ); ASSERT( eq.matches( BSON( "a" << BSON( "b" << 5 ) ), NULL ) ); ASSERT( eq.matches( BSON( "a" << BSON( "b" << BSON_ARRAY( 5 ) ) ), NULL ) ); ASSERT( eq.matches( BSON( "a" << BSON_ARRAY( BSON( "b" << 5 ) ) ), NULL ) ); @@ -70,16 +70,16 @@ namespace mongo { TEST( EqOp, MatchesReferencedArrayValue ) { BSONObj operand = BSON( "a.0" << 5 ); - ComparisonExpression eq; - eq.init( "a.0", ComparisonExpression::EQ, operand[ "a.0" ] ); + ComparisonMatchExpression eq; + eq.init( "a.0", ComparisonMatchExpression::EQ, operand[ "a.0" ] ); ASSERT( eq.matches( BSON( "a" << BSON_ARRAY( 5 ) ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << BSON_ARRAY( BSON_ARRAY( 5 ) ) ), NULL ) ); } TEST( EqOp, MatchesNull ) { BSONObj operand = BSON( "a" << BSONNULL ); - ComparisonExpression eq; - eq.init( "a", ComparisonExpression::EQ, operand[ "a" ] ); + ComparisonMatchExpression eq; + eq.init( "a", ComparisonMatchExpression::EQ, operand[ "a" ] ); ASSERT( eq.matches( BSONObj(), NULL ) ); ASSERT( eq.matches( BSON( "a" << BSONNULL ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << 4 ), NULL ) ); @@ -87,8 +87,8 @@ namespace mongo { TEST( EqOp, MatchesMinKey ) { BSONObj operand = BSON( "a" << MinKey ); - ComparisonExpression eq; - eq.init( "a", ComparisonExpression::EQ, operand[ "a" ] ); + ComparisonMatchExpression eq; + eq.init( "a", ComparisonMatchExpression::EQ, operand[ "a" ] ); ASSERT( eq.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << 4 ), NULL ) ); @@ -98,8 +98,8 @@ namespace mongo { TEST( EqOp, MatchesMaxKey ) { BSONObj operand = BSON( "a" << MaxKey ); - ComparisonExpression eq; - ASSERT( eq.init( "a", ComparisonExpression::EQ, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression eq; + ASSERT( eq.init( "a", ComparisonMatchExpression::EQ, operand[ "a" ] ).isOK() ); ASSERT( eq.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << 4 ), NULL ) ); @@ -107,8 +107,8 @@ namespace mongo { TEST( EqOp, MatchesFullArray ) { BSONObj operand = BSON( "a" << BSON_ARRAY( 1 << 2 ) ); - ComparisonExpression eq; - ASSERT( eq.init( "a", ComparisonExpression::EQ, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression eq; + ASSERT( eq.init( "a", ComparisonMatchExpression::EQ, operand[ "a" ] ).isOK() ); ASSERT( eq.matches( BSON( "a" << BSON_ARRAY( 1 << 2 ) ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << BSON_ARRAY( 1 << 2 << 3 ) ), NULL ) ); ASSERT( !eq.matches( BSON( "a" << BSON_ARRAY( 1 ) ), NULL ) ); @@ -117,8 +117,8 @@ namespace mongo { TEST( EqOp, ElemMatchKey ) { BSONObj operand = BSON( "a" << 5 ); - ComparisonExpression eq; - ASSERT( eq.init( "a", ComparisonExpression::EQ, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression eq; + ASSERT( eq.init( "a", ComparisonMatchExpression::EQ, operand[ "a" ] ).isOK() ); MatchDetails details; details.requestElemMatchKey(); ASSERT( !eq.matches( BSON( "a" << 4 ), &details ) ); @@ -133,49 +133,49 @@ namespace mongo { /** TEST( EqOp, MatchesIndexKeyScalar ) { BSONObj operand = BSON( "a" << 6 ); - ComparisonExpression eq; - ASSERT( eq.init( "a", ComparisonExpression::EQ, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression eq; + ASSERT( eq.init( "a", ComparisonMatchExpression::EQ, operand[ "a" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == eq.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == eq.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == eq.matchesIndexKey( BSON( "" << BSON_ARRAY( 6 ) ), indexSpec ) ); } TEST( EqOp, MatchesIndexKeyMissing ) { BSONObj operand = BSON( "a" << 6 ); - ComparisonExpression eq; - ASSERT( eq.init( "a", ComparisonExpression::EQ, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression eq; + ASSERT( eq.init( "a", ComparisonMatchExpression::EQ, operand[ "a" ] ).isOK() ); IndexSpec indexSpec( BSON( "b" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == eq.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == eq.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == eq.matchesIndexKey( BSON( "" << BSON_ARRAY( 8 << 6 ) ), indexSpec ) ); } TEST( EqOp, MatchesIndexKeyArray ) { BSONObj operand = BSON( "a" << BSON_ARRAY( 4 << 5 ) ); - ComparisonExpression eq + ComparisonMatchExpression eq ASSERT( eq.init( "a", operand[ "a" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == eq.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); } TEST( EqOp, MatchesIndexKeyArrayValue ) { BSONObj operand = BSON( "a" << 6 ); - ComparisonExpression eq + ComparisonMatchExpression eq ASSERT( eq.init( "a", operand[ "a" ] ).isOK() ); IndexSpec indexSpec( BSON( "loc" << "mockarrayvalue" << "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == eq.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == eq.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == eq.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( 8 << 6 ) ), indexSpec ) ); } @@ -186,8 +186,8 @@ namespace mongo { BSONObj notMatch = BSON( "a" << 6 ); BSONObj notMatchEqual = BSON( "a" << 5 ); BSONObj notMatchWrongType = BSON( "a" << "foo" ); - ComparisonExpression lt; - ASSERT( lt.init( "", ComparisonExpression::LT, operand[ "$lt" ] ).isOK() ); + ComparisonMatchExpression lt; + ASSERT( lt.init( "", ComparisonMatchExpression::LT, operand[ "$lt" ] ).isOK() ); ASSERT( lt.matchesSingleElement( match.firstElement() ) ); ASSERT( !lt.matchesSingleElement( notMatch.firstElement() ) ); ASSERT( !lt.matchesSingleElement( notMatchEqual.firstElement() ) ); @@ -196,38 +196,38 @@ namespace mongo { TEST( LtOp, InvalidEooOperand ) { BSONObj operand; - ComparisonExpression lt; - ASSERT( !lt.init( "", ComparisonExpression::LT, operand.firstElement() ).isOK() ); + ComparisonMatchExpression lt; + ASSERT( !lt.init( "", ComparisonMatchExpression::LT, operand.firstElement() ).isOK() ); } TEST( LtOp, MatchesScalar ) { BSONObj operand = BSON( "$lt" << 5 ); - ComparisonExpression lt; - ASSERT( lt.init( "a", ComparisonExpression::LT, operand[ "$lt" ] ).isOK() ); + ComparisonMatchExpression lt; + ASSERT( lt.init( "a", ComparisonMatchExpression::LT, operand[ "$lt" ] ).isOK() ); ASSERT( lt.matches( BSON( "a" << 4.5 ), NULL ) ); ASSERT( !lt.matches( BSON( "a" << 6 ), NULL ) ); } TEST( LtOp, MatchesArrayValue ) { BSONObj operand = BSON( "$lt" << 5 ); - ComparisonExpression lt; - ASSERT( lt.init( "a", ComparisonExpression::LT, operand[ "$lt" ] ).isOK() ); + ComparisonMatchExpression lt; + ASSERT( lt.init( "a", ComparisonMatchExpression::LT, operand[ "$lt" ] ).isOK() ); ASSERT( lt.matches( BSON( "a" << BSON_ARRAY( 6 << 4.5 ) ), NULL ) ); ASSERT( !lt.matches( BSON( "a" << BSON_ARRAY( 6 << 7 ) ), NULL ) ); } TEST( LtOp, MatchesWholeArray ) { BSONObj operand = BSON( "$lt" << BSON_ARRAY( 5 ) ); - ComparisonExpression lt; - ASSERT( lt.init( "a", ComparisonExpression::LT, operand[ "$lt" ] ).isOK() ); + ComparisonMatchExpression lt; + ASSERT( lt.init( "a", ComparisonMatchExpression::LT, operand[ "$lt" ] ).isOK() ); // Arrays are not comparable as inequalities. ASSERT( !lt.matches( BSON( "a" << BSON_ARRAY( 4 ) ), NULL ) ); } TEST( LtOp, MatchesNull ) { BSONObj operand = BSON( "$lt" << BSONNULL ); - ComparisonExpression lt; - ASSERT( lt.init( "a", ComparisonExpression::LT, operand[ "$lt" ] ).isOK() ); + ComparisonMatchExpression lt; + ASSERT( lt.init( "a", ComparisonMatchExpression::LT, operand[ "$lt" ] ).isOK() ); ASSERT( !lt.matches( BSONObj(), NULL ) ); ASSERT( !lt.matches( BSON( "a" << BSONNULL ), NULL ) ); ASSERT( !lt.matches( BSON( "a" << 4 ), NULL ) ); @@ -235,8 +235,8 @@ namespace mongo { TEST( LtOp, MatchesMinKey ) { BSONObj operand = BSON( "a" << MinKey ); - ComparisonExpression lt; - ASSERT( lt.init( "a", ComparisonExpression::LT, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression lt; + ASSERT( lt.init( "a", ComparisonMatchExpression::LT, operand[ "a" ] ).isOK() ); ASSERT( !lt.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( !lt.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( !lt.matches( BSON( "a" << 4 ), NULL ) ); @@ -244,8 +244,8 @@ namespace mongo { TEST( LtOp, MatchesMaxKey ) { BSONObj operand = BSON( "a" << MaxKey ); - ComparisonExpression lt; - ASSERT( lt.init( "a", ComparisonExpression::LT, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression lt; + ASSERT( lt.init( "a", ComparisonMatchExpression::LT, operand[ "a" ] ).isOK() ); ASSERT( !lt.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( lt.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( lt.matches( BSON( "a" << 4 ), NULL ) ); @@ -253,8 +253,8 @@ namespace mongo { TEST( LtOp, ElemMatchKey ) { BSONObj operand = BSON( "$lt" << 5 ); - ComparisonExpression lt; - ASSERT( lt.init( "a", ComparisonExpression::LT, operand[ "$lt" ] ).isOK() ); + ComparisonMatchExpression lt; + ASSERT( lt.init( "a", ComparisonMatchExpression::LT, operand[ "$lt" ] ).isOK() ); MatchDetails details; details.requestElemMatchKey(); ASSERT( !lt.matches( BSON( "a" << 6 ), &details ) ); @@ -272,11 +272,11 @@ namespace mongo { LtOp lt; ASSERT( lt.init( "a", operand[ "$lt" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == lt.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == lt.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == lt.matchesIndexKey( BSON( "" << BSON_ARRAY( 5 ) ), indexSpec ) ); } @@ -285,11 +285,11 @@ namespace mongo { LtOp lt; ASSERT( lt.init( "a", operand[ "$lt" ] ).isOK() ); IndexSpec indexSpec( BSON( "b" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == lt.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == lt.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == lt.matchesIndexKey( BSON( "" << BSON_ARRAY( 8 << 6 ) ), indexSpec ) ); } @@ -298,7 +298,7 @@ namespace mongo { LtOp lt; ASSERT( lt.init( "a", operand[ "$lt" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == lt.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); } @@ -307,11 +307,11 @@ namespace mongo { LtOp lt; ASSERT( lt.init( "a", operand[ "$lt" ] ).isOK() ); IndexSpec indexSpec( BSON( "loc" << "mockarrayvalue" << "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == lt.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 3 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == lt.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == lt.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( 8 << 6 << 4 ) ), indexSpec ) ); } @@ -322,8 +322,8 @@ namespace mongo { BSONObj equalMatch = BSON( "a" << 5 ); BSONObj notMatch = BSON( "a" << 6 ); BSONObj notMatchWrongType = BSON( "a" << "foo" ); - ComparisonExpression lte; - ASSERT( lte.init( "", ComparisonExpression::LTE, operand[ "$lte" ] ).isOK() ); + ComparisonMatchExpression lte; + ASSERT( lte.init( "", ComparisonMatchExpression::LTE, operand[ "$lte" ] ).isOK() ); ASSERT( lte.matchesSingleElement( match.firstElement() ) ); ASSERT( lte.matchesSingleElement( equalMatch.firstElement() ) ); ASSERT( !lte.matchesSingleElement( notMatch.firstElement() ) ); @@ -332,38 +332,38 @@ namespace mongo { TEST( LteOp, InvalidEooOperand ) { BSONObj operand; - ComparisonExpression lte; - ASSERT( !lte.init( "", ComparisonExpression::LTE, operand.firstElement() ).isOK() ); + ComparisonMatchExpression lte; + ASSERT( !lte.init( "", ComparisonMatchExpression::LTE, operand.firstElement() ).isOK() ); } TEST( LteOp, MatchesScalar ) { BSONObj operand = BSON( "$lte" << 5 ); - ComparisonExpression lte; - ASSERT( lte.init( "a", ComparisonExpression::LTE, operand[ "$lte" ] ).isOK() ); + ComparisonMatchExpression lte; + ASSERT( lte.init( "a", ComparisonMatchExpression::LTE, operand[ "$lte" ] ).isOK() ); ASSERT( lte.matches( BSON( "a" << 4.5 ), NULL ) ); ASSERT( !lte.matches( BSON( "a" << 6 ), NULL ) ); } TEST( LteOp, MatchesArrayValue ) { BSONObj operand = BSON( "$lte" << 5 ); - ComparisonExpression lte; - ASSERT( lte.init( "a", ComparisonExpression::LTE, operand[ "$lte" ] ).isOK() ); + ComparisonMatchExpression lte; + ASSERT( lte.init( "a", ComparisonMatchExpression::LTE, operand[ "$lte" ] ).isOK() ); ASSERT( lte.matches( BSON( "a" << BSON_ARRAY( 6 << 4.5 ) ), NULL ) ); ASSERT( !lte.matches( BSON( "a" << BSON_ARRAY( 6 << 7 ) ), NULL ) ); } TEST( LteOp, MatchesWholeArray ) { BSONObj operand = BSON( "$lte" << BSON_ARRAY( 5 ) ); - ComparisonExpression lte; - ASSERT( lte.init( "a", ComparisonExpression::LTE, operand[ "$lte" ] ).isOK() ); + ComparisonMatchExpression lte; + ASSERT( lte.init( "a", ComparisonMatchExpression::LTE, operand[ "$lte" ] ).isOK() ); // Arrays are not comparable as inequalities. ASSERT( !lte.matches( BSON( "a" << BSON_ARRAY( 4 ) ), NULL ) ); } TEST( LteOp, MatchesNull ) { BSONObj operand = BSON( "$lte" << BSONNULL ); - ComparisonExpression lte; - ASSERT( lte.init( "a", ComparisonExpression::LTE, operand[ "$lte" ] ).isOK() ); + ComparisonMatchExpression lte; + ASSERT( lte.init( "a", ComparisonMatchExpression::LTE, operand[ "$lte" ] ).isOK() ); ASSERT( lte.matches( BSONObj(), NULL ) ); ASSERT( lte.matches( BSON( "a" << BSONNULL ), NULL ) ); ASSERT( !lte.matches( BSON( "a" << 4 ), NULL ) ); @@ -371,8 +371,8 @@ namespace mongo { TEST( LteOp, MatchesMinKey ) { BSONObj operand = BSON( "a" << MinKey ); - ComparisonExpression lte; - ASSERT( lte.init( "a", ComparisonExpression::LTE, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression lte; + ASSERT( lte.init( "a", ComparisonMatchExpression::LTE, operand[ "a" ] ).isOK() ); ASSERT( lte.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( !lte.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( !lte.matches( BSON( "a" << 4 ), NULL ) ); @@ -380,8 +380,8 @@ namespace mongo { TEST( LteOp, MatchesMaxKey ) { BSONObj operand = BSON( "a" << MaxKey ); - ComparisonExpression lte; - ASSERT( lte.init( "a", ComparisonExpression::LTE, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression lte; + ASSERT( lte.init( "a", ComparisonMatchExpression::LTE, operand[ "a" ] ).isOK() ); ASSERT( lte.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( lte.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( lte.matches( BSON( "a" << 4 ), NULL ) ); @@ -390,8 +390,8 @@ namespace mongo { TEST( LteOp, ElemMatchKey ) { BSONObj operand = BSON( "$lte" << 5 ); - ComparisonExpression lte; - ASSERT( lte.init( "a", ComparisonExpression::LTE, operand[ "$lte" ] ).isOK() ); + ComparisonMatchExpression lte; + ASSERT( lte.init( "a", ComparisonMatchExpression::LTE, operand[ "$lte" ] ).isOK() ); MatchDetails details; details.requestElemMatchKey(); ASSERT( !lte.matches( BSON( "a" << 6 ), &details ) ); @@ -409,11 +409,11 @@ namespace mongo { LteOp lte; ASSERT( lte.init( "a", operand[ "$lte" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == lte.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == lte.matchesIndexKey( BSON( "" << 7 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == lte.matchesIndexKey( BSON( "" << BSON_ARRAY( 5 ) ), indexSpec ) ); } @@ -422,11 +422,11 @@ namespace mongo { LteOp lte; ASSERT( lte.init( "a", operand[ "$lte" ] ).isOK() ); IndexSpec indexSpec( BSON( "b" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == lte.matchesIndexKey( BSON( "" << 7 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == lte.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == lte.matchesIndexKey( BSON( "" << BSON_ARRAY( 8 << 6 ) ), indexSpec ) ); } @@ -435,7 +435,7 @@ namespace mongo { LteOp lte; ASSERT( lte.init( "a", operand[ "$lte" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == lte.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); } @@ -444,11 +444,11 @@ namespace mongo { LteOp lte; ASSERT( lte.init( "a", operand[ "$lte" ] ).isOK() ); IndexSpec indexSpec( BSON( "loc" << "mockarrayvalue" << "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == lte.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 3 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == lte.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 7 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == lte.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( 8 << 6 << 4 ) ), indexSpec ) ); } @@ -470,38 +470,38 @@ namespace mongo { TEST( GtOp, InvalidEooOperand ) { BSONObj operand; - ComparisonExpression gt; - ASSERT( !gt.init( "", ComparisonExpression::GT, operand.firstElement() ).isOK() ); + ComparisonMatchExpression gt; + ASSERT( !gt.init( "", ComparisonMatchExpression::GT, operand.firstElement() ).isOK() ); } TEST( GtOp, MatchesScalar ) { BSONObj operand = BSON( "$gt" << 5 ); - ComparisonExpression gt; - ASSERT( gt.init( "a", ComparisonExpression::GT, operand[ "$gt" ] ).isOK() ); + ComparisonMatchExpression gt; + ASSERT( gt.init( "a", ComparisonMatchExpression::GT, operand[ "$gt" ] ).isOK() ); ASSERT( gt.matches( BSON( "a" << 5.5 ), NULL ) ); ASSERT( !gt.matches( BSON( "a" << 4 ), NULL ) ); } TEST( GtOp, MatchesArrayValue ) { BSONObj operand = BSON( "$gt" << 5 ); - ComparisonExpression gt; - ASSERT( gt.init( "a", ComparisonExpression::GT, operand[ "$gt" ] ).isOK() ); + ComparisonMatchExpression gt; + ASSERT( gt.init( "a", ComparisonMatchExpression::GT, operand[ "$gt" ] ).isOK() ); ASSERT( gt.matches( BSON( "a" << BSON_ARRAY( 3 << 5.5 ) ), NULL ) ); ASSERT( !gt.matches( BSON( "a" << BSON_ARRAY( 2 << 4 ) ), NULL ) ); } TEST( GtOp, MatchesWholeArray ) { BSONObj operand = BSON( "$gt" << BSON_ARRAY( 5 ) ); - ComparisonExpression gt; - ASSERT( gt.init( "a", ComparisonExpression::GT, operand[ "$gt" ] ).isOK() ); + ComparisonMatchExpression gt; + ASSERT( gt.init( "a", ComparisonMatchExpression::GT, operand[ "$gt" ] ).isOK() ); // Arrays are not comparable as inequalities. ASSERT( !gt.matches( BSON( "a" << BSON_ARRAY( 6 ) ), NULL ) ); } TEST( GtOp, MatchesNull ) { BSONObj operand = BSON( "$gt" << BSONNULL ); - ComparisonExpression gt; - ASSERT( gt.init( "a", ComparisonExpression::GT, operand[ "$gt" ] ).isOK() ); + ComparisonMatchExpression gt; + ASSERT( gt.init( "a", ComparisonMatchExpression::GT, operand[ "$gt" ] ).isOK() ); ASSERT( !gt.matches( BSONObj(), NULL ) ); ASSERT( !gt.matches( BSON( "a" << BSONNULL ), NULL ) ); ASSERT( !gt.matches( BSON( "a" << 4 ), NULL ) ); @@ -509,8 +509,8 @@ namespace mongo { TEST( GtOp, MatchesMinKey ) { BSONObj operand = BSON( "a" << MinKey ); - ComparisonExpression gt; - ASSERT( gt.init( "a", ComparisonExpression::GT, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression gt; + ASSERT( gt.init( "a", ComparisonMatchExpression::GT, operand[ "a" ] ).isOK() ); ASSERT( !gt.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( gt.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( gt.matches( BSON( "a" << 4 ), NULL ) ); @@ -518,8 +518,8 @@ namespace mongo { TEST( GtOp, MatchesMaxKey ) { BSONObj operand = BSON( "a" << MaxKey ); - ComparisonExpression gt; - ASSERT( gt.init( "a", ComparisonExpression::GT, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression gt; + ASSERT( gt.init( "a", ComparisonMatchExpression::GT, operand[ "a" ] ).isOK() ); ASSERT( !gt.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( !gt.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( !gt.matches( BSON( "a" << 4 ), NULL ) ); @@ -527,8 +527,8 @@ namespace mongo { TEST( GtOp, ElemMatchKey ) { BSONObj operand = BSON( "$gt" << 5 ); - ComparisonExpression gt; - ASSERT( gt.init( "a", ComparisonExpression::GT, operand[ "$gt" ] ).isOK() ); + ComparisonMatchExpression gt; + ASSERT( gt.init( "a", ComparisonMatchExpression::GT, operand[ "$gt" ] ).isOK() ); MatchDetails details; details.requestElemMatchKey(); ASSERT( !gt.matches( BSON( "a" << 4 ), &details ) ); @@ -546,11 +546,11 @@ namespace mongo { GtOp gt; ASSERT( gt.init( "a", operand[ "$gt" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == gt.matchesIndexKey( BSON( "" << 7 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == gt.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == gt.matchesIndexKey( BSON( "" << BSON_ARRAY( 9 ) ), indexSpec ) ); } @@ -559,11 +559,11 @@ namespace mongo { GtOp gt; ASSERT( gt.init( "a", operand[ "$gt" ] ).isOK() ); IndexSpec indexSpec( BSON( "b" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == gt.matchesIndexKey( BSON( "" << 7 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == gt.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == gt.matchesIndexKey( BSON( "" << BSON_ARRAY( 8 << 6 ) ), indexSpec ) ); } @@ -572,7 +572,7 @@ namespace mongo { GtOp gt; ASSERT( gt.init( "a", operand[ "$gt" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == gt.matchesIndexKey( BSON( "" << 8 ), indexSpec ) ); } @@ -581,91 +581,91 @@ namespace mongo { GtOp gt; ASSERT( gt.init( "a", operand[ "$gt" ] ).isOK() ); IndexSpec indexSpec( BSON( "loc" << "mockarrayvalue" << "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == gt.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 7 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == gt.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 3 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == gt.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( 8 << 6 << 4 ) ), indexSpec ) ); } */ - TEST( ComparisonExpression, MatchesElement ) { + TEST( ComparisonMatchExpression, MatchesElement ) { BSONObj operand = BSON( "$gte" << 5 ); BSONObj match = BSON( "a" << 5.5 ); BSONObj equalMatch = BSON( "a" << 5 ); BSONObj notMatch = BSON( "a" << 4 ); BSONObj notMatchWrongType = BSON( "a" << "foo" ); - ComparisonExpression gte; - ASSERT( gte.init( "", ComparisonExpression::GTE, operand[ "$gte" ] ).isOK() ); + ComparisonMatchExpression gte; + ASSERT( gte.init( "", ComparisonMatchExpression::GTE, operand[ "$gte" ] ).isOK() ); ASSERT( gte.matchesSingleElement( match.firstElement() ) ); ASSERT( gte.matchesSingleElement( equalMatch.firstElement() ) ); ASSERT( !gte.matchesSingleElement( notMatch.firstElement() ) ); ASSERT( !gte.matchesSingleElement( notMatchWrongType.firstElement() ) ); } - TEST( ComparisonExpression, InvalidEooOperand ) { + TEST( ComparisonMatchExpression, InvalidEooOperand ) { BSONObj operand; - ComparisonExpression gte; - ASSERT( !gte.init( "", ComparisonExpression::GTE, operand.firstElement() ).isOK() ); + ComparisonMatchExpression gte; + ASSERT( !gte.init( "", ComparisonMatchExpression::GTE, operand.firstElement() ).isOK() ); } - TEST( ComparisonExpression, MatchesScalar ) { + TEST( ComparisonMatchExpression, MatchesScalar ) { BSONObj operand = BSON( "$gte" << 5 ); - ComparisonExpression gte; - ASSERT( gte.init( "a", ComparisonExpression::GTE, operand[ "$gte" ] ).isOK() ); + ComparisonMatchExpression gte; + ASSERT( gte.init( "a", ComparisonMatchExpression::GTE, operand[ "$gte" ] ).isOK() ); ASSERT( gte.matches( BSON( "a" << 5.5 ), NULL ) ); ASSERT( !gte.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( ComparisonExpression, MatchesArrayValue ) { + TEST( ComparisonMatchExpression, MatchesArrayValue ) { BSONObj operand = BSON( "$gte" << 5 ); - ComparisonExpression gte; - ASSERT( gte.init( "a", ComparisonExpression::GTE, operand[ "$gte" ] ).isOK() ); + ComparisonMatchExpression gte; + ASSERT( gte.init( "a", ComparisonMatchExpression::GTE, operand[ "$gte" ] ).isOK() ); ASSERT( gte.matches( BSON( "a" << BSON_ARRAY( 4 << 5.5 ) ), NULL ) ); ASSERT( !gte.matches( BSON( "a" << BSON_ARRAY( 1 << 2 ) ), NULL ) ); } - TEST( ComparisonExpression, MatchesWholeArray ) { + TEST( ComparisonMatchExpression, MatchesWholeArray ) { BSONObj operand = BSON( "$gte" << BSON_ARRAY( 5 ) ); - ComparisonExpression gte; - ASSERT( gte.init( "a", ComparisonExpression::GTE, operand[ "$gte" ] ).isOK() ); + ComparisonMatchExpression gte; + ASSERT( gte.init( "a", ComparisonMatchExpression::GTE, operand[ "$gte" ] ).isOK() ); // Arrays are not comparable as inequalities. ASSERT( !gte.matches( BSON( "a" << BSON_ARRAY( 6 ) ), NULL ) ); } - TEST( ComparisonExpression, MatchesNull ) { + TEST( ComparisonMatchExpression, MatchesNull ) { BSONObj operand = BSON( "$gte" << BSONNULL ); - ComparisonExpression gte; - ASSERT( gte.init( "a", ComparisonExpression::GTE, operand[ "$gte" ] ).isOK() ); + ComparisonMatchExpression gte; + ASSERT( gte.init( "a", ComparisonMatchExpression::GTE, operand[ "$gte" ] ).isOK() ); ASSERT( gte.matches( BSONObj(), NULL ) ); ASSERT( gte.matches( BSON( "a" << BSONNULL ), NULL ) ); ASSERT( !gte.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( ComparisonExpression, MatchesMinKey ) { + TEST( ComparisonMatchExpression, MatchesMinKey ) { BSONObj operand = BSON( "a" << MinKey ); - ComparisonExpression gte; - ASSERT( gte.init( "a", ComparisonExpression::GTE, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression gte; + ASSERT( gte.init( "a", ComparisonMatchExpression::GTE, operand[ "a" ] ).isOK() ); ASSERT( gte.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( gte.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( gte.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( ComparisonExpression, MatchesMaxKey ) { + TEST( ComparisonMatchExpression, MatchesMaxKey ) { BSONObj operand = BSON( "a" << MaxKey ); - ComparisonExpression gte; - ASSERT( gte.init( "a", ComparisonExpression::GTE, operand[ "a" ] ).isOK() ); + ComparisonMatchExpression gte; + ASSERT( gte.init( "a", ComparisonMatchExpression::GTE, operand[ "a" ] ).isOK() ); ASSERT( gte.matches( BSON( "a" << MaxKey ), NULL ) ); ASSERT( !gte.matches( BSON( "a" << MinKey ), NULL ) ); ASSERT( !gte.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( ComparisonExpression, ElemMatchKey ) { + TEST( ComparisonMatchExpression, ElemMatchKey ) { BSONObj operand = BSON( "$gte" << 5 ); - ComparisonExpression gte; - ASSERT( gte.init( "a", ComparisonExpression::GTE, operand[ "$gte" ] ).isOK() ); + ComparisonMatchExpression gte; + ASSERT( gte.init( "a", ComparisonMatchExpression::GTE, operand[ "$gte" ] ).isOK() ); MatchDetails details; details.requestElemMatchKey(); ASSERT( !gte.matches( BSON( "a" << 4 ), &details ) ); @@ -683,11 +683,11 @@ namespace mongo { GteOp gte; ASSERT( gte.init( "a", operand[ "$gte" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == gte.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == gte.matchesIndexKey( BSON( "" << 5 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == gte.matchesIndexKey( BSON( "" << BSON_ARRAY( 7 ) ), indexSpec ) ); } @@ -696,11 +696,11 @@ namespace mongo { GteOp gte; ASSERT( gte.init( "a", operand[ "$gte" ] ).isOK() ); IndexSpec indexSpec( BSON( "b" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == gte.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == gte.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == gte.matchesIndexKey( BSON( "" << BSON_ARRAY( 8 << 6 ) ), indexSpec ) ); } @@ -709,7 +709,7 @@ namespace mongo { GteOp gte; ASSERT( gte.init( "a", operand[ "$gte" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == gte.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); } @@ -718,11 +718,11 @@ namespace mongo { GteOp gte; ASSERT( gte.init( "a", operand[ "$gte" ] ).isOK() ); IndexSpec indexSpec( BSON( "loc" << "mockarrayvalue" << "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == gte.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == gte.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 3 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == gte.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( 8 << 6 << 4 ) ), indexSpec ) ); } @@ -732,30 +732,30 @@ namespace mongo { BSONObj operand = BSON( "$ne" << 5 ); BSONObj match = BSON( "a" << 6 ); BSONObj notMatch = BSON( "a" << 5 ); - ComparisonExpression ne; - ASSERT( ne.init( "", ComparisonExpression::NE, operand[ "$ne" ] ).isOK() ); + ComparisonMatchExpression ne; + ASSERT( ne.init( "", ComparisonMatchExpression::NE, operand[ "$ne" ] ).isOK() ); ASSERT( ne.matchesSingleElement( match.firstElement() ) ); ASSERT( !ne.matchesSingleElement( notMatch.firstElement() ) ); } TEST( NeOp, InvalidEooOperand ) { BSONObj operand; - ComparisonExpression ne; - ASSERT( !ne.init( "", ComparisonExpression::NE, operand.firstElement() ).isOK() ); + ComparisonMatchExpression ne; + ASSERT( !ne.init( "", ComparisonMatchExpression::NE, operand.firstElement() ).isOK() ); } TEST( NeOp, MatchesScalar ) { BSONObj operand = BSON( "$ne" << 5 ); - ComparisonExpression ne; - ASSERT( ne.init( "a", ComparisonExpression::NE, operand[ "$ne" ] ).isOK() ); + ComparisonMatchExpression ne; + ASSERT( ne.init( "a", ComparisonMatchExpression::NE, operand[ "$ne" ] ).isOK() ); ASSERT( ne.matches( BSON( "a" << 4 ), NULL ) ); ASSERT( !ne.matches( BSON( "a" << 5 ), NULL ) ); } TEST( NeOp, MatchesArrayValue ) { BSONObj operand = BSON( "$ne" << 5 ); - ComparisonExpression ne; - ASSERT( ne.init( "a", ComparisonExpression::NE, operand[ "$ne" ] ).isOK() ); + ComparisonMatchExpression ne; + ASSERT( ne.init( "a", ComparisonMatchExpression::NE, operand[ "$ne" ] ).isOK() ); ASSERT( ne.matches( BSON( "a" << BSON_ARRAY( 4 << 6 ) ), NULL ) ); ASSERT( !ne.matches( BSON( "a" << BSON_ARRAY( 4 << 5 ) ), NULL ) ); ASSERT( !ne.matches( BSON( "a" << BSON_ARRAY( 5 << 5 ) ), NULL ) ); @@ -763,8 +763,8 @@ namespace mongo { TEST( NeOp, MatchesNull ) { BSONObj operand = BSON( "$ne" << BSONNULL ); - ComparisonExpression ne; - ASSERT( ne.init( "a", ComparisonExpression::NE, operand[ "$ne" ] ).isOK() ); + ComparisonMatchExpression ne; + ASSERT( ne.init( "a", ComparisonMatchExpression::NE, operand[ "$ne" ] ).isOK() ); ASSERT( ne.matches( BSON( "a" << 4 ), NULL ) ); ASSERT( !ne.matches( BSONObj(), NULL ) ); ASSERT( !ne.matches( BSON( "a" << BSONNULL ), NULL ) ); @@ -772,8 +772,8 @@ namespace mongo { TEST( NeOp, ElemMatchKey ) { BSONObj operand = BSON( "$ne" << 5 ); - ComparisonExpression ne; - ASSERT( ne.init( "a", ComparisonExpression::NE, operand[ "$ne" ] ).isOK() ); + ComparisonMatchExpression ne; + ASSERT( ne.init( "a", ComparisonMatchExpression::NE, operand[ "$ne" ] ).isOK() ); MatchDetails details; details.requestElemMatchKey(); ASSERT( !ne.matches( BSON( "a" << BSON_ARRAY( 2 << 6 << 5 ) ), &details ) ); @@ -790,179 +790,179 @@ namespace mongo { ASSERT( ne.init( "a", operand[ "$ne" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << 1 ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == ne.matchesIndexKey( indexKey, indexSpec ) ); } */ - TEST( RegexExpression, MatchesElementExact ) { + TEST( RegexMatchExpression, MatchesElementExact ) { BSONObj match = BSON( "a" << "b" ); BSONObj notMatch = BSON( "a" << "c" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "b", "" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, TooLargePattern ) { + TEST( RegexMatchExpression, TooLargePattern ) { string tooLargePattern( 50 * 1000, 'z' ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( !regex.init( "a", tooLargePattern, "" ).isOK() ); } - TEST( RegexExpression, MatchesElementSimplePrefix ) { + TEST( RegexMatchExpression, MatchesElementSimplePrefix ) { BSONObj match = BSON( "x" << "abc" ); BSONObj notMatch = BSON( "x" << "adz" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "^ab", "" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementCaseSensitive ) { + TEST( RegexMatchExpression, MatchesElementCaseSensitive ) { BSONObj match = BSON( "x" << "abc" ); BSONObj notMatch = BSON( "x" << "ABC" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "abc", "" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementCaseInsensitive ) { + TEST( RegexMatchExpression, MatchesElementCaseInsensitive ) { BSONObj match = BSON( "x" << "abc" ); BSONObj matchUppercase = BSON( "x" << "ABC" ); BSONObj notMatch = BSON( "x" << "abz" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "abc", "i" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( regex.matchesSingleElement( matchUppercase.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementMultilineOff ) { + TEST( RegexMatchExpression, MatchesElementMultilineOff ) { BSONObj match = BSON( "x" << "az" ); BSONObj notMatch = BSON( "x" << "\naz" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "^a", "" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementMultilineOn ) { + TEST( RegexMatchExpression, MatchesElementMultilineOn ) { BSONObj match = BSON( "x" << "az" ); BSONObj matchMultiline = BSON( "x" << "\naz" ); BSONObj notMatch = BSON( "x" << "\n\n" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "^a", "m" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( regex.matchesSingleElement( matchMultiline.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementExtendedOff ) { + TEST( RegexMatchExpression, MatchesElementExtendedOff ) { BSONObj match = BSON( "x" << "a b" ); BSONObj notMatch = BSON( "x" << "ab" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "a b", "" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementExtendedOn ) { + TEST( RegexMatchExpression, MatchesElementExtendedOn ) { BSONObj match = BSON( "x" << "ab" ); BSONObj notMatch = BSON( "x" << "a b" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "a b", "x" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementDotAllOff ) { + TEST( RegexMatchExpression, MatchesElementDotAllOff ) { BSONObj match = BSON( "x" << "a b" ); BSONObj notMatch = BSON( "x" << "a\nb" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "a.b", "" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementDotAllOn ) { + TEST( RegexMatchExpression, MatchesElementDotAllOn ) { BSONObj match = BSON( "x" << "a b" ); BSONObj matchDotAll = BSON( "x" << "a\nb" ); BSONObj notMatch = BSON( "x" << "ab" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "a.b", "s" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( regex.matchesSingleElement( matchDotAll.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementMultipleFlags ) { + TEST( RegexMatchExpression, MatchesElementMultipleFlags ) { BSONObj matchMultilineDotAll = BSON( "x" << "\na\nb" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "^a.b", "ms" ).isOK() ); ASSERT( regex.matchesSingleElement( matchMultilineDotAll.firstElement() ) ); } - TEST( RegexExpression, MatchesElementRegexType ) { + TEST( RegexMatchExpression, MatchesElementRegexType ) { BSONObj match = BSONObjBuilder().appendRegex( "x", "yz", "i" ).obj(); BSONObj notMatchPattern = BSONObjBuilder().appendRegex( "x", "r", "i" ).obj(); BSONObj notMatchFlags = BSONObjBuilder().appendRegex( "x", "yz", "s" ).obj(); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "yz", "i" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatchPattern.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatchFlags.firstElement() ) ); } - TEST( RegexExpression, MatchesElementSymbolType ) { + TEST( RegexMatchExpression, MatchesElementSymbolType ) { BSONObj match = BSONObjBuilder().appendSymbol( "x", "yz" ).obj(); BSONObj notMatch = BSONObjBuilder().appendSymbol( "x", "gg" ).obj(); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "yz", "" ).isOK() ); ASSERT( regex.matchesSingleElement( match.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( RegexExpression, MatchesElementWrongType ) { + TEST( RegexMatchExpression, MatchesElementWrongType ) { BSONObj notMatchInt = BSON( "x" << 1 ); BSONObj notMatchBool = BSON( "x" << true ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "1", "" ).isOK() ); ASSERT( !regex.matchesSingleElement( notMatchInt.firstElement() ) ); ASSERT( !regex.matchesSingleElement( notMatchBool.firstElement() ) ); } - TEST( RegexExpression, MatchesElementUtf8 ) { + TEST( RegexMatchExpression, MatchesElementUtf8 ) { BSONObj multiByteCharacter = BSON( "x" << "\xc2\xa5" ); - RegexExpression regex; + RegexMatchExpression regex; ASSERT( regex.init( "", "^.$", "" ).isOK() ); ASSERT( regex.matchesSingleElement( multiByteCharacter.firstElement() ) ); } - TEST( RegexExpression, MatchesScalar ) { - RegexExpression regex; + TEST( RegexMatchExpression, MatchesScalar ) { + RegexMatchExpression regex; ASSERT( regex.init( "a", "b", "" ).isOK() ); ASSERT( regex.matches( BSON( "a" << "b" ), NULL ) ); ASSERT( !regex.matches( BSON( "a" << "c" ), NULL ) ); } - TEST( RegexExpression, MatchesArrayValue ) { - RegexExpression regex; + TEST( RegexMatchExpression, MatchesArrayValue ) { + RegexMatchExpression regex; ASSERT( regex.init( "a", "b", "" ).isOK() ); ASSERT( regex.matches( BSON( "a" << BSON_ARRAY( "c" << "b" ) ), NULL ) ); ASSERT( !regex.matches( BSON( "a" << BSON_ARRAY( "d" << "c" ) ), NULL ) ); } - TEST( RegexExpression, MatchesNull ) { - RegexExpression regex; + TEST( RegexMatchExpression, MatchesNull ) { + RegexMatchExpression regex; ASSERT( regex.init( "a", "b", "" ).isOK() ); ASSERT( !regex.matches( BSONObj(), NULL ) ); ASSERT( !regex.matches( BSON( "a" << BSONNULL ), NULL ) ); } - TEST( RegexExpression, ElemMatchKey ) { - RegexExpression regex; + TEST( RegexMatchExpression, ElemMatchKey ) { + RegexMatchExpression regex; ASSERT( regex.init( "a", "b", "" ).isOK() ); MatchDetails details; details.requestElemMatchKey(); @@ -976,51 +976,51 @@ namespace mongo { } /** - TEST( RegexExpression, MatchesIndexKeyScalar ) { - RegexExpression regex; + TEST( RegexMatchExpression, MatchesIndexKeyScalar ) { + RegexMatchExpression regex; ASSERT( regex.init( "a", "xyz", "" ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == regex.matchesIndexKey( BSON( "" << "z xyz" ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == regex.matchesIndexKey( BSON( "" << "xy" ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == regex.matchesIndexKey( BSON( "" << BSON_ARRAY( "xyz" ) ), indexSpec ) ); } - TEST( RegexExpression, MatchesIndexKeyMissing ) { - RegexExpression regex; + TEST( RegexMatchExpression, MatchesIndexKeyMissing ) { + RegexMatchExpression regex; ASSERT( regex.init( "a", "xyz", "" ).isOK() ); IndexSpec indexSpec( BSON( "b" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == regex.matchesIndexKey( BSON( "" << "z xyz" ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == regex.matchesIndexKey( BSON( "" << "xy" ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == regex.matchesIndexKey( BSON( "" << BSON_ARRAY( 8 << "xyz" ) ), indexSpec ) ); } - TEST( RegexExpression, MatchesIndexKeyArrayValue ) { - RegexExpression regex; + TEST( RegexMatchExpression, MatchesIndexKeyArrayValue ) { + RegexMatchExpression regex; ASSERT( regex.init( "a", "xyz", "" ).isOK() ); IndexSpec indexSpec( BSON( "loc" << "mockarrayvalue" << "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == regex.matchesIndexKey( BSON( "" << "dummygeohash" << "" << "xyz" ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == regex.matchesIndexKey( BSON( "" << "dummygeohash" << "" << "z" ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == regex.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( "r" << 6 << "xyz" ) ), indexSpec ) ); } */ - TEST( ModExpression, MatchesElement ) { + TEST( ModMatchExpression, MatchesElement ) { BSONObj match = BSON( "a" << 1 ); BSONObj largerMatch = BSON( "a" << 4.0 ); BSONObj longLongMatch = BSON( "a" << 68719476736LL ); BSONObj notMatch = BSON( "a" << 6 ); BSONObj negativeNotMatch = BSON( "a" << -2 ); - ModExpression mod; + ModMatchExpression mod; ASSERT( mod.init( "", 3, 1 ).isOK() ); ASSERT( mod.matchesSingleElement( match.firstElement() ) ); ASSERT( mod.matchesSingleElement( largerMatch.firstElement() ) ); @@ -1029,34 +1029,34 @@ namespace mongo { ASSERT( !mod.matchesSingleElement( negativeNotMatch.firstElement() ) ); } - TEST( ModExpression, ZeroDivisor ) { - ModExpression mod; + TEST( ModMatchExpression, ZeroDivisor ) { + ModMatchExpression mod; ASSERT( !mod.init( "", 0, 1 ).isOK() ); } - TEST( ModExpression, MatchesScalar ) { - ModExpression mod; + TEST( ModMatchExpression, MatchesScalar ) { + ModMatchExpression mod; ASSERT( mod.init( "a", 5, 2 ).isOK() ); ASSERT( mod.matches( BSON( "a" << 7.0 ), NULL ) ); ASSERT( !mod.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( ModExpression, MatchesArrayValue ) { - ModExpression mod; + TEST( ModMatchExpression, MatchesArrayValue ) { + ModMatchExpression mod; ASSERT( mod.init( "a", 5, 2 ).isOK() ); ASSERT( mod.matches( BSON( "a" << BSON_ARRAY( 5 << 12LL ) ), NULL ) ); ASSERT( !mod.matches( BSON( "a" << BSON_ARRAY( 6 << 8 ) ), NULL ) ); } - TEST( ModExpression, MatchesNull ) { - ModExpression mod; + TEST( ModMatchExpression, MatchesNull ) { + ModMatchExpression mod; ASSERT( mod.init( "a", 5, 2 ).isOK() ); ASSERT( !mod.matches( BSONObj(), NULL ) ); ASSERT( !mod.matches( BSON( "a" << BSONNULL ), NULL ) ); } - TEST( ModExpression, ElemMatchKey ) { - ModExpression mod; + TEST( ModMatchExpression, ElemMatchKey ) { + ModMatchExpression mod; ASSERT( mod.init( "a", 5, 2 ).isOK() ); MatchDetails details; details.requestElemMatchKey(); @@ -1069,44 +1069,44 @@ namespace mongo { ASSERT_EQUALS( "1", details.elemMatchKey() ); } /** - TEST( ModExpression, MatchesIndexKey ) { + TEST( ModMatchExpression, MatchesIndexKey ) { BSONObj operand = BSON( "$mod" << BSON_ARRAY( 2 << 1 ) ); - ModExpression mod; + ModMatchExpression mod; ASSERT( mod.init( "a", operand[ "$mod" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << 1 ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == mod.matchesIndexKey( indexKey, indexSpec ) ); } */ - TEST( ExistsExpression, MatchesElement ) { + TEST( ExistsMatchExpression, MatchesElement ) { BSONObj existsInt = BSON( "a" << 5 ); BSONObj existsNull = BSON( "a" << BSONNULL ); BSONObj doesntExist = BSONObj(); - ExistsExpression exists; + ExistsMatchExpression exists; ASSERT( exists.init( "", true ).isOK() ); ASSERT( exists.matchesSingleElement( existsInt.firstElement() ) ); ASSERT( exists.matchesSingleElement( existsNull.firstElement() ) ); ASSERT( !exists.matchesSingleElement( doesntExist.firstElement() ) ); } - TEST( ExistsExpression, MatchesElementExistsFalse ) { + TEST( ExistsMatchExpression, MatchesElementExistsFalse ) { BSONObj existsInt = BSON( "a" << 5 ); BSONObj existsNull = BSON( "a" << BSONNULL ); BSONObj doesntExist = BSONObj(); - ExistsExpression exists; + ExistsMatchExpression exists; ASSERT( exists.init( "", false ).isOK() ); ASSERT( !exists.matchesSingleElement( existsInt.firstElement() ) ); ASSERT( !exists.matchesSingleElement( existsNull.firstElement() ) ); ASSERT( exists.matchesSingleElement( doesntExist.firstElement() ) ); } - TEST( ExistsExpression, MatchesElementExistsTrueValue ) { + TEST( ExistsMatchExpression, MatchesElementExistsTrueValue ) { BSONObj exists = BSON( "a" << 5 ); BSONObj missing = BSONObj(); - ExistsExpression existsTrueValue; - ExistsExpression existsFalseValue; + ExistsMatchExpression existsTrueValue; + ExistsMatchExpression existsFalseValue; ASSERT( existsTrueValue.init( "", true ).isOK() ); ASSERT( existsFalseValue.init( "", false ).isOK() ); ASSERT( existsTrueValue.matchesSingleElement( exists.firstElement() ) ); @@ -1115,30 +1115,30 @@ namespace mongo { ASSERT( existsFalseValue.matchesSingleElement( missing.firstElement() ) ); } - TEST( ExistsExpression, MatchesScalar ) { - ExistsExpression exists; + TEST( ExistsMatchExpression, MatchesScalar ) { + ExistsMatchExpression exists; ASSERT( exists.init( "a", true ).isOK() ); ASSERT( exists.matches( BSON( "a" << 1 ), NULL ) ); ASSERT( exists.matches( BSON( "a" << BSONNULL ), NULL ) ); ASSERT( !exists.matches( BSON( "b" << 1 ), NULL ) ); } - TEST( ExistsExpression, MatchesScalarFalse ) { - ExistsExpression exists; + TEST( ExistsMatchExpression, MatchesScalarFalse ) { + ExistsMatchExpression exists; ASSERT( exists.init( "a", false ).isOK() ); ASSERT( !exists.matches( BSON( "a" << 1 ), NULL ) ); ASSERT( !exists.matches( BSON( "a" << BSONNULL ), NULL ) ); ASSERT( exists.matches( BSON( "b" << 1 ), NULL ) ); } - TEST( ExistsExpression, MatchesArray ) { - ExistsExpression exists; + TEST( ExistsMatchExpression, MatchesArray ) { + ExistsMatchExpression exists; ASSERT( exists.init( "a", true ).isOK() ); ASSERT( exists.matches( BSON( "a" << BSON_ARRAY( 4 << 5.5 ) ), NULL ) ); } - TEST( ExistsExpression, ElemMatchKey ) { - ExistsExpression exists; + TEST( ExistsMatchExpression, ElemMatchKey ) { + ExistsMatchExpression exists; ASSERT( exists.init( "a.b", true ).isOK() ); MatchDetails details; details.requestElemMatchKey(); @@ -1151,57 +1151,57 @@ namespace mongo { ASSERT_EQUALS( "1", details.elemMatchKey() ); } /** - TEST( ExistsExpression, MatchesIndexKey ) { + TEST( ExistsMatchExpression, MatchesIndexKey ) { BSONObj operand = BSON( "$exists" << true ); - ExistsExpression exists; + ExistsMatchExpression exists; ASSERT( exists.init( "a", operand[ "$exists" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << 1 ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == exists.matchesIndexKey( indexKey, indexSpec ) ); } */ - TEST( TypeExpression, MatchesElementStringType ) { + TEST( TypeMatchExpression, MatchesElementStringType ) { BSONObj match = BSON( "a" << "abc" ); BSONObj notMatch = BSON( "a" << 5 ); - TypeExpression type; + TypeMatchExpression type; ASSERT( type.init( "", String ).isOK() ); ASSERT( type.matchesSingleElement( match[ "a" ] ) ); ASSERT( !type.matchesSingleElement( notMatch[ "a" ] ) ); } - TEST( TypeExpression, MatchesElementNullType ) { + TEST( TypeMatchExpression, MatchesElementNullType ) { BSONObj match = BSON( "a" << BSONNULL ); BSONObj notMatch = BSON( "a" << "abc" ); - TypeExpression type; + TypeMatchExpression type; ASSERT( type.init( "", jstNULL ).isOK() ); ASSERT( type.matchesSingleElement( match[ "a" ] ) ); ASSERT( !type.matchesSingleElement( notMatch[ "a" ] ) ); } - TEST( TypeExpression, InvalidTypeExpressionerand ) { + 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" ); - TypeExpression type; + TypeMatchExpression type; ASSERT( type.init( "", JSTypeMax + 1 ).isOK() ); ASSERT( !type.matchesSingleElement( notMatch1[ "a" ] ) ); ASSERT( !type.matchesSingleElement( notMatch2[ "a" ] ) ); } - TEST( TypeExpression, MatchesScalar ) { - TypeExpression type; + TEST( TypeMatchExpression, MatchesScalar ) { + TypeMatchExpression type; ASSERT( type.init( "a", Bool ).isOK() ); ASSERT( type.matches( BSON( "a" << true ), NULL ) ); ASSERT( !type.matches( BSON( "a" << 1 ), NULL ) ); } - TEST( TypeExpression, MatchesArray ) { - TypeExpression type; + TEST( TypeMatchExpression, MatchesArray ) { + TypeMatchExpression type; ASSERT( type.init( "a", NumberInt ).isOK() ); ASSERT( type.matches( BSON( "a" << BSON_ARRAY( 4 ) ), NULL ) ); ASSERT( type.matches( BSON( "a" << BSON_ARRAY( 4 << "a" ) ), NULL ) ); @@ -1210,8 +1210,8 @@ namespace mongo { ASSERT( !type.matches( BSON( "a" << BSON_ARRAY( BSON_ARRAY( 4 ) ) ), NULL ) ); } - TEST( TypeExpression, MatchesOuterArray ) { - TypeExpression type; + TEST( TypeMatchExpression, MatchesOuterArray ) { + TypeMatchExpression type; ASSERT( type.init( "a", Array ).isOK() ); // The outer array is not matched. ASSERT( !type.matches( BSON( "a" << BSONArray() ), NULL ) ); @@ -1220,16 +1220,16 @@ namespace mongo { ASSERT( !type.matches( BSON( "a" << "bar" ), NULL ) ); } - TEST( TypeExpression, MatchesNull ) { - TypeExpression type; + TEST( TypeMatchExpression, MatchesNull ) { + TypeMatchExpression type; ASSERT( type.init( "a", jstNULL ).isOK() ); ASSERT( type.matches( BSON( "a" << BSONNULL ), NULL ) ); ASSERT( !type.matches( BSON( "a" << 4 ), NULL ) ); ASSERT( !type.matches( BSONObj(), NULL ) ); } - TEST( TypeExpression, ElemMatchKey ) { - TypeExpression type; + TEST( TypeMatchExpression, ElemMatchKey ) { + TypeMatchExpression type; ASSERT( type.init( "a.b", String ).isOK() ); MatchDetails details; details.requestElemMatchKey(); @@ -1248,30 +1248,30 @@ namespace mongo { ASSERT_EQUALS( "1", details.elemMatchKey() ); } /** - TEST( TypeExpression, MatchesIndexKey ) { + TEST( TypeMatchExpression, MatchesIndexKey ) { BSONObj operand = BSON( "$type" << 2 ); - TypeExpression type; + TypeMatchExpression type; ASSERT( type.init( "a", operand[ "$type" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << "q" ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == type.matchesIndexKey( indexKey, indexSpec ) ); } */ - TEST( InExpression, MatchesElementSingle ) { + TEST( InMatchExpression, MatchesElementSingle ) { BSONArray operand = BSON_ARRAY( 1 ); BSONObj match = BSON( "a" << 1 ); BSONObj notMatch = BSON( "a" << 2 ); - InExpression in; + InMatchExpression in; in.getArrayFilterEntries()->addEquality( operand.firstElement() ); ASSERT( in.matchesSingleElement( match[ "a" ] ) ); ASSERT( !in.matchesSingleElement( notMatch[ "a" ] ) ); } - TEST( InExpression, MatchesEmpty ) { - InExpression in; + TEST( InMatchExpression, MatchesEmpty ) { + InMatchExpression in; in.init( "a" ); BSONObj notMatch = BSON( "a" << 2 ); @@ -1280,9 +1280,9 @@ namespace mongo { ASSERT( !in.matches( BSONObj(), NULL ) ); } - TEST( InExpression, MatchesElementMultiple ) { + TEST( InMatchExpression, MatchesElementMultiple ) { BSONObj operand = BSON_ARRAY( 1 << "r" << true << 1 ); - InExpression in; + InMatchExpression in; in.getArrayFilterEntries()->addEquality( operand[0] ); in.getArrayFilterEntries()->addEquality( operand[1] ); in.getArrayFilterEntries()->addEquality( operand[2] ); @@ -1299,9 +1299,9 @@ namespace mongo { } - TEST( InExpression, MatchesScalar ) { + TEST( InMatchExpression, MatchesScalar ) { BSONObj operand = BSON_ARRAY( 5 ); - InExpression in; + InMatchExpression in; in.init( "a" ); in.getArrayFilterEntries()->addEquality( operand.firstElement() ); @@ -1309,9 +1309,9 @@ namespace mongo { ASSERT( !in.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( InExpression, MatchesArrayValue ) { + TEST( InMatchExpression, MatchesArrayValue ) { BSONObj operand = BSON_ARRAY( 5 ); - InExpression in; + InMatchExpression in; in.init( "a" ); in.getArrayFilterEntries()->addEquality( operand.firstElement() ); @@ -1320,10 +1320,10 @@ namespace mongo { ASSERT( !in.matches( BSON( "a" << BSON_ARRAY( BSON_ARRAY( 5 ) ) ), NULL ) ); } - TEST( InExpression, MatchesNull ) { + TEST( InMatchExpression, MatchesNull ) { BSONObj operand = BSON_ARRAY( BSONNULL ); - InExpression in; + InMatchExpression in; in.init( "a" ); in.getArrayFilterEntries()->addEquality( operand.firstElement() ); @@ -1332,9 +1332,9 @@ namespace mongo { ASSERT( !in.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( InExpression, MatchesMinKey ) { + TEST( InMatchExpression, MatchesMinKey ) { BSONObj operand = BSON_ARRAY( MinKey ); - InExpression in; + InMatchExpression in; in.init( "a" ); in.getArrayFilterEntries()->addEquality( operand.firstElement() ); @@ -1343,9 +1343,9 @@ namespace mongo { ASSERT( !in.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( InExpression, MatchesMaxKey ) { + TEST( InMatchExpression, MatchesMaxKey ) { BSONObj operand = BSON_ARRAY( MaxKey ); - InExpression in; + InMatchExpression in; in.init( "a" ); in.getArrayFilterEntries()->addEquality( operand.firstElement() ); @@ -1354,9 +1354,9 @@ namespace mongo { ASSERT( !in.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( InExpression, MatchesFullArray ) { + TEST( InMatchExpression, MatchesFullArray ) { BSONObj operand = BSON_ARRAY( BSON_ARRAY( 1 << 2 ) << 4 << 5 ); - InExpression in; + InMatchExpression in; in.init( "a" ); in.getArrayFilterEntries()->addEquality( operand[0] ); in.getArrayFilterEntries()->addEquality( operand[1] ); @@ -1368,9 +1368,9 @@ namespace mongo { ASSERT( !in.matches( BSON( "a" << 1 ), NULL ) ); } - TEST( InExpression, ElemMatchKey ) { + TEST( InMatchExpression, ElemMatchKey ) { BSONObj operand = BSON_ARRAY( 5 << 2 ); - InExpression in; + InMatchExpression in; in.init( "a" ); in.getArrayFilterEntries()->addEquality( operand[0] ); in.getArrayFilterEntries()->addEquality( operand[1] ); @@ -1387,97 +1387,97 @@ namespace mongo { } /** - TEST( InExpression, MatchesIndexKeyScalar ) { + TEST( InMatchExpression, MatchesIndexKeyScalar ) { BSONObj operand = BSON( "$in" << BSON_ARRAY( 6 << 5 ) ); - InExpression in; + InMatchExpression in; ASSERT( in.init( "a", operand[ "$in" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == in.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == in.matchesIndexKey( BSON( "" << 5 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == in.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == in.matchesIndexKey( BSON( "" << BSON_ARRAY( 6 ) ), indexSpec ) ); } - TEST( InExpression, MatchesIndexKeyMissing ) { + TEST( InMatchExpression, MatchesIndexKeyMissing ) { BSONObj operand = BSON( "$in" << BSON_ARRAY( 6 ) ); - ComparisonExpression eq + ComparisonMatchExpression eq ASSERT( eq.init( "a", operand[ "$in" ] ).isOK() ); IndexSpec indexSpec( BSON( "b" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == eq.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == eq.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == eq.matchesIndexKey( BSON( "" << BSON_ARRAY( 8 << 6 ) ), indexSpec ) ); } - TEST( InExpression, MatchesIndexKeyArray ) { + TEST( InMatchExpression, MatchesIndexKeyArray ) { BSONObj operand = BSON( "$in" << BSON_ARRAY( 4 << BSON_ARRAY( 5 ) ) ); - InExpression in; + InMatchExpression in; ASSERT( in.init( "a", operand[ "$in" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == in.matchesIndexKey( BSON( "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == in.matchesIndexKey( BSON( "" << 5 ), indexSpec ) ); } - TEST( InExpression, MatchesIndexKeyArrayValue ) { + TEST( InMatchExpression, MatchesIndexKeyArrayValue ) { BSONObjBuilder inArray; inArray.append( "0", 4 ).append( "1", 5 ).appendRegex( "2", "abc", "" ); BSONObj operand = BSONObjBuilder().appendArray( "$in", inArray.obj() ).obj(); - InExpression in; + InMatchExpression in; ASSERT( in.init( "a", operand[ "$in" ] ).isOK() ); IndexSpec indexSpec( BSON( "loc" << "mockarrayvalue" << "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == in.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 4 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == in.matchesIndexKey( BSON( "" << "dummygeohash" << "" << 6 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == in.matchesIndexKey( BSON( "" << "dummygeohash" << "" << "abcd" ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == in.matchesIndexKey( BSONObjBuilder() .append( "", "dummygeohash" ) .appendRegex( "", "abc", "" ).obj(), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == in.matchesIndexKey( BSON( "" << "dummygeohash" << "" << "ab" ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == in.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( 8 << 5 ) ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == in.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( 8 << 9 ) ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == in.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( 8 << "abc" ) ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == in.matchesIndexKey( BSON( "" << "dummygeohash" << "" << BSON_ARRAY( 8 << "ac" ) ), indexSpec ) ); } */ - TEST( NinExpression, MatchesElementSingle ) { + TEST( NinMatchExpression, MatchesElementSingle ) { BSONObj operands = BSON_ARRAY( 1 ); BSONObj match = BSON( "a" << 2 ); BSONObj notMatch = BSON( "a" << 1 ); - NinExpression nin; + NinMatchExpression nin; nin.getArrayFilterEntries()->addEquality( operands.firstElement() ); ASSERT( nin.matchesSingleElement( match[ "a" ] ) ); ASSERT( !nin.matchesSingleElement( notMatch[ "a" ] ) ); } - TEST( NinExpression, MatchesElementMultiple ) { + TEST( NinMatchExpression, MatchesElementMultiple ) { BSONArray operand = BSON_ARRAY( 1 << "r" << true << 1 ); BSONObj match = BSON( "a" << false ); BSONObj notMatchFirst = BSON( "a" << 1 ); BSONObj notMatchSecond = BSON( "a" << "r" ); BSONObj notMatchThird = BSON( "a" << true ); - NinExpression nin; + NinMatchExpression nin; nin.getArrayFilterEntries()->addEquality( operand[0] ); nin.getArrayFilterEntries()->addEquality( operand[1] ); nin.getArrayFilterEntries()->addEquality( operand[2] ); @@ -1488,9 +1488,9 @@ namespace mongo { ASSERT( !nin.matchesSingleElement( notMatchThird[ "a" ] ) ); } - TEST( NinExpression, MatchesScalar ) { + TEST( NinMatchExpression, MatchesScalar ) { BSONObj operand = BSON_ARRAY( 5 ); - NinExpression nin; + NinMatchExpression nin; nin.init( "a" ); nin.getArrayFilterEntries()->addEquality( operand.firstElement() ); ASSERT( nin.matches( BSON( "a" << 4 ), NULL ) ); @@ -1498,9 +1498,9 @@ namespace mongo { ASSERT( !nin.matches( BSON( "a" << 5.0 ), NULL ) ); } - TEST( NinExpression, MatchesArrayValue ) { + TEST( NinMatchExpression, MatchesArrayValue ) { BSONObj operand = BSON_ARRAY( 5 ); - NinExpression nin; + NinMatchExpression nin; nin.init( "a" ); nin.getArrayFilterEntries()->addEquality( operand.firstElement() ); ASSERT( !nin.matches( BSON( "a" << BSON_ARRAY( 5.0 << 6 ) ), NULL ) ); @@ -1508,11 +1508,11 @@ namespace mongo { ASSERT( nin.matches( BSON( "a" << BSON_ARRAY( BSON_ARRAY( 5 ) ) ), NULL ) ); } - TEST( NinExpression, MatchesNull ) { + TEST( NinMatchExpression, MatchesNull ) { BSONObjBuilder ninArray; ninArray.appendNull( "0" ); BSONObj operand = ninArray.obj(); - NinExpression nin; + NinMatchExpression nin; nin.init( "a" ); nin.getArrayFilterEntries()->addEquality( operand.firstElement() ); ASSERT( !nin.matches( BSONObj(), NULL ) ); @@ -1520,9 +1520,9 @@ namespace mongo { ASSERT( nin.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( NinExpression, MatchesFullArray ) { + TEST( NinMatchExpression, MatchesFullArray ) { BSONArray operand = BSON_ARRAY( BSON_ARRAY( 1 << 2 ) << 4 << 5 ); - NinExpression nin; + NinMatchExpression nin; nin.init( "a" ); nin.getArrayFilterEntries()->addEquality( operand[0] ); nin.getArrayFilterEntries()->addEquality( operand[1] ); @@ -1533,9 +1533,9 @@ namespace mongo { ASSERT( nin.matches( BSON( "a" << 1 ), NULL ) ); } - TEST( NinExpression, ElemMatchKey ) { + TEST( NinMatchExpression, ElemMatchKey ) { BSONArray operand = BSON_ARRAY( 5 << 2 ); - NinExpression nin; + NinMatchExpression nin; nin.init( "a" ); nin.getArrayFilterEntries()->addEquality( operand[0] ); nin.getArrayFilterEntries()->addEquality( operand[1] ); @@ -1552,13 +1552,13 @@ namespace mongo { } /** - TEST( NinExpression, MatchesIndexKey ) { + TEST( NinMatchExpression, MatchesIndexKey ) { BSONObj operand = BSON( "$nin" << BSON_ARRAY( 5 ) ); - NinExpression nin; + NinMatchExpression nin; ASSERT( nin.init( "a", operand[ "$nin" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << "7" ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == nin.matchesIndexKey( indexKey, indexSpec ) ); } */ |