diff options
Diffstat (limited to 'src')
21 files changed, 996 insertions, 996 deletions
diff --git a/src/mongo/db/matcher/expression.cpp b/src/mongo/db/matcher/expression.cpp index a05d15926bb..4b9b9f020ba 100644 --- a/src/mongo/db/matcher/expression.cpp +++ b/src/mongo/db/matcher/expression.cpp @@ -25,13 +25,13 @@ namespace mongo { - string Expression::toString() const { + string MatchExpression::toString() const { StringBuilder buf; debugString( buf, 0 ); return buf.str(); } - void Expression::_debugAddSpace( StringBuilder& debug, int level ) const { + void MatchExpression::_debugAddSpace( StringBuilder& debug, int level ) const { for ( int i = 0; i < level; i++ ) debug << " "; } diff --git a/src/mongo/db/matcher/expression.h b/src/mongo/db/matcher/expression.h index d292cf7fc9c..c91f44c1a33 100644 --- a/src/mongo/db/matcher/expression.h +++ b/src/mongo/db/matcher/expression.h @@ -25,14 +25,14 @@ namespace mongo { - class TreeExpression; + class TreeMatchExpression; - class Expression { - MONGO_DISALLOW_COPYING( Expression ); + class MatchExpression { + MONGO_DISALLOW_COPYING( MatchExpression ); public: - Expression(){} - virtual ~Expression(){} + MatchExpression(){} + virtual ~MatchExpression(){} /** * determins if the doc matches the expression diff --git a/src/mongo/db/matcher/expression_array.cpp b/src/mongo/db/matcher/expression_array.cpp index 18582d7dfa6..73be4fb4275 100644 --- a/src/mongo/db/matcher/expression_array.cpp +++ b/src/mongo/db/matcher/expression_array.cpp @@ -28,12 +28,12 @@ namespace mongo { // ---------- - Status AllExpression::init( const StringData& path ) { + Status AllMatchExpression::init( const StringData& path ) { _path = path; return Status::OK(); } - bool AllExpression::matches( const BSONObj& doc, MatchDetails* details ) const { + bool AllMatchExpression::matches( const BSONObj& doc, MatchDetails* details ) const { FieldRef path; path.parse(_path); @@ -61,7 +61,7 @@ namespace mongo { return _match( all ); } - bool AllExpression::matchesSingleElement( const BSONElement& e ) const { + bool AllMatchExpression::matchesSingleElement( const BSONElement& e ) const { if ( _arrayEntries.size() == 0 ) return false; @@ -84,7 +84,7 @@ namespace mongo { return _match( all ); } - bool AllExpression::_match( const BSONElementSet& all ) const { + bool AllMatchExpression::_match( const BSONElementSet& all ) const { if ( all.size() == 0 ) return _arrayEntries.singleNull(); @@ -114,14 +114,14 @@ namespace mongo { return true; } - void AllExpression::debugString( StringBuilder& debug, int level ) const { + void AllMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " $all TODO\n"; } // ------- - bool ArrayMatchingExpression::matches( const BSONObj& doc, MatchDetails* details ) const { + bool ArrayMatchingMatchExpression::matches( const BSONObj& doc, MatchDetails* details ) const { FieldRef path; path.parse(_path); @@ -163,7 +163,7 @@ namespace mongo { return false; } - bool ArrayMatchingExpression::matchesSingleElement( const BSONElement& e ) const { + bool ArrayMatchingMatchExpression::matchesSingleElement( const BSONElement& e ) const { if ( e.type() != Array ) return false; return matchesArray( e.Obj(), NULL ); @@ -172,7 +172,7 @@ namespace mongo { // ------- - Status ElemMatchObjectExpression::init( const StringData& path, const Expression* sub ) { + Status ElemMatchObjectMatchExpression::init( const StringData& path, const MatchExpression* sub ) { _path = path; _sub.reset( sub ); return Status::OK(); @@ -180,7 +180,7 @@ namespace mongo { - bool ElemMatchObjectExpression::matchesArray( const BSONObj& anArray, MatchDetails* details ) const { + bool ElemMatchObjectMatchExpression::matchesArray( const BSONObj& anArray, MatchDetails* details ) const { BSONObjIterator i( anArray ); while ( i.more() ) { BSONElement inner = i.next(); @@ -196,7 +196,7 @@ namespace mongo { return false; } - void ElemMatchObjectExpression::debugString( StringBuilder& debug, int level ) const { + void ElemMatchObjectMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " $elemMatch\n"; _sub->debugString( debug, level + 1 ); @@ -205,30 +205,30 @@ namespace mongo { // ------- - ElemMatchValueExpression::~ElemMatchValueExpression() { + ElemMatchValueMatchExpression::~ElemMatchValueMatchExpression() { for ( unsigned i = 0; i < _subs.size(); i++ ) delete _subs[i]; _subs.clear(); } - Status ElemMatchValueExpression::init( const StringData& path, const Expression* sub ) { + Status ElemMatchValueMatchExpression::init( const StringData& path, const MatchExpression* sub ) { init( path ); add( sub ); return Status::OK(); } - Status ElemMatchValueExpression::init( const StringData& path ) { + Status ElemMatchValueMatchExpression::init( const StringData& path ) { _path = path; return Status::OK(); } - void ElemMatchValueExpression::add( const Expression* sub ) { + void ElemMatchValueMatchExpression::add( const MatchExpression* sub ) { verify( sub ); _subs.push_back( sub ); } - bool ElemMatchValueExpression::matchesArray( const BSONObj& anArray, MatchDetails* details ) const { + bool ElemMatchValueMatchExpression::matchesArray( const BSONObj& anArray, MatchDetails* details ) const { BSONObjIterator i( anArray ); while ( i.more() ) { BSONElement inner = i.next(); @@ -243,7 +243,7 @@ namespace mongo { return false; } - bool ElemMatchValueExpression::_arrayElementMatchesAll( const BSONElement& e ) const { + bool ElemMatchValueMatchExpression::_arrayElementMatchesAll( const BSONElement& e ) const { for ( unsigned i = 0; i < _subs.size(); i++ ) { if ( !_subs[i]->matchesSingleElement( e ) ) return false; @@ -251,7 +251,7 @@ namespace mongo { return true; } - void ElemMatchValueExpression::debugString( StringBuilder& debug, int level ) const { + void ElemMatchValueMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " $elemMatch\n"; for ( unsigned i = 0; i < _subs.size(); i++ ) { @@ -273,7 +273,7 @@ namespace mongo { return Status::OK(); } - void AllElemMatchOp::add( const ArrayMatchingExpression* expr ) { + void AllElemMatchOp::add( const ArrayMatchingMatchExpression* expr ) { verify( expr ); _list.push_back( expr ); } @@ -322,19 +322,19 @@ namespace mongo { // --------- - Status SizeExpression::init( const StringData& path, int size ) { + Status SizeMatchExpression::init( const StringData& path, int size ) { _path = path; _size = size; return Status::OK(); } - bool SizeExpression::matchesArray( const BSONObj& anArray, MatchDetails* details ) const { + bool SizeMatchExpression::matchesArray( const BSONObj& anArray, MatchDetails* details ) const { if ( _size < 0 ) return false; return anArray.nFields() == _size; } - void SizeExpression::debugString( StringBuilder& debug, int level ) const { + void SizeMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " $size : " << _size << "\n"; } diff --git a/src/mongo/db/matcher/expression_array.h b/src/mongo/db/matcher/expression_array.h index 07856284d9a..1d467a16ad1 100644 --- a/src/mongo/db/matcher/expression_array.h +++ b/src/mongo/db/matcher/expression_array.h @@ -28,7 +28,7 @@ namespace mongo { /** - * this SHOULD extend from ArrayMatchingExpression + * this SHOULD extend from ArrayMatchingMatchExpression * the only reason it can't is > db.foo.insert( { x : 5 } ) @@ -40,7 +40,7 @@ namespace mongo { * the { x : 5} doc should NOT match * */ - class AllExpression : public Expression { + class AllMatchExpression : public MatchExpression { public: Status init( const StringData& path ); ArrayFilterEntries* getArrayFilterEntries() { return &_arrayEntries; } @@ -58,9 +58,9 @@ namespace mongo { }; - class ArrayMatchingExpression : public Expression { + class ArrayMatchingMatchExpression : public MatchExpression { public: - virtual ~ArrayMatchingExpression(){} + virtual ~ArrayMatchingMatchExpression(){} virtual bool matches( const BSONObj& doc, MatchDetails* details ) const; @@ -76,24 +76,24 @@ namespace mongo { }; - class ElemMatchObjectExpression : public ArrayMatchingExpression { + class ElemMatchObjectMatchExpression : public ArrayMatchingMatchExpression { public: - Status init( const StringData& path, const Expression* sub ); + Status init( const StringData& path, const MatchExpression* sub ); bool matchesArray( const BSONObj& anArray, MatchDetails* details ) const; virtual void debugString( StringBuilder& debug, int level ) const; private: - boost::scoped_ptr<const Expression> _sub; + boost::scoped_ptr<const MatchExpression> _sub; }; - class ElemMatchValueExpression : public ArrayMatchingExpression { + class ElemMatchValueMatchExpression : public ArrayMatchingMatchExpression { public: - virtual ~ElemMatchValueExpression(); + virtual ~ElemMatchValueMatchExpression(); Status init( const StringData& path ); - Status init( const StringData& path, const Expression* sub ); - void add( const Expression* sub ); + Status init( const StringData& path, const MatchExpression* sub ); + void add( const MatchExpression* sub ); bool matchesArray( const BSONObj& anArray, MatchDetails* details ) const; @@ -101,19 +101,19 @@ namespace mongo { private: bool _arrayElementMatchesAll( const BSONElement& e ) const; - std::vector< const Expression* > _subs; + std::vector< const MatchExpression* > _subs; }; /** - * i'm suprised this isn't a regular AllExpression + * i'm suprised this isn't a regular AllMatchExpression */ - class AllElemMatchOp : public Expression { + class AllElemMatchOp : public MatchExpression { public: virtual ~AllElemMatchOp(); Status init( const StringData& path ); - void add( const ArrayMatchingExpression* expr ); + void add( const ArrayMatchingMatchExpression* expr ); virtual bool matches( const BSONObj& doc, MatchDetails* details ) const; @@ -127,10 +127,10 @@ namespace mongo { bool _allMatch( const BSONObj& anArray ) const; StringData _path; - std::vector< const ArrayMatchingExpression* > _list; + std::vector< const ArrayMatchingMatchExpression* > _list; }; - class SizeExpression : public ArrayMatchingExpression { + class SizeMatchExpression : public ArrayMatchingMatchExpression { public: Status init( const StringData& path, int size ); diff --git a/src/mongo/db/matcher/expression_array_test.cpp b/src/mongo/db/matcher/expression_array_test.cpp index 879e0a24404..eceac5a4cde 100644 --- a/src/mongo/db/matcher/expression_array_test.cpp +++ b/src/mongo/db/matcher/expression_array_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" @@ -26,11 +26,11 @@ namespace mongo { - TEST( AllExpression, MatchesElementSingle ) { + TEST( AllMatchExpression, MatchesElementSingle ) { BSONObj operand = BSON_ARRAY( 1 << 1 ); BSONObj match = BSON( "a" << 1 ); BSONObj notMatch = BSON( "a" << 2 ); - AllExpression all; + AllMatchExpression all; all.getArrayFilterEntries()->addEquality( operand[0] ); all.getArrayFilterEntries()->addEquality( operand[1] ); @@ -38,19 +38,19 @@ namespace mongo { ASSERT( !all.matchesSingleElement( notMatch[ "a" ] ) ); } - TEST( AllExpression, MatchesEmpty ) { + TEST( AllMatchExpression, MatchesEmpty ) { BSONObj notMatch = BSON( "a" << 2 ); - AllExpression all; + AllMatchExpression all; ASSERT( !all.matchesSingleElement( notMatch[ "a" ] ) ); ASSERT( !all.matches( BSON( "a" << 1 ), NULL ) ); ASSERT( !all.matches( BSONObj(), NULL ) ); } - TEST( AllExpression, MatchesElementMultiple ) { + TEST( AllMatchExpression, MatchesElementMultiple ) { BSONObj operand = BSON_ARRAY( 1 << "r" ); - AllExpression all; + AllMatchExpression all; all.getArrayFilterEntries()->addEquality( operand[0] ); all.getArrayFilterEntries()->addEquality( operand[1] ); @@ -63,9 +63,9 @@ namespace mongo { ASSERT( !all.matchesSingleElement( notMatchArray[ "a" ] ) ); } - TEST( AllExpression, MatchesScalar ) { + TEST( AllMatchExpression, MatchesScalar ) { BSONObj operand = BSON_ARRAY( 5 ); - AllExpression all; + AllMatchExpression all; all.init( "a" ); all.getArrayFilterEntries()->addEquality( operand[0] ); @@ -73,9 +73,9 @@ namespace mongo { ASSERT( !all.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( AllExpression, MatchesArrayValue ) { + TEST( AllMatchExpression, MatchesArrayValue ) { BSONObj operand = BSON_ARRAY( 5 ); - AllExpression all; + AllMatchExpression all; all.init( "a" ); all.getArrayFilterEntries()->addEquality( operand[0] ); @@ -84,9 +84,9 @@ namespace mongo { ASSERT( !all.matches( BSON( "a" << BSON_ARRAY( BSON_ARRAY( 5 ) ) ), NULL ) ); } - TEST( AllExpression, MatchesNonArrayMultiValues ) { + TEST( AllMatchExpression, MatchesNonArrayMultiValues ) { BSONObj operand = BSON_ARRAY( 5 << 6 ); - AllExpression all; + AllMatchExpression all; all.init( "a.b" ); all.getArrayFilterEntries()->addEquality( operand[0] ); all.getArrayFilterEntries()->addEquality( operand[1] ); @@ -100,9 +100,9 @@ namespace mongo { NULL ) ); } - TEST( AllExpression, MatchesArrayAndNonArrayMultiValues ) { + TEST( AllMatchExpression, MatchesArrayAndNonArrayMultiValues ) { BSONObj operand = BSON_ARRAY( 1 << 2 << 3 << 4 ); - AllExpression all; + AllMatchExpression all; all.init( "a.b" ); all.getArrayFilterEntries()->addEquality( operand[0] ); all.getArrayFilterEntries()->addEquality( operand[1] ); @@ -116,12 +116,12 @@ namespace mongo { NULL ) ); } - TEST( AllExpression, MatchesNull ) { + TEST( AllMatchExpression, MatchesNull ) { BSONObjBuilder allArray; allArray.appendNull( "0" ); BSONObj operand = allArray.obj(); - AllExpression all; + AllMatchExpression all; ASSERT( all.init( "a" ).isOK() ); all.getArrayFilterEntries()->addEquality( operand[0] ); @@ -130,9 +130,9 @@ namespace mongo { ASSERT( !all.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( AllExpression, MatchesFullArray ) { + TEST( AllMatchExpression, MatchesFullArray ) { BSONObj operand = BSON_ARRAY( BSON_ARRAY( 1 << 2 ) << 1 ); - AllExpression all; + AllMatchExpression all; ASSERT( all.init( "a" ).isOK() ); all.getArrayFilterEntries()->addEquality( operand[0] ); all.getArrayFilterEntries()->addEquality( operand[1] ); @@ -144,9 +144,9 @@ namespace mongo { ASSERT( !all.matches( BSON( "a" << 1 ), NULL ) ); } - TEST( AllExpression, ElemMatchKey ) { + TEST( AllMatchExpression, ElemMatchKey ) { BSONObj operand = BSON_ARRAY( 5 ); - AllExpression all; + AllMatchExpression all; ASSERT( all.init( "a" ).isOK() ); all.getArrayFilterEntries()->addEquality( operand[0] ); @@ -161,9 +161,9 @@ namespace mongo { ASSERT( !details.hasElemMatchKey() ); } - TEST( AllExpression, MatchesMinKey ) { + TEST( AllMatchExpression, MatchesMinKey ) { BSONObj operand = BSON_ARRAY( MinKey ); - AllExpression all; + AllMatchExpression all; ASSERT( all.init( "a" ).isOK() ); all.getArrayFilterEntries()->addEquality( operand[0] ); @@ -172,9 +172,9 @@ namespace mongo { ASSERT( !all.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( AllExpression, MatchesMaxKey ) { + TEST( AllMatchExpression, MatchesMaxKey ) { BSONObj operand = BSON_ARRAY( MaxKey ); - AllExpression all; + AllMatchExpression all; ASSERT( all.init( "a" ).isOK() ); all.getArrayFilterEntries()->addEquality( operand[0] ); @@ -184,42 +184,42 @@ namespace mongo { } /** - TEST( AllExpression, MatchesIndexKey ) { + TEST( AllMatchExpression, MatchesIndexKey ) { BSONObj operand = BSON( "$all" << BSON_ARRAY( 5 ) ); - AllExpression all; + AllMatchExpression all; ASSERT( all.init( "a", operand[ "$all" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << "7" ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == all.matchesIndexKey( indexKey, indexSpec ) ); } */ - TEST( ElemMatchObjectExpression, MatchesElementSingle ) { + TEST( ElemMatchObjectMatchExpression, MatchesElementSingle ) { BSONObj baseOperand = BSON( "b" << 5 ); BSONObj match = BSON( "a" << BSON_ARRAY( BSON( "b" << 5.0 ) ) ); BSONObj notMatch = BSON( "a" << BSON_ARRAY( BSON( "b" << 6 ) ) ); - auto_ptr<ComparisonExpression> eq( new ComparisonExpression() ); - ASSERT( eq->init( "b", ComparisonExpression::EQ, baseOperand[ "b" ] ).isOK() ); - ElemMatchObjectExpression op; + auto_ptr<ComparisonMatchExpression> eq( new ComparisonMatchExpression() ); + ASSERT( eq->init( "b", ComparisonMatchExpression::EQ, baseOperand[ "b" ] ).isOK() ); + ElemMatchObjectMatchExpression op; ASSERT( op.init( "a", eq.release() ).isOK() ); ASSERT( op.matchesSingleElement( match[ "a" ] ) ); ASSERT( !op.matchesSingleElement( notMatch[ "a" ] ) ); } - TEST( ElemMatchObjectExpression, MatchesElementArray ) { + TEST( ElemMatchObjectMatchExpression, MatchesElementArray ) { BSONObj baseOperand = BSON( "1" << 5 ); BSONObj match = BSON( "a" << BSON_ARRAY( BSON_ARRAY( 's' << 5.0 ) ) ); BSONObj notMatch = BSON( "a" << BSON_ARRAY( BSON_ARRAY( 5 << 6 ) ) ); - auto_ptr<ComparisonExpression> eq( new ComparisonExpression() ); - ASSERT( eq->init( "1", ComparisonExpression::EQ, baseOperand[ "1" ] ).isOK() ); - ElemMatchObjectExpression op; + auto_ptr<ComparisonMatchExpression> eq( new ComparisonMatchExpression() ); + ASSERT( eq->init( "1", ComparisonMatchExpression::EQ, baseOperand[ "1" ] ).isOK() ); + ElemMatchObjectMatchExpression op; ASSERT( op.init( "a", eq.release() ).isOK() ); ASSERT( op.matchesSingleElement( match[ "a" ] ) ); ASSERT( !op.matchesSingleElement( notMatch[ "a" ] ) ); } - TEST( ElemMatchObjectExpression, MatchesElementMultiple ) { + TEST( ElemMatchObjectMatchExpression, MatchesElementMultiple ) { BSONObj baseOperand1 = BSON( "b" << 5 ); BSONObj baseOperand2 = BSON( "b" << 6 ); BSONObj baseOperand3 = BSON( "c" << 7 ); @@ -228,19 +228,19 @@ namespace mongo { BSONObj notMatch3 = BSON( "a" << BSON_ARRAY( BSON( "b" << BSON_ARRAY( 5 << 6 ) ) ) ); BSONObj match = BSON( "a" << BSON_ARRAY( BSON( "b" << BSON_ARRAY( 5 << 6 ) << "c" << 7 ) ) ); - auto_ptr<ComparisonExpression> eq1( new ComparisonExpression() ); - ASSERT( eq1->init( "b", ComparisonExpression::EQ, baseOperand1[ "b" ] ).isOK() ); - auto_ptr<ComparisonExpression> eq2( new ComparisonExpression() ); - ASSERT( eq2->init( "b", ComparisonExpression::EQ, baseOperand2[ "b" ] ).isOK() ); - auto_ptr<ComparisonExpression> eq3( new ComparisonExpression() ); - ASSERT( eq3->init( "c", ComparisonExpression::EQ, baseOperand3[ "c" ] ).isOK() ); - - auto_ptr<AndExpression> andOp( new AndExpression() ); + auto_ptr<ComparisonMatchExpression> eq1( new ComparisonMatchExpression() ); + ASSERT( eq1->init( "b", ComparisonMatchExpression::EQ, baseOperand1[ "b" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> eq2( new ComparisonMatchExpression() ); + ASSERT( eq2->init( "b", ComparisonMatchExpression::EQ, baseOperand2[ "b" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> eq3( new ComparisonMatchExpression() ); + ASSERT( eq3->init( "c", ComparisonMatchExpression::EQ, baseOperand3[ "c" ] ).isOK() ); + + auto_ptr<AndMatchExpression> andOp( new AndMatchExpression() ); andOp->add( eq1.release() ); andOp->add( eq2.release() ); andOp->add( eq3.release() ); - ElemMatchObjectExpression op; + ElemMatchObjectMatchExpression op; ASSERT( op.init( "a", andOp.release() ).isOK() ); ASSERT( !op.matchesSingleElement( notMatch1[ "a" ] ) ); ASSERT( !op.matchesSingleElement( notMatch2[ "a" ] ) ); @@ -248,11 +248,11 @@ namespace mongo { ASSERT( op.matchesSingleElement( match[ "a" ] ) ); } - TEST( ElemMatchObjectExpression, MatchesNonArray ) { + TEST( ElemMatchObjectMatchExpression, MatchesNonArray ) { BSONObj baseOperand = BSON( "b" << 5 ); - auto_ptr<ComparisonExpression> eq( new ComparisonExpression() ); - ASSERT( eq->init( "b", ComparisonExpression::EQ, baseOperand[ "b" ] ).isOK() ); - ElemMatchObjectExpression op; + auto_ptr<ComparisonMatchExpression> eq( new ComparisonMatchExpression() ); + ASSERT( eq->init( "b", ComparisonMatchExpression::EQ, baseOperand[ "b" ] ).isOK() ); + ElemMatchObjectMatchExpression op; ASSERT( op.init( "a", eq.release() ).isOK() ); // Directly nested objects are not matched with $elemMatch. An intervening array is // required. @@ -261,11 +261,11 @@ namespace mongo { ASSERT( !op.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( ElemMatchObjectExpression, MatchesArrayObject ) { + TEST( ElemMatchObjectMatchExpression, MatchesArrayObject ) { BSONObj baseOperand = BSON( "b" << 5 ); - auto_ptr<ComparisonExpression> eq( new ComparisonExpression() ); - ASSERT( eq->init( "b", ComparisonExpression::EQ, baseOperand[ "b" ] ).isOK() ); - ElemMatchObjectExpression op; + auto_ptr<ComparisonMatchExpression> eq( new ComparisonMatchExpression() ); + ASSERT( eq->init( "b", ComparisonMatchExpression::EQ, baseOperand[ "b" ] ).isOK() ); + ElemMatchObjectMatchExpression op; ASSERT( op.init( "a", eq.release() ).isOK() ); ASSERT( op.matches( BSON( "a" << BSON_ARRAY( BSON( "b" << 5 ) ) ), NULL ) ); ASSERT( op.matches( BSON( "a" << BSON_ARRAY( 4 << BSON( "b" << 5 ) ) ), NULL ) ); @@ -274,11 +274,11 @@ namespace mongo { NULL ) ); } - TEST( ElemMatchObjectExpression, MatchesMultipleNamedValues ) { + TEST( ElemMatchObjectMatchExpression, MatchesMultipleNamedValues ) { BSONObj baseOperand = BSON( "c" << 5 ); - auto_ptr<ComparisonExpression> eq( new ComparisonExpression() ); - ASSERT( eq->init( "c", ComparisonExpression::EQ, baseOperand[ "c" ] ).isOK() ); - ElemMatchObjectExpression op; + auto_ptr<ComparisonMatchExpression> eq( new ComparisonMatchExpression() ); + ASSERT( eq->init( "c", ComparisonMatchExpression::EQ, baseOperand[ "c" ] ).isOK() ); + ElemMatchObjectMatchExpression op; ASSERT( op.init( "a.b", eq.release() ).isOK() ); ASSERT( op.matches( BSON( "a" << BSON_ARRAY( BSON( "b" << @@ -295,11 +295,11 @@ namespace mongo { NULL ) ); } - TEST( ElemMatchObjectExpression, ElemMatchKey ) { + TEST( ElemMatchObjectMatchExpression, ElemMatchKey ) { BSONObj baseOperand = BSON( "c" << 6 ); - auto_ptr<ComparisonExpression> eq( new ComparisonExpression() ); - ASSERT( eq->init( "c", ComparisonExpression::EQ, baseOperand[ "c" ] ).isOK() ); - ElemMatchObjectExpression op; + auto_ptr<ComparisonMatchExpression> eq( new ComparisonMatchExpression() ); + ASSERT( eq->init( "c", ComparisonMatchExpression::EQ, baseOperand[ "c" ] ).isOK() ); + ElemMatchObjectMatchExpression op; ASSERT( op.init( "a.b", eq.release() ).isOK() ); MatchDetails details; details.requestElemMatchKey(); @@ -325,43 +325,43 @@ namespace mongo { } /** - TEST( ElemMatchObjectExpression, MatchesIndexKey ) { + TEST( ElemMatchObjectMatchExpression, MatchesIndexKey ) { BSONObj baseOperand = BSON( "b" << 5 ); - auto_ptr<ComparisonExpression> eq( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> eq( new ComparisonMatchExpression() ); ASSERT( eq->init( "b", baseOperand[ "b" ] ).isOK() ); - ElemMatchObjectExpression op; + ElemMatchObjectMatchExpression op; ASSERT( op.init( "a", eq.release() ).isOK() ); IndexSpec indexSpec( BSON( "a.b" << 1 ) ); BSONObj indexKey = BSON( "" << "5" ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == op.matchesIndexKey( indexKey, indexSpec ) ); } */ - TEST( ElemMatchValueExpression, MatchesElementSingle ) { + TEST( ElemMatchValueMatchExpression, MatchesElementSingle ) { BSONObj baseOperand = BSON( "$gt" << 5 ); BSONObj match = BSON( "a" << BSON_ARRAY( 6 ) ); BSONObj notMatch = BSON( "a" << BSON_ARRAY( 4 ) ); - auto_ptr<ComparisonExpression> gt( new ComparisonExpression() ); - ASSERT( gt->init( "", ComparisonExpression::GT, baseOperand[ "$gt" ] ).isOK() ); - ElemMatchValueExpression op; + auto_ptr<ComparisonMatchExpression> gt( new ComparisonMatchExpression() ); + ASSERT( gt->init( "", ComparisonMatchExpression::GT, baseOperand[ "$gt" ] ).isOK() ); + ElemMatchValueMatchExpression op; ASSERT( op.init( "a", gt.release() ).isOK() ); ASSERT( op.matchesSingleElement( match[ "a" ] ) ); ASSERT( !op.matchesSingleElement( notMatch[ "a" ] ) ); } - TEST( ElemMatchValueExpression, MatchesElementMultiple ) { + TEST( ElemMatchValueMatchExpression, MatchesElementMultiple ) { BSONObj baseOperand1 = BSON( "$gt" << 1 ); BSONObj baseOperand2 = BSON( "$lt" << 10 ); BSONObj notMatch1 = BSON( "a" << BSON_ARRAY( 0 << 1 ) ); BSONObj notMatch2 = BSON( "a" << BSON_ARRAY( 10 << 11 ) ); BSONObj match = BSON( "a" << BSON_ARRAY( 0 << 5 << 11 ) ); - auto_ptr<ComparisonExpression> gt( new ComparisonExpression() ); - ASSERT( gt->init( "", ComparisonExpression::GT, baseOperand1[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> lt( new ComparisonExpression() ); - ASSERT( lt->init( "", ComparisonExpression::LT, baseOperand2[ "$lt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> gt( new ComparisonMatchExpression() ); + ASSERT( gt->init( "", ComparisonMatchExpression::GT, baseOperand1[ "$gt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); + ASSERT( lt->init( "", ComparisonMatchExpression::LT, baseOperand2[ "$lt" ] ).isOK() ); - ElemMatchValueExpression op; + ElemMatchValueMatchExpression op; ASSERT( op.init( "a" ).isOK() ); op.add( gt.release() ); op.add( lt.release() ); @@ -371,11 +371,11 @@ namespace mongo { ASSERT( op.matchesSingleElement( match[ "a" ] ) ); } - TEST( ElemMatchValueExpression, MatchesNonArray ) { + TEST( ElemMatchValueMatchExpression, MatchesNonArray ) { BSONObj baseOperand = BSON( "$gt" << 5 ); - auto_ptr<ComparisonExpression> gt( new ComparisonExpression() ); - ASSERT( gt->init( "", ComparisonExpression::GT, baseOperand[ "$gt" ] ).isOK() ); - ElemMatchObjectExpression op; + auto_ptr<ComparisonMatchExpression> gt( new ComparisonMatchExpression() ); + ASSERT( gt->init( "", ComparisonMatchExpression::GT, baseOperand[ "$gt" ] ).isOK() ); + ElemMatchObjectMatchExpression op; ASSERT( op.init( "a", gt.release() ).isOK() ); // Directly nested objects are not matched with $elemMatch. An intervening array is // required. @@ -383,22 +383,22 @@ namespace mongo { ASSERT( !op.matches( BSON( "a" << BSON( "0" << 6 ) ), NULL ) ); } - TEST( ElemMatchValueExpression, MatchesArrayScalar ) { + TEST( ElemMatchValueMatchExpression, MatchesArrayScalar ) { BSONObj baseOperand = BSON( "$gt" << 5 ); - auto_ptr<ComparisonExpression> gt( new ComparisonExpression() ); - ASSERT( gt->init( "", ComparisonExpression::GT, baseOperand[ "$gt" ] ).isOK() ); - ElemMatchValueExpression op; + auto_ptr<ComparisonMatchExpression> gt( new ComparisonMatchExpression() ); + ASSERT( gt->init( "", ComparisonMatchExpression::GT, baseOperand[ "$gt" ] ).isOK() ); + ElemMatchValueMatchExpression op; ASSERT( op.init( "a", gt.release() ).isOK() ); ASSERT( op.matches( BSON( "a" << BSON_ARRAY( 6 ) ), NULL ) ); ASSERT( op.matches( BSON( "a" << BSON_ARRAY( 4 << 6 ) ), NULL ) ); ASSERT( op.matches( BSON( "a" << BSON_ARRAY( BSONObj() << 7 ) ), NULL ) ); } - TEST( ElemMatchValueExpression, MatchesMultipleNamedValues ) { + TEST( ElemMatchValueMatchExpression, MatchesMultipleNamedValues ) { BSONObj baseOperand = BSON( "$gt" << 5 ); - auto_ptr<ComparisonExpression> gt( new ComparisonExpression() ); - ASSERT( gt->init( "", ComparisonExpression::GT, baseOperand[ "$gt" ] ).isOK() ); - ElemMatchValueExpression op; + auto_ptr<ComparisonMatchExpression> gt( new ComparisonMatchExpression() ); + ASSERT( gt->init( "", ComparisonMatchExpression::GT, baseOperand[ "$gt" ] ).isOK() ); + ElemMatchValueMatchExpression op; ASSERT( op.init( "a.b", gt.release() ).isOK() ); ASSERT( op.matches( BSON( "a" << BSON_ARRAY( BSON( "b" << BSON_ARRAY( 6 ) ) ) ), NULL ) ); ASSERT( op.matches( BSON( "a" << @@ -407,11 +407,11 @@ namespace mongo { NULL ) ); } - TEST( ElemMatchValueExpression, ElemMatchKey ) { + TEST( ElemMatchValueMatchExpression, ElemMatchKey ) { BSONObj baseOperand = BSON( "$gt" << 6 ); - auto_ptr<ComparisonExpression> gt( new ComparisonExpression() ); - ASSERT( gt->init( "", ComparisonExpression::GT, baseOperand[ "$gt" ] ).isOK() ); - ElemMatchValueExpression op; + auto_ptr<ComparisonMatchExpression> gt( new ComparisonMatchExpression() ); + ASSERT( gt->init( "", ComparisonMatchExpression::GT, baseOperand[ "$gt" ] ).isOK() ); + ElemMatchValueMatchExpression op; ASSERT( op.init( "a.b", gt.release() ).isOK() ); MatchDetails details; details.requestElemMatchKey(); @@ -435,15 +435,15 @@ namespace mongo { } /** - TEST( ElemMatchValueExpression, MatchesIndexKey ) { + TEST( ElemMatchValueMatchExpression, MatchesIndexKey ) { BSONObj baseOperand = BSON( "$lt" << 5 ); - auto_ptr<LtOp> lt( new ComparisonExpression() ); + auto_ptr<LtOp> lt( new ComparisonMatchExpression() ); ASSERT( lt->init( "a", baseOperand[ "$lt" ] ).isOK() ); - ElemMatchValueExpression op; + ElemMatchValueMatchExpression op; ASSERT( op.init( "a", lt.release() ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << "3" ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == op.matchesIndexKey( indexKey, indexSpec ) ); } */ @@ -452,35 +452,35 @@ namespace mongo { BSONObj baseOperanda1 = BSON( "a" << 1 ); - auto_ptr<ComparisonExpression> eqa1( new ComparisonExpression() ); - ASSERT( eqa1->init( "a", ComparisonExpression::EQ, baseOperanda1[ "a" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> eqa1( new ComparisonMatchExpression() ); + ASSERT( eqa1->init( "a", ComparisonMatchExpression::EQ, baseOperanda1[ "a" ] ).isOK() ); BSONObj baseOperandb1 = BSON( "b" << 1 ); - auto_ptr<ComparisonExpression> eqb1( new ComparisonExpression() ); - ASSERT( eqb1->init( "b", ComparisonExpression::EQ, baseOperandb1[ "b" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> eqb1( new ComparisonMatchExpression() ); + ASSERT( eqb1->init( "b", ComparisonMatchExpression::EQ, baseOperandb1[ "b" ] ).isOK() ); - auto_ptr<AndExpression> and1( new AndExpression() ); + auto_ptr<AndMatchExpression> and1( new AndMatchExpression() ); and1->add( eqa1.release() ); and1->add( eqb1.release() ); // and1 = { a : 1, b : 1 } - auto_ptr<ElemMatchObjectExpression> elemMatch1( new ElemMatchObjectExpression() ); + auto_ptr<ElemMatchObjectMatchExpression> elemMatch1( new ElemMatchObjectMatchExpression() ); elemMatch1->init( "x", and1.release() ); // elemMatch1 = { x : { $elemMatch : { a : 1, b : 1 } } } BSONObj baseOperanda2 = BSON( "a" << 2 ); - auto_ptr<ComparisonExpression> eqa2( new ComparisonExpression() ); - ASSERT( eqa2->init( "a", ComparisonExpression::EQ, baseOperanda2[ "a" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> eqa2( new ComparisonMatchExpression() ); + ASSERT( eqa2->init( "a", ComparisonMatchExpression::EQ, baseOperanda2[ "a" ] ).isOK() ); BSONObj baseOperandb2 = BSON( "b" << 2 ); - auto_ptr<ComparisonExpression> eqb2( new ComparisonExpression() ); - ASSERT( eqb2->init( "b", ComparisonExpression::EQ, baseOperandb2[ "b" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> eqb2( new ComparisonMatchExpression() ); + ASSERT( eqb2->init( "b", ComparisonMatchExpression::EQ, baseOperandb2[ "b" ] ).isOK() ); - auto_ptr<AndExpression> and2( new AndExpression() ); + auto_ptr<AndMatchExpression> and2( new AndMatchExpression() ); and2->add( eqa2.release() ); and2->add( eqb2.release() ); - auto_ptr<ElemMatchObjectExpression> elemMatch2( new ElemMatchObjectExpression() ); + auto_ptr<ElemMatchObjectMatchExpression> elemMatch2( new ElemMatchObjectMatchExpression() ); elemMatch2->init( "x", and2.release() ); // elemMatch2 = { x : { $elemMatch : { a : 2, b : 2 } } } @@ -510,27 +510,27 @@ namespace mongo { TEST( AllElemMatchOp, Matches ) { BSONObj baseOperandgt1 = BSON( "$gt" << 1 ); - auto_ptr<ComparisonExpression> gt1( new ComparisonExpression() ); - ASSERT( gt1->init( "", ComparisonExpression::GT, baseOperandgt1[ "$gt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> gt1( new ComparisonMatchExpression() ); + ASSERT( gt1->init( "", ComparisonMatchExpression::GT, baseOperandgt1[ "$gt" ] ).isOK() ); BSONObj baseOperandlt1 = BSON( "$lt" << 10 ); - auto_ptr<ComparisonExpression> lt1( new ComparisonExpression() ); - ASSERT( lt1->init( "", ComparisonExpression::LT, baseOperandlt1[ "$lt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> lt1( new ComparisonMatchExpression() ); + ASSERT( lt1->init( "", ComparisonMatchExpression::LT, baseOperandlt1[ "$lt" ] ).isOK() ); - auto_ptr<ElemMatchValueExpression> elemMatch1( new ElemMatchValueExpression() ); + auto_ptr<ElemMatchValueMatchExpression> elemMatch1( new ElemMatchValueMatchExpression() ); elemMatch1->init( "x" ); elemMatch1->add( gt1.release() ); elemMatch1->add( lt1.release() ); BSONObj baseOperandgt2 = BSON( "$gt" << 101 ); - auto_ptr<ComparisonExpression> gt2( new ComparisonExpression() ); - ASSERT( gt2->init( "", ComparisonExpression::GT, baseOperandgt2[ "$gt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> gt2( new ComparisonMatchExpression() ); + ASSERT( gt2->init( "", ComparisonMatchExpression::GT, baseOperandgt2[ "$gt" ] ).isOK() ); BSONObj baseOperandlt2 = BSON( "$lt" << 110 ); - auto_ptr<ComparisonExpression> lt2( new ComparisonExpression() ); - ASSERT( lt2->init( "", ComparisonExpression::LT, baseOperandlt2[ "$lt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> lt2( new ComparisonMatchExpression() ); + ASSERT( lt2->init( "", ComparisonMatchExpression::LT, baseOperandlt2[ "$lt" ] ).isOK() ); - auto_ptr<ElemMatchValueExpression> elemMatch2( new ElemMatchValueExpression() ); + auto_ptr<ElemMatchValueMatchExpression> elemMatch2( new ElemMatchValueMatchExpression() ); elemMatch2->init( "x" ); elemMatch2->add( gt2.release() ); elemMatch2->add( lt2.release() ); @@ -560,44 +560,44 @@ namespace mongo { /** TEST( AllElemMatchOp, MatchesIndexKey ) { BSONObj baseOperand = BSON( "$lt" << 5 ); - auto_ptr<LtOp> lt( new ComparisonExpression() ); + auto_ptr<LtOp> lt( new ComparisonMatchExpression() ); ASSERT( lt->init( "a", baseOperand[ "$lt" ] ).isOK() ); - auto_ptr<ElemMatchValueExpression> elemMatchValueOp( new ElemMatchValueExpression() ); + auto_ptr<ElemMatchValueMatchExpression> elemMatchValueOp( new ElemMatchValueMatchExpression() ); ASSERT( elemMatchValueOp->init( "a", lt.release() ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( elemMatchValueOp.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( elemMatchValueOp.release() ); AllElemMatchOp allElemMatchOp; - ASSERT( allElemMatchOp.init( &subExpressions ).isOK() ); + ASSERT( allElemMatchOp.init( &subMatchExpressions ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << "3" ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == allElemMatchOp.matchesIndexKey( indexKey, indexSpec ) ); } */ - TEST( SizeExpression, MatchesElement ) { + TEST( SizeMatchExpression, MatchesElement ) { BSONObj match = BSON( "a" << BSON_ARRAY( 5 << 6 ) ); BSONObj notMatch = BSON( "a" << BSON_ARRAY( 5 ) ); - SizeExpression size; + SizeMatchExpression size; ASSERT( size.init( "", 2 ).isOK() ); ASSERT( size.matchesSingleElement( match.firstElement() ) ); ASSERT( !size.matchesSingleElement( notMatch.firstElement() ) ); } - TEST( SizeExpression, MatchesNonArray ) { + TEST( SizeMatchExpression, MatchesNonArray ) { // Non arrays do not match. BSONObj stringValue = BSON( "a" << "z" ); BSONObj numberValue = BSON( "a" << 0 ); BSONObj arrayValue = BSON( "a" << BSONArray() ); - SizeExpression size; + SizeMatchExpression size; ASSERT( size.init( "", 0 ).isOK() ); ASSERT( !size.matchesSingleElement( stringValue.firstElement() ) ); ASSERT( !size.matchesSingleElement( numberValue.firstElement() ) ); ASSERT( size.matchesSingleElement( arrayValue.firstElement() ) ); } - TEST( SizeExpression, MatchesArray ) { - SizeExpression size; + TEST( SizeMatchExpression, MatchesArray ) { + SizeMatchExpression size; ASSERT( size.init( "a", 2 ).isOK() ); ASSERT( size.matches( BSON( "a" << BSON_ARRAY( 4 << 5.5 ) ), NULL ) ); // Arrays are not unwound to look for matching subarrays. @@ -605,16 +605,16 @@ namespace mongo { NULL ) ); } - TEST( SizeExpression, MatchesNestedArray ) { - SizeExpression size; + TEST( SizeMatchExpression, MatchesNestedArray ) { + SizeMatchExpression size; ASSERT( size.init( "a.2", 2 ).isOK() ); // A numerically referenced nested array is matched. ASSERT( size.matches( BSON( "a" << BSON_ARRAY( 4 << 5.5 << BSON_ARRAY( 1 << 2 ) ) ), NULL ) ); } - TEST( SizeExpression, ElemMatchKey ) { - SizeExpression size; + TEST( SizeMatchExpression, ElemMatchKey ) { + SizeMatchExpression size; ASSERT( size.init( "a.b", 3 ).isOK() ); MatchDetails details; details.requestElemMatchKey(); @@ -631,13 +631,13 @@ namespace mongo { } /** - TEST( SizeExpression, MatchesIndexKey ) { + TEST( SizeMatchExpression, MatchesIndexKey ) { BSONObj operand = BSON( "$size" << 4 ); - SizeExpression size; + SizeMatchExpression size; ASSERT( size.init( "a", operand[ "$size" ] ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << 1 ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == size.matchesIndexKey( indexKey, indexSpec ) ); } */ diff --git a/src/mongo/db/matcher/expression_leaf.cpp b/src/mongo/db/matcher/expression_leaf.cpp index 6d1ee7723ae..cad5cd110f1 100644 --- a/src/mongo/db/matcher/expression_leaf.cpp +++ b/src/mongo/db/matcher/expression_leaf.cpp @@ -27,7 +27,7 @@ namespace mongo { - bool LeafExpression::matches( const BSONObj& doc, MatchDetails* details ) const { + bool LeafMatchExpression::matches( const BSONObj& doc, MatchDetails* details ) const { //log() << "e doc: " << doc << " path: " << _path << std::endl; FieldRef path; @@ -75,7 +75,7 @@ namespace mongo { // ------------- - Status ComparisonExpression::init( const StringData& path, Type type, const BSONElement& rhs ) { + Status ComparisonMatchExpression::init( const StringData& path, Type type, const BSONElement& rhs ) { _path = path; _type = type; _rhs = rhs; @@ -89,8 +89,8 @@ namespace mongo { } - bool ComparisonExpression::matchesSingleElement( const BSONElement& e ) const { - //log() << "\t ComparisonExpression e: " << e << " _rhs: " << _rhs << std::endl; + bool ComparisonMatchExpression::matchesSingleElement( const BSONElement& e ) const { + //log() << "\t ComparisonMatchExpression e: " << e << " _rhs: " << _rhs << std::endl; if ( e.canonicalType() != _rhs.canonicalType() ) { // some special cases @@ -126,13 +126,13 @@ namespace mongo { throw 1; } - bool ComparisonExpression::_invertForNE( bool normal ) const { + bool ComparisonMatchExpression::_invertForNE( bool normal ) const { if ( _type == NE ) return !normal; return normal; } - void ComparisonExpression::debugString( StringBuilder& debug, int level ) const { + void ComparisonMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " "; switch ( _type ) { @@ -166,14 +166,14 @@ namespace mongo { return options; } - Status RegexExpression::init( const StringData& path, const BSONElement& e ) { + Status RegexMatchExpression::init( const StringData& path, const BSONElement& e ) { if ( e.type() != RegEx ) return Status( ErrorCodes::BadValue, "regex not a regex" ); return init( path, e.regex(), e.regexFlags() ); } - Status RegexExpression::init( const StringData& path, const StringData& regex, const StringData& options ) { + Status RegexMatchExpression::init( const StringData& path, const StringData& regex, const StringData& options ) { _path = path; if ( regex.size() > MaxPatternSize ) { @@ -186,8 +186,8 @@ namespace mongo { return Status::OK(); } - bool RegexExpression::matchesSingleElement( const BSONElement& e ) const { - //log() << "RegexExpression::matchesSingleElement _regex: " << _regex << " e: " << e << std::endl; + bool RegexMatchExpression::matchesSingleElement( const BSONElement& e ) const { + //log() << "RegexMatchExpression::matchesSingleElement _regex: " << _regex << " e: " << e << std::endl; switch (e.type()) { case String: case Symbol: @@ -202,14 +202,14 @@ namespace mongo { } } - void RegexExpression::debugString( StringBuilder& debug, int level ) const { + void RegexMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " regex /" << _regex << "/" << _flags << "\n"; } // --------- - Status ModExpression::init( const StringData& path, int divisor, int remainder ) { + Status ModMatchExpression::init( const StringData& path, int divisor, int remainder ) { _path = path; if ( divisor == 0 ) return Status( ErrorCodes::BadValue, "divisor cannot be 0" ); @@ -218,13 +218,13 @@ namespace mongo { return Status::OK(); } - bool ModExpression::matchesSingleElement( const BSONElement& e ) const { + bool ModMatchExpression::matchesSingleElement( const BSONElement& e ) const { if ( !e.isNumber() ) return false; return e.numberLong() % _divisor == _remainder; } - void ModExpression::debugString( StringBuilder& debug, int level ) const { + void ModMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " mod " << _divisor << " % x == " << _remainder << "\n"; } @@ -232,41 +232,41 @@ namespace mongo { // ------------------ - Status ExistsExpression::init( const StringData& path, bool exists ) { + Status ExistsMatchExpression::init( const StringData& path, bool exists ) { _path = path; _exists = exists; return Status::OK(); } - bool ExistsExpression::matchesSingleElement( const BSONElement& e ) const { + bool ExistsMatchExpression::matchesSingleElement( const BSONElement& e ) const { if ( e.eoo() ) { return !_exists; } return _exists; } - void ExistsExpression::debugString( StringBuilder& debug, int level ) const { + void ExistsMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " exists: " << _exists << "\n"; } // ---- - Status TypeExpression::init( const StringData& path, int type ) { + Status TypeMatchExpression::init( const StringData& path, int type ) { _path = path; _type = type; return Status::OK(); } - bool TypeExpression::matchesSingleElement( const BSONElement& e ) const { + bool TypeMatchExpression::matchesSingleElement( const BSONElement& e ) const { return e.type() == _type; } - bool TypeExpression::matches( const BSONObj& doc, MatchDetails* details ) const { + bool TypeMatchExpression::matches( const BSONObj& doc, MatchDetails* details ) const { return _matches( _path, doc, details ); } - bool TypeExpression::_matches( const StringData& path, const BSONObj& doc, MatchDetails* details ) const { + bool TypeMatchExpression::_matches( const StringData& path, const BSONObj& doc, MatchDetails* details ) const { FieldRef pathRef; pathRef.parse(path); @@ -305,7 +305,7 @@ namespace mongo { return false; } - void TypeExpression::debugString( StringBuilder& debug, int level ) const { + void TypeMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " type: " << _type << "\n"; } @@ -340,20 +340,20 @@ namespace mongo { return Status::OK(); } - Status ArrayFilterEntries::addRegex( RegexExpression* expr ) { + Status ArrayFilterEntries::addRegex( RegexMatchExpression* expr ) { _regexes.push_back( expr ); return Status::OK(); } // ----------- - void InExpression::init( const StringData& path ) { + void InMatchExpression::init( const StringData& path ) { _path = path; _allHaveToMatch = false; } - bool InExpression::matchesSingleElement( const BSONElement& e ) const { + bool InMatchExpression::matchesSingleElement( const BSONElement& e ) const { if ( _arrayEntries.hasNull() && e.eoo() ) return true; @@ -368,7 +368,7 @@ namespace mongo { return false; } - void InExpression::debugString( StringBuilder& debug, int level ) const { + void InMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " $in: TODO\n"; } @@ -376,18 +376,18 @@ namespace mongo { // ---------- - void NinExpression::init( const StringData& path ) { + void NinMatchExpression::init( const StringData& path ) { _path = path; _allHaveToMatch = true; } - bool NinExpression::matchesSingleElement( const BSONElement& e ) const { + bool NinMatchExpression::matchesSingleElement( const BSONElement& e ) const { return !_in.matchesSingleElement( e ); } - void NinExpression::debugString( StringBuilder& debug, int level ) const { + void NinMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << _path << " $nin: TODO\n"; } diff --git a/src/mongo/db/matcher/expression_leaf.h b/src/mongo/db/matcher/expression_leaf.h index e55a5dea587..a0aebe7a345 100644 --- a/src/mongo/db/matcher/expression_leaf.h +++ b/src/mongo/db/matcher/expression_leaf.h @@ -28,13 +28,13 @@ namespace mongo { - class LeafExpression : public Expression { + class LeafMatchExpression : public MatchExpression { public: - LeafExpression() { + LeafMatchExpression() { _allHaveToMatch = false; } - virtual ~LeafExpression(){} + virtual ~LeafMatchExpression(){} virtual bool matches( const BSONObj& doc, MatchDetails* details = 0 ) const; @@ -46,13 +46,13 @@ namespace mongo { // ----- - class ComparisonExpression : public LeafExpression { + class ComparisonMatchExpression : public LeafMatchExpression { public: enum Type { LTE, LT, EQ, GT, GTE, NE }; Status init( const StringData& path, Type type, const BSONElement& rhs ); - virtual ~ComparisonExpression(){} + virtual ~ComparisonMatchExpression(){} virtual Type getType() const { return _type; } @@ -67,7 +67,7 @@ namespace mongo { BSONElement _rhs; }; - class RegexExpression : public LeafExpression { + class RegexMatchExpression : public LeafMatchExpression { public: /** * Maximum pattern size which pcre v8.3 can do matches correctly with @@ -88,7 +88,7 @@ namespace mongo { boost::scoped_ptr<pcrecpp::RE> _re; }; - class ModExpression : public LeafExpression { + class ModMatchExpression : public LeafMatchExpression { public: Status init( const StringData& path, int divisor, int remainder ); @@ -100,7 +100,7 @@ namespace mongo { int _remainder; }; - class ExistsExpression : public LeafExpression { + class ExistsMatchExpression : public LeafMatchExpression { public: Status init( const StringData& path, bool exists ); @@ -111,7 +111,7 @@ namespace mongo { bool _exists; }; - class TypeExpression : public Expression { + class TypeMatchExpression : public MatchExpression { public: Status init( const StringData& path, int type ); @@ -140,13 +140,13 @@ namespace mongo { ~ArrayFilterEntries(); Status addEquality( const BSONElement& e ); - Status addRegex( RegexExpression* expr ); + Status addRegex( RegexMatchExpression* expr ); const BSONElementSet& equalities() const { return _equalities; } bool contains( const BSONElement& elem ) const { return _equalities.count(elem) > 0; } size_t numRegexes() const { return _regexes.size(); } - RegexExpression* regex( int idx ) const { return _regexes[idx]; } + RegexMatchExpression* regex( int idx ) const { return _regexes[idx]; } bool hasNull() const { return _hasNull; } bool singleNull() const { return size() == 1 && _hasNull; } @@ -155,14 +155,14 @@ namespace mongo { private: bool _hasNull; // if _equalities has a jstNULL element in it BSONElementSet _equalities; - std::vector<RegexExpression*> _regexes; + std::vector<RegexMatchExpression*> _regexes; }; /** * query operator: $in */ - class InExpression : public LeafExpression { + class InMatchExpression : public LeafMatchExpression { public: void init( const StringData& path ); ArrayFilterEntries* getArrayFilterEntries() { return &_arrayEntries; } @@ -174,7 +174,7 @@ namespace mongo { ArrayFilterEntries _arrayEntries; }; - class NinExpression : public LeafExpression { + class NinMatchExpression : public LeafMatchExpression { public: void init( const StringData& path ); ArrayFilterEntries* getArrayFilterEntries() { return _in.getArrayFilterEntries(); } @@ -183,7 +183,7 @@ namespace mongo { virtual void debugString( StringBuilder& debug, int level ) const; private: - InExpression _in; + InMatchExpression _in; }; 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 ) ); } */ diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp index ef6f058cca1..e444866d60b 100644 --- a/src/mongo/db/matcher/expression_parser.cpp +++ b/src/mongo/db/matcher/expression_parser.cpp @@ -31,25 +31,25 @@ namespace mongo { - StatusWithExpression ExpressionParser::_parseComparison( const char* name, - ComparisonExpression::Type cmp, + StatusWithMatchExpression MatchExpressionParser::_parseComparison( const char* name, + ComparisonMatchExpression::Type cmp, const BSONElement& e ) { - std::auto_ptr<ComparisonExpression> temp( new ComparisonExpression() ); + std::auto_ptr<ComparisonMatchExpression> temp( new ComparisonMatchExpression() ); Status s = temp->init( name, cmp, e ); if ( !s.isOK() ) - return StatusWithExpression(s); + return StatusWithMatchExpression(s); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( temp.release() ); } - StatusWithExpression ExpressionParser::_parseSubField( const char* name, + StatusWithMatchExpression MatchExpressionParser::_parseSubField( const char* name, const BSONElement& e ) { // TODO: these should move to getGtLtOp, or its replacement if ( mongoutils::str::equals( "$eq", e.fieldName() ) ) - return _parseComparison( name, ComparisonExpression::EQ, e ); + return _parseComparison( name, ComparisonMatchExpression::EQ, e ); if ( mongoutils::str::equals( "$not", e.fieldName() ) ) { return _parseNot( name, e ); @@ -59,42 +59,42 @@ namespace mongo { int x = e.getGtLtOp(-1); switch ( x ) { case -1: - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, mongoutils::str::stream() << "unknown operator: " << e.fieldName() ); case BSONObj::LT: - return _parseComparison( name, ComparisonExpression::LT, e ); + return _parseComparison( name, ComparisonMatchExpression::LT, e ); case BSONObj::LTE: - return _parseComparison( name, ComparisonExpression::LTE, e ); + return _parseComparison( name, ComparisonMatchExpression::LTE, e ); case BSONObj::GT: - return _parseComparison( name, ComparisonExpression::GT, e ); + return _parseComparison( name, ComparisonMatchExpression::GT, e ); case BSONObj::GTE: - return _parseComparison( name, ComparisonExpression::GTE, e ); + return _parseComparison( name, ComparisonMatchExpression::GTE, e ); case BSONObj::NE: - return _parseComparison( name, ComparisonExpression::NE, e ); + return _parseComparison( name, ComparisonMatchExpression::NE, e ); case BSONObj::Equality: - return _parseComparison( name, ComparisonExpression::EQ, e ); + return _parseComparison( name, ComparisonMatchExpression::EQ, e ); case BSONObj::opIN: { if ( e.type() != Array ) - return StatusWithExpression( ErrorCodes::BadValue, "$in needs an array" ); - std::auto_ptr<InExpression> temp( new InExpression() ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "$in needs an array" ); + std::auto_ptr<InMatchExpression> temp( new InMatchExpression() ); temp->init( name ); Status s = _parseArrayFilterEntries( temp->getArrayFilterEntries(), e.Obj() ); if ( !s.isOK() ) - return StatusWithExpression( s ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( s ); + return StatusWithMatchExpression( temp.release() ); } case BSONObj::NIN: { if ( e.type() != Array ) - return StatusWithExpression( ErrorCodes::BadValue, "$nin needs an array" ); - std::auto_ptr<NinExpression> temp( new NinExpression() ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "$nin needs an array" ); + std::auto_ptr<NinMatchExpression> temp( new NinMatchExpression() ); temp->init( name ); Status s = _parseArrayFilterEntries( temp->getArrayFilterEntries(), e.Obj() ); if ( !s.isOK() ) - return StatusWithExpression( s ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( s ); + return StatusWithMatchExpression( temp.release() ); } case BSONObj::opSIZE: { @@ -117,37 +117,37 @@ namespace mongo { } } else { - return StatusWithExpression( ErrorCodes::BadValue, "$size needs a number" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "$size needs a number" ); } - std::auto_ptr<SizeExpression> temp( new SizeExpression() ); + std::auto_ptr<SizeMatchExpression> temp( new SizeMatchExpression() ); Status s = temp->init( name, size ); if ( !s.isOK() ) - return StatusWithExpression( s ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( s ); + return StatusWithMatchExpression( temp.release() ); } case BSONObj::opEXISTS: { if ( e.eoo() ) - return StatusWithExpression( ErrorCodes::BadValue, "$exists can't be eoo" ); - std::auto_ptr<ExistsExpression> temp( new ExistsExpression() ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "$exists can't be eoo" ); + std::auto_ptr<ExistsMatchExpression> temp( new ExistsMatchExpression() ); Status s = temp->init( name, e.trueValue() ); if ( !s.isOK() ) - return StatusWithExpression( s ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( s ); + return StatusWithMatchExpression( temp.release() ); } case BSONObj::opTYPE: { if ( !e.isNumber() ) - return StatusWithExpression( ErrorCodes::BadValue, "$type has to be a number" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "$type has to be a number" ); int type = e.numberInt(); if ( e.type() != NumberInt && type != e.number() ) type = -1; - std::auto_ptr<TypeExpression> temp( new TypeExpression() ); + std::auto_ptr<TypeMatchExpression> temp( new TypeMatchExpression() ); Status s = temp->init( name, type ); if ( !s.isOK() ) - return StatusWithExpression( s ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( s ); + return StatusWithMatchExpression( temp.release() ); } @@ -155,7 +155,7 @@ namespace mongo { return _parseMOD( name, e ); case BSONObj::opOPTIONS: - return StatusWithExpression( ErrorCodes::BadValue, "$options has to be after a $regex" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "$options has to be after a $regex" ); case BSONObj::opELEM_MATCH: return _parseElemMatch( name, e ); @@ -164,14 +164,14 @@ namespace mongo { return _parseAll( name, e ); default: - return StatusWithExpression( ErrorCodes::BadValue, "not done" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "not done" ); } } - StatusWithExpression ExpressionParser::parse( const BSONObj& obj ) { + StatusWithMatchExpression MatchExpressionParser::parse( const BSONObj& obj ) { - std::auto_ptr<AndExpression> root( new AndExpression() ); + std::auto_ptr<AndMatchExpression> root( new AndMatchExpression() ); BSONObjIterator i( obj ); while ( i.more() ){ @@ -183,36 +183,36 @@ namespace mongo { // TODO: optimize if block? if ( mongoutils::str::equals( "or", rest ) ) { if ( e.type() != Array ) - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, "$or needs an array" ); - std::auto_ptr<OrExpression> temp( new OrExpression() ); + std::auto_ptr<OrMatchExpression> temp( new OrMatchExpression() ); Status s = _parseTreeList( e.Obj(), temp.get() ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); root->add( temp.release() ); } else if ( mongoutils::str::equals( "and", rest ) ) { if ( e.type() != Array ) - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, "and needs an array" ); - std::auto_ptr<AndExpression> temp( new AndExpression() ); + std::auto_ptr<AndMatchExpression> temp( new AndMatchExpression() ); Status s = _parseTreeList( e.Obj(), temp.get() ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); root->add( temp.release() ); } else if ( mongoutils::str::equals( "nor", rest ) ) { if ( e.type() != Array ) - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, "and needs an array" ); - std::auto_ptr<NorExpression> temp( new NorExpression() ); + std::auto_ptr<NorMatchExpression> temp( new NorMatchExpression() ); Status s = _parseTreeList( e.Obj(), temp.get() ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); root->add( temp.release() ); } else { - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, mongoutils::str::stream() << "unkown operator: " << e.fieldName() ); @@ -224,32 +224,32 @@ namespace mongo { if ( e.type() == Object && e.Obj().firstElement().fieldName()[0] == '$' ) { Status s = _parseSub( e.fieldName(), e.Obj(), root.get() ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); continue; } if ( e.type() == RegEx ) { - StatusWithExpression result = _parseRegexElement( e.fieldName(), e ); + StatusWithMatchExpression result = _parseRegexElement( e.fieldName(), e ); if ( !result.isOK() ) return result; root->add( result.getValue() ); continue; } - std::auto_ptr<ComparisonExpression> eq( new ComparisonExpression() ); - Status s = eq->init( e.fieldName(), ComparisonExpression::EQ, e ); + std::auto_ptr<ComparisonMatchExpression> eq( new ComparisonMatchExpression() ); + Status s = eq->init( e.fieldName(), ComparisonMatchExpression::EQ, e ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); root->add( eq.release() ); } - return StatusWithExpression( root.release() ); + return StatusWithMatchExpression( root.release() ); } - Status ExpressionParser::_parseSub( const char* name, + Status MatchExpressionParser::_parseSub( const char* name, const BSONObj& sub, - AndExpression* root ) { + AndMatchExpression* root ) { bool first = true; @@ -262,14 +262,14 @@ namespace mongo { if ( !first ) return Status( ErrorCodes::BadValue, "$regex has to be first" ); - StatusWithExpression s = _parseRegexDocument( name, sub ); + StatusWithMatchExpression s = _parseRegexDocument( name, sub ); if ( !s.isOK() ) return s.getStatus(); root->add( s.getValue() ); return Status::OK(); } - StatusWithExpression s = _parseSubField( name, deep ); + StatusWithMatchExpression s = _parseSubField( name, deep ); if ( !s.isOK() ) return s.getStatus(); @@ -281,49 +281,49 @@ namespace mongo { - StatusWithExpression ExpressionParser::_parseMOD( const char* name, + StatusWithMatchExpression MatchExpressionParser::_parseMOD( const char* name, const BSONElement& e ) { if ( e.type() != Array ) - return StatusWithExpression( ErrorCodes::BadValue, "malformed mod, needs to be an array" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, needs to be an array" ); BSONObjIterator i( e.Obj() ); if ( !i.more() ) - return StatusWithExpression( ErrorCodes::BadValue, "malformed mod, not enough elements" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, not enough elements" ); BSONElement d = i.next(); if ( !d.isNumber() ) - return StatusWithExpression( ErrorCodes::BadValue, "malformed mod, divisor not a number" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, divisor not a number" ); if ( !i.more() ) - return StatusWithExpression( ErrorCodes::BadValue, "malformed mod, not enough elements" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, not enough elements" ); BSONElement r = i.next(); if ( !d.isNumber() ) - return StatusWithExpression( ErrorCodes::BadValue, "malformed mod, remainder not a number" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, remainder not a number" ); if ( i.more() ) - return StatusWithExpression( ErrorCodes::BadValue, "malformed mod, too many elements" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "malformed mod, too many elements" ); - std::auto_ptr<ModExpression> temp( new ModExpression() ); + std::auto_ptr<ModMatchExpression> temp( new ModMatchExpression() ); Status s = temp->init( name, d.numberInt(), r.numberInt() ); if ( !s.isOK() ) - return StatusWithExpression( s ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( s ); + return StatusWithMatchExpression( temp.release() ); } - StatusWithExpression ExpressionParser::_parseRegexElement( const char* name, + StatusWithMatchExpression MatchExpressionParser::_parseRegexElement( const char* name, const BSONElement& e ) { if ( e.type() != RegEx ) - return StatusWithExpression( ErrorCodes::BadValue, "not a regex" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "not a regex" ); - std::auto_ptr<RegexExpression> temp( new RegexExpression() ); + std::auto_ptr<RegexMatchExpression> temp( new RegexMatchExpression() ); Status s = temp->init( name, e.regex(), e.regexFlags() ); if ( !s.isOK() ) - return StatusWithExpression( s ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( s ); + return StatusWithMatchExpression( temp.release() ); } - StatusWithExpression ExpressionParser::_parseRegexDocument( const char* name, + StatusWithMatchExpression MatchExpressionParser::_parseRegexDocument( const char* name, const BSONObj& doc ) { string regex; string regexOptions; @@ -334,33 +334,33 @@ namespace mongo { switch ( e.getGtLtOp() ) { case BSONObj::opREGEX: if ( e.type() != String ) - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, "$regex has to be a string" ); regex = e.String(); break; case BSONObj::opOPTIONS: if ( e.type() != String ) - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, "$options has to be a string" ); regexOptions = e.String(); break; default: - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, mongoutils::str::stream() << "bad $regex doc option: " << e.fieldName() ); } } - std::auto_ptr<RegexExpression> temp( new RegexExpression() ); + std::auto_ptr<RegexMatchExpression> temp( new RegexMatchExpression() ); Status s = temp->init( name, regex, regexOptions ); if ( !s.isOK() ) - return StatusWithExpression( s ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( s ); + return StatusWithMatchExpression( temp.release() ); } - Status ExpressionParser::_parseArrayFilterEntries( ArrayFilterEntries* entries, + Status MatchExpressionParser::_parseArrayFilterEntries( ArrayFilterEntries* entries, const BSONObj& theArray ) { @@ -369,7 +369,7 @@ namespace mongo { BSONElement e = i.next(); if ( e.type() == RegEx ) { - std::auto_ptr<RegexExpression> r( new RegexExpression() ); + std::auto_ptr<RegexMatchExpression> r( new RegexMatchExpression() ); Status s = r->init( "", e ); if ( !s.isOK() ) return s; @@ -387,51 +387,51 @@ namespace mongo { } - StatusWithExpression ExpressionParser::_parseElemMatch( const char* name, + StatusWithMatchExpression MatchExpressionParser::_parseElemMatch( const char* name, const BSONElement& e ) { if ( e.type() != Object ) - return StatusWithExpression( ErrorCodes::BadValue, "$elemMatch needs an Object" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "$elemMatch needs an Object" ); BSONObj obj = e.Obj(); if ( obj.firstElement().fieldName()[0] == '$' ) { // value case - AndExpression theAnd; + AndMatchExpression theAnd; Status s = _parseSub( "", obj, &theAnd ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); - std::auto_ptr<ElemMatchValueExpression> temp( new ElemMatchValueExpression() ); + std::auto_ptr<ElemMatchValueMatchExpression> temp( new ElemMatchValueMatchExpression() ); s = temp->init( name ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); for ( size_t i = 0; i < theAnd.size(); i++ ) { temp->add( theAnd.get( i ) ); } theAnd.clearAndRelease(); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( temp.release() ); } // object case - StatusWithExpression sub = parse( obj ); + StatusWithMatchExpression sub = parse( obj ); if ( !sub.isOK() ) return sub; - std::auto_ptr<ElemMatchObjectExpression> temp( new ElemMatchObjectExpression() ); + std::auto_ptr<ElemMatchObjectMatchExpression> temp( new ElemMatchObjectMatchExpression() ); Status status = temp->init( name, sub.getValue() ); if ( !status.isOK() ) - return StatusWithExpression( status ); + return StatusWithMatchExpression( status ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( temp.release() ); } - StatusWithExpression ExpressionParser::_parseAll( const char* name, + StatusWithMatchExpression MatchExpressionParser::_parseAll( const char* name, const BSONElement& e ) { if ( e.type() != Array ) - return StatusWithExpression( ErrorCodes::BadValue, "$all needs an array" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "$all needs an array" ); BSONObj arr = e.Obj(); if ( arr.firstElement().type() == Object && @@ -442,7 +442,7 @@ namespace mongo { std::auto_ptr<AllElemMatchOp> temp( new AllElemMatchOp() ); Status s = temp->init( name ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); BSONObjIterator i( arr ); while ( i.more() ) { @@ -450,7 +450,7 @@ namespace mongo { if ( hopefullyElemMatchElemennt.type() != Object ) { // $all : [ { $elemMatch : ... }, 5 ] - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, "$all/$elemMatch has to be consistent" ); } @@ -458,29 +458,29 @@ namespace mongo { if ( !mongoutils::str::equals( "$elemMatch", hopefullyElemMatchObj.firstElement().fieldName() ) ) { // $all : [ { $elemMatch : ... }, { x : 5 } ] - return StatusWithExpression( ErrorCodes::BadValue, + return StatusWithMatchExpression( ErrorCodes::BadValue, "$all/$elemMatch has to be consistent" ); } - StatusWithExpression inner = _parseElemMatch( "", hopefullyElemMatchObj.firstElement() ); + StatusWithMatchExpression inner = _parseElemMatch( "", hopefullyElemMatchObj.firstElement() ); if ( !inner.isOK() ) return inner; - temp->add( static_cast<ArrayMatchingExpression*>( inner.getValue() ) ); + temp->add( static_cast<ArrayMatchingMatchExpression*>( inner.getValue() ) ); } - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( temp.release() ); } - std::auto_ptr<AllExpression> temp( new AllExpression() ); + std::auto_ptr<AllMatchExpression> temp( new AllMatchExpression() ); Status s = temp->init( name ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); s = _parseArrayFilterEntries( temp->getArrayFilterEntries(), arr ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); - return StatusWithExpression( temp.release() ); + return StatusWithMatchExpression( temp.release() ); } diff --git a/src/mongo/db/matcher/expression_parser.h b/src/mongo/db/matcher/expression_parser.h index 2655da3f556..b062387102e 100644 --- a/src/mongo/db/matcher/expression_parser.h +++ b/src/mongo/db/matcher/expression_parser.h @@ -26,11 +26,11 @@ namespace mongo { - typedef StatusWith<Expression*> StatusWithExpression; + typedef StatusWith<MatchExpression*> StatusWithMatchExpression; - class ExpressionParser { + class MatchExpressionParser { public: - static StatusWithExpression parse( const BSONObj& obj ); + static StatusWithMatchExpression parse( const BSONObj& obj ); private: @@ -41,27 +41,27 @@ namespace mongo { */ static Status _parseSub( const char* name, const BSONObj& obj, - AndExpression* root ); + AndMatchExpression* root ); /** * parses a single field in a sub expression * if the query is { x : { $gt : 5, $lt : 8 } } * e is $gt : 5 */ - static StatusWithExpression _parseSubField( const char* name, + static StatusWithMatchExpression _parseSubField( const char* name, const BSONElement& e ); - static StatusWithExpression _parseComparison( const char* name, - ComparisonExpression::Type cmp, + static StatusWithMatchExpression _parseComparison( const char* name, + ComparisonMatchExpression::Type cmp, const BSONElement& e ); - static StatusWithExpression _parseMOD( const char* name, + static StatusWithMatchExpression _parseMOD( const char* name, const BSONElement& e ); - static StatusWithExpression _parseRegexElement( const char* name, + static StatusWithMatchExpression _parseRegexElement( const char* name, const BSONElement& e ); - static StatusWithExpression _parseRegexDocument( const char* name, + static StatusWithMatchExpression _parseRegexDocument( const char* name, const BSONObj& doc ); @@ -70,17 +70,17 @@ namespace mongo { // arrays - static StatusWithExpression _parseElemMatch( const char* name, + static StatusWithMatchExpression _parseElemMatch( const char* name, const BSONElement& e ); - static StatusWithExpression _parseAll( const char* name, + static StatusWithMatchExpression _parseAll( const char* name, const BSONElement& e ); // tree - static Status _parseTreeList( const BSONObj& arr, ListOfExpression* out ); + static Status _parseTreeList( const BSONObj& arr, ListOfMatchExpression* out ); - static StatusWithExpression _parseNot( const char* name, const BSONElement& e ); + static StatusWithMatchExpression _parseNot( const char* name, const BSONElement& e ); }; diff --git a/src/mongo/db/matcher/expression_parser_array_test.cpp b/src/mongo/db/matcher/expression_parser_array_test.cpp index 3b0a6d0cc52..46f1f158807 100644 --- a/src/mongo/db/matcher/expression_parser_array_test.cpp +++ b/src/mongo/db/matcher/expression_parser_array_test.cpp @@ -27,9 +27,9 @@ namespace mongo { - TEST( ExpressionParserArrayTest, Size1 ) { + TEST( MatchExpressionParserArrayTest, Size1 ) { BSONObj query = BSON( "x" << BSON( "$size" << 2 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -38,9 +38,9 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << BSON_ARRAY( 1 << 2 << 3 ) ) ) ); } - TEST( ExpressionParserArrayTest, SizeAsString ) { + TEST( MatchExpressionParserArrayTest, SizeAsString ) { BSONObj query = BSON( "x" << BSON( "$size" << "a" ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -49,9 +49,9 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << BSON_ARRAY( 1 ) ) ) ); } - TEST( ExpressionParserArrayTest, SizeWithDouble ) { + TEST( MatchExpressionParserArrayTest, SizeWithDouble ) { BSONObj query = BSON( "x" << BSON( "$size" << 2.5 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -61,17 +61,17 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << BSON_ARRAY( 1 << 2 << 3 ) ) ) ); } - TEST( ExpressionParserArrayTest, SizeBad ) { + TEST( MatchExpressionParserArrayTest, SizeBad ) { BSONObj query = BSON( "x" << BSON( "$size" << BSONNULL ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } // --------- - TEST( ExpressionParserArrayTest, ElemMatchArr1 ) { + TEST( MatchExpressionParserArrayTest, ElemMatchArr1 ) { BSONObj query = BSON( "x" << BSON( "$elemMatch" << BSON( "x" << 1 << "y" << 2 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -82,9 +82,9 @@ namespace mongo { } - TEST( ExpressionParserArrayTest, ElemMatchVal1 ) { + TEST( MatchExpressionParserArrayTest, ElemMatchVal1 ) { BSONObj query = BSON( "x" << BSON( "$elemMatch" << BSON( "$gt" << 5 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -92,9 +92,9 @@ namespace mongo { ASSERT( result.getValue()->matches( BSON( "x" << BSON_ARRAY( 6 ) ) ) ); } - TEST( ExpressionParserArrayTest, All1 ) { + TEST( MatchExpressionParserArrayTest, All1 ) { BSONObj query = BSON( "x" << BSON( "$all" << BSON_ARRAY( 1 << 2 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -105,13 +105,13 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << BSON_ARRAY( 2 << 3 ) ) ) ); } - TEST( ExpressionParserArrayTest, AllBadArg ) { + TEST( MatchExpressionParserArrayTest, AllBadArg ) { BSONObj query = BSON( "x" << BSON( "$all" << 1 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } - TEST( ExpressionParserArrayTest, AllBadRegexArg ) { + TEST( MatchExpressionParserArrayTest, AllBadRegexArg ) { string tooLargePattern( 50 * 1000, 'z' ); BSONObjBuilder allArray; allArray.appendRegex( "0", tooLargePattern, "" ); @@ -120,12 +120,12 @@ namespace mongo { BSONObj query = BSON( "x" << operand.obj() ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } - TEST( ExpressionParserArrayTest, AllRegex1 ) { + TEST( MatchExpressionParserArrayTest, AllRegex1 ) { BSONObjBuilder allArray; allArray.appendRegex( "0", "^a", "" ); allArray.appendRegex( "1", "B", "i" ); @@ -133,7 +133,7 @@ namespace mongo { all.appendArray( "$all", allArray.obj() ); BSONObj query = BSON( "a" << all.obj() ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); BSONObj notMatchFirst = BSON( "a" << "ax" ); @@ -145,7 +145,7 @@ namespace mongo { ASSERT( result.getValue()->matchesSingleElement( matchesBoth[ "a" ] ) ); } - TEST( ExpressionParserArrayTest, AllRegex2 ) { + TEST( MatchExpressionParserArrayTest, AllRegex2 ) { BSONObjBuilder allArray; allArray.appendRegex( "0", "^a", "" ); allArray.append( "1", "abc" ); @@ -153,7 +153,7 @@ namespace mongo { all.appendArray( "$all", allArray.obj() ); BSONObj query = BSON( "a" << all.obj() ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); BSONObj notMatchFirst = BSON( "a" << "ax" ); @@ -163,10 +163,10 @@ namespace mongo { ASSERT( result.getValue()->matchesSingleElement( matchesBoth[ "a" ] ) ); } - TEST( ExpressionParserArrayTest, AllElemMatch1 ) { + TEST( MatchExpressionParserArrayTest, AllElemMatch1 ) { BSONObj internal = BSON( "x" << 1 << "y" << 2 ); BSONObj query = BSON( "x" << BSON( "$all" << BSON_ARRAY( BSON( "$elemMatch" << internal ) ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -177,15 +177,15 @@ namespace mongo { } - TEST( ExpressionParserArrayTest, AllElemMatchBad ) { + TEST( MatchExpressionParserArrayTest, AllElemMatchBad ) { BSONObj internal = BSON( "x" << 1 << "y" << 2 ); BSONObj query = BSON( "x" << BSON( "$all" << BSON_ARRAY( BSON( "$elemMatch" << internal ) << 5 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); query = BSON( "x" << BSON( "$all" << BSON_ARRAY( 5 << BSON( "$elemMatch" << internal ) ) ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } diff --git a/src/mongo/db/matcher/expression_parser_leaf_test.cpp b/src/mongo/db/matcher/expression_parser_leaf_test.cpp index 92246eead25..c9df6ab2f8c 100644 --- a/src/mongo/db/matcher/expression_parser_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_parser_leaf_test.cpp @@ -27,9 +27,9 @@ namespace mongo { - TEST( ExpressionParserLeafTest, SimpleEQ2 ) { + TEST( MatchExpressionParserLeafTest, SimpleEQ2 ) { BSONObj query = BSON( "x" << BSON( "$eq" << 2 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -37,18 +37,18 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << 3 ) ) ); } - TEST( ExpressionParserLeafTest, SimpleGT1 ) { + TEST( MatchExpressionParserLeafTest, SimpleGT1 ) { BSONObj query = BSON( "x" << BSON( "$gt" << 2 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 2 ) ) ); ASSERT( result.getValue()->matches( BSON( "x" << 3 ) ) ); } - TEST( ExpressionParserLeafTest, SimpleLT1 ) { + TEST( MatchExpressionParserLeafTest, SimpleLT1 ) { BSONObj query = BSON( "x" << BSON( "$lt" << 2 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -56,9 +56,9 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << 3 ) ) ); } - TEST( ExpressionParserLeafTest, SimpleGTE1 ) { + TEST( MatchExpressionParserLeafTest, SimpleGTE1 ) { BSONObj query = BSON( "x" << BSON( "$gte" << 2 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -66,9 +66,9 @@ namespace mongo { ASSERT( result.getValue()->matches( BSON( "x" << 3 ) ) ); } - TEST( ExpressionParserLeafTest, SimpleLTE1 ) { + TEST( MatchExpressionParserLeafTest, SimpleLTE1 ) { BSONObj query = BSON( "x" << BSON( "$lte" << 2 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -76,9 +76,9 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << 3 ) ) ); } - TEST( ExpressionParserLeafTest, SimpleNE1 ) { + TEST( MatchExpressionParserLeafTest, SimpleNE1 ) { BSONObj query = BSON( "x" << BSON( "$ne" << 2 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -86,35 +86,35 @@ namespace mongo { ASSERT( result.getValue()->matches( BSON( "x" << 3 ) ) ); } - TEST( ExpressionParserLeafTest, SimpleModBad1 ) { + TEST( MatchExpressionParserLeafTest, SimpleModBad1 ) { BSONObj query = BSON( "x" << BSON( "$mod" << BSON_ARRAY( 3 << 2 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); query = BSON( "x" << BSON( "$mod" << BSON_ARRAY( 3 ) ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_TRUE( !result.isOK() ); query = BSON( "x" << BSON( "$mod" << BSON_ARRAY( 3 << 2 << 4 ) ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_TRUE( !result.isOK() ); query = BSON( "x" << BSON( "$mod" << BSON_ARRAY( "q" << 2 ) ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_TRUE( !result.isOK() ); query = BSON( "x" << BSON( "$mod" << 3 ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_TRUE( !result.isOK() ); query = BSON( "x" << BSON( "$mod" << BSON( "a" << 1 << "b" << 2 ) ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_TRUE( !result.isOK() ); } - TEST( ExpressionParserLeafTest, SimpleMod1 ) { + TEST( MatchExpressionParserLeafTest, SimpleMod1 ) { BSONObj query = BSON( "x" << BSON( "$mod" << BSON_ARRAY( 3 << 2 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 5 ) ) ); @@ -122,9 +122,9 @@ namespace mongo { ASSERT( result.getValue()->matches( BSON( "x" << 8 ) ) ); } - TEST( ExpressionParserLeafTest, SimpleModNotNumber ) { + TEST( MatchExpressionParserLeafTest, SimpleModNotNumber ) { BSONObj query = BSON( "x" << BSON( "$mod" << BSON_ARRAY( 2 << "r" ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 2 ) ) ); @@ -134,9 +134,9 @@ namespace mongo { } - TEST( ExpressionParserLeafTest, SimpleIN1 ) { + TEST( MatchExpressionParserLeafTest, SimpleIN1 ) { BSONObj query = BSON( "x" << BSON( "$in" << BSON_ARRAY( 2 << 3 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -145,37 +145,37 @@ namespace mongo { } - TEST( ExpressionParserLeafTest, INNotArray ) { + TEST( MatchExpressionParserLeafTest, INNotArray ) { BSONObj query = BSON( "x" << BSON( "$in" << 5 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } - TEST( ExpressionParserLeafTest, INNotElemMatch ) { + TEST( MatchExpressionParserLeafTest, INNotElemMatch ) { BSONObj query = BSON( "x" << BSON( "$in" << BSON_ARRAY( BSON( "$elemMatch" << 1 ) ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } - TEST( ExpressionParserLeafTest, INRegexTooLong ) { + TEST( MatchExpressionParserLeafTest, INRegexTooLong ) { string tooLargePattern( 50 * 1000, 'z' ); BSONObjBuilder inArray; inArray.appendRegex( "0", tooLargePattern, "" ); BSONObjBuilder operand; operand.appendArray( "$in", inArray.obj() ); BSONObj query = BSON( "x" << operand.obj() ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } - TEST( ExpressionParserLeafTest, INRegexTooLong2 ) { + TEST( MatchExpressionParserLeafTest, INRegexTooLong2 ) { string tooLargePattern( 50 * 1000, 'z' ); BSONObj query = BSON( "x" << BSON( "$in" << BSON_ARRAY( BSON( "$regex" << tooLargePattern ) ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } - TEST( ExpressionParserLeafTest, INRegexStuff ) { + TEST( MatchExpressionParserLeafTest, INRegexStuff ) { BSONObjBuilder inArray; inArray.appendRegex( "0", "^a", "" ); inArray.appendRegex( "1", "B", "i" ); @@ -184,7 +184,7 @@ namespace mongo { operand.appendArray( "$in", inArray.obj() ); BSONObj query = BSON( "a" << operand.obj() ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); BSONObj matchFirst = BSON( "a" << "ax" ); @@ -204,9 +204,9 @@ namespace mongo { ASSERT( !result.getValue()->matches( notMatchRegex ) ); } - TEST( ExpressionParserLeafTest, SimpleNIN1 ) { + TEST( MatchExpressionParserLeafTest, SimpleNIN1 ) { BSONObj query = BSON( "x" << BSON( "$nin" << BSON_ARRAY( 2 << 3 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -214,18 +214,18 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << 3 ) ) ); } - TEST( ExpressionParserLeafTest, NINNotArray ) { + TEST( MatchExpressionParserLeafTest, NINNotArray ) { BSONObj query = BSON( "x" << BSON( "$nin" << 5 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } - TEST( ExpressionParserLeafTest, Regex1 ) { + TEST( MatchExpressionParserLeafTest, Regex1 ) { BSONObjBuilder b; b.appendRegex( "x", "abc", "i" ); BSONObj query = b.obj(); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << "abc" ) ) ); @@ -233,9 +233,9 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << "AC" ) ) ); } - TEST( ExpressionParserLeafTest, Regex2 ) { + TEST( MatchExpressionParserLeafTest, Regex2 ) { BSONObj query = BSON( "x" << BSON( "$regex" << "abc" << "$options" << "i" ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << "abc" ) ) ); @@ -243,82 +243,82 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << "AC" ) ) ); } - TEST( ExpressionParserLeafTest, RegexBad ) { + TEST( MatchExpressionParserLeafTest, RegexBad ) { BSONObj query = BSON( "x" << BSON( "$regex" << "abc" << "$optionas" << "i" ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); query = BSON( "x" << BSON( "$optionas" << "i" ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); query = BSON( "x" << BSON( "$options" << "i" ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); // has to be in the other order query = BSON( "x" << BSON( "$options" << "i" << "$regex" << "abc" ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); query = BSON( "x" << BSON( "$gt" << "i" << "$regex" << "abc" ) ); - result = ExpressionParser::parse( query ); + result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } - TEST( ExpressionParserLeafTest, ExistsYes1 ) { + TEST( MatchExpressionParserLeafTest, ExistsYes1 ) { BSONObjBuilder b; b.appendBool( "$exists", true ); BSONObj query = BSON( "x" << b.obj() ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << "abc" ) ) ); ASSERT( !result.getValue()->matches( BSON( "y" << "AC" ) ) ); } - TEST( ExpressionParserLeafTest, ExistsNO1 ) { + TEST( MatchExpressionParserLeafTest, ExistsNO1 ) { BSONObjBuilder b; b.appendBool( "$exists", false ); BSONObj query = BSON( "x" << b.obj() ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << "abc" ) ) ); ASSERT( result.getValue()->matches( BSON( "y" << "AC" ) ) ); } - TEST( ExpressionParserLeafTest, Type1 ) { + TEST( MatchExpressionParserLeafTest, Type1 ) { BSONObj query = BSON( "x" << BSON( "$type" << String ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << "abc" ) ) ); ASSERT( !result.getValue()->matches( BSON( "x" << 5 ) ) ); } - TEST( ExpressionParserLeafTest, Type2 ) { + TEST( MatchExpressionParserLeafTest, Type2 ) { BSONObj query = BSON( "x" << BSON( "$type" << (double)NumberDouble ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 5.3 ) ) ); ASSERT( !result.getValue()->matches( BSON( "x" << 5 ) ) ); } - TEST( ExpressionParserLeafTest, TypeDoubleOperator ) { + TEST( MatchExpressionParserLeafTest, TypeDoubleOperator ) { BSONObj query = BSON( "x" << BSON( "$type" << 1.5 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 5.3 ) ) ); ASSERT( !result.getValue()->matches( BSON( "x" << 5 ) ) ); } - TEST( ExpressionParserLeafTest, TypeNull ) { + TEST( MatchExpressionParserLeafTest, TypeNull ) { BSONObj query = BSON( "x" << BSON( "$type" << jstNULL ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSONObj() ) ); @@ -328,20 +328,20 @@ namespace mongo { ASSERT( result.getValue()->matches( b.obj() ) ); } - TEST( ExpressionParserLeafTest, TypeBadType ) { + TEST( MatchExpressionParserLeafTest, TypeBadType ) { BSONObjBuilder b; b.append( "$type", ( JSTypeMax + 1 ) ); BSONObj query = BSON( "x" << b.obj() ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 5.3 ) ) ); ASSERT( !result.getValue()->matches( BSON( "x" << 5 ) ) ); } - TEST( ExpressionParserLeafTest, TypeBad ) { + TEST( MatchExpressionParserLeafTest, TypeBad ) { BSONObj query = BSON( "x" << BSON( "$type" << BSON( "x" << 1 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_FALSE( result.isOK() ); } diff --git a/src/mongo/db/matcher/expression_parser_test.cpp b/src/mongo/db/matcher/expression_parser_test.cpp index 92f5248a3bb..f7ee08f3da0 100644 --- a/src/mongo/db/matcher/expression_parser_test.cpp +++ b/src/mongo/db/matcher/expression_parser_test.cpp @@ -27,18 +27,18 @@ namespace mongo { - TEST( ExpressionParserTest, SimpleEQ1 ) { + TEST( MatchExpressionParserTest, SimpleEQ1 ) { BSONObj query = BSON( "x" << 2 ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 2 ) ) ); ASSERT( !result.getValue()->matches( BSON( "x" << 3 ) ) ); } - TEST( ExpressionParserTest, Multiple1 ) { + TEST( MatchExpressionParserTest, Multiple1 ) { BSONObj query = BSON( "x" << 5 << "y" << BSON( "$gt" << 5 << "$lt" << 8 ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 5 << "y" << 7 ) ) ); diff --git a/src/mongo/db/matcher/expression_parser_tree.cpp b/src/mongo/db/matcher/expression_parser_tree.cpp index ba375ea6784..d510ecaae1a 100644 --- a/src/mongo/db/matcher/expression_parser_tree.cpp +++ b/src/mongo/db/matcher/expression_parser_tree.cpp @@ -30,7 +30,7 @@ namespace mongo { - Status ExpressionParser::_parseTreeList( const BSONObj& arr, ListOfExpression* out ) { + Status MatchExpressionParser::_parseTreeList( const BSONObj& arr, ListOfMatchExpression* out ) { BSONObjIterator i( arr ); while ( i.more() ) { BSONElement e = i.next(); @@ -39,7 +39,7 @@ namespace mongo { return Status( ErrorCodes::BadValue, "$or/$and/$nor entries need to be full objects" ); - StatusWithExpression sub = parse( e.Obj() ); + StatusWithMatchExpression sub = parse( e.Obj() ); if ( !sub.isOK() ) return sub.getStatus(); @@ -48,33 +48,33 @@ namespace mongo { return Status::OK(); } - StatusWithExpression ExpressionParser::_parseNot( const char* name, + StatusWithMatchExpression MatchExpressionParser::_parseNot( const char* name, const BSONElement& e ) { if ( e.type() == RegEx ) { - StatusWithExpression s = _parseRegexElement( name, e ); + StatusWithMatchExpression s = _parseRegexElement( name, e ); if ( !s.isOK() ) return s; - std::auto_ptr<NotExpression> n( new NotExpression() ); + std::auto_ptr<NotMatchExpression> n( new NotMatchExpression() ); Status s2 = n->init( s.getValue() ); if ( !s2.isOK() ) - return StatusWithExpression( s2 ); - return StatusWithExpression( n.release() ); + return StatusWithMatchExpression( s2 ); + return StatusWithMatchExpression( n.release() ); } if ( e.type() != Object ) - return StatusWithExpression( ErrorCodes::BadValue, "$not needs a regex or a document" ); + return StatusWithMatchExpression( ErrorCodes::BadValue, "$not needs a regex or a document" ); - std::auto_ptr<AndExpression> theAnd( new AndExpression() ); + std::auto_ptr<AndMatchExpression> theAnd( new AndMatchExpression() ); Status s = _parseSub( name, e.Obj(), theAnd.get() ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); - std::auto_ptr<NotExpression> theNot( new NotExpression() ); + std::auto_ptr<NotMatchExpression> theNot( new NotMatchExpression() ); s = theNot->init( theAnd.release() ); if ( !s.isOK() ) - return StatusWithExpression( s ); + return StatusWithMatchExpression( s ); - return StatusWithExpression( theNot.release() ); + return StatusWithMatchExpression( theNot.release() ); } } diff --git a/src/mongo/db/matcher/expression_parser_tree_test.cpp b/src/mongo/db/matcher/expression_parser_tree_test.cpp index 57594d8bf53..65e3e1af055 100644 --- a/src/mongo/db/matcher/expression_parser_tree_test.cpp +++ b/src/mongo/db/matcher/expression_parser_tree_test.cpp @@ -27,10 +27,10 @@ namespace mongo { - TEST( ExpressionParserTreeTest, OR1 ) { + TEST( MatchExpressionParserTreeTest, OR1 ) { BSONObj query = BSON( "$or" << BSON_ARRAY( BSON( "x" << 1 ) << BSON( "y" << 2 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -39,11 +39,11 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "y" << 1 ) ) ); } - TEST( ExpressionParserTreeTest, OREmbedded ) { + TEST( MatchExpressionParserTreeTest, OREmbedded ) { BSONObj query1 = BSON( "$or" << BSON_ARRAY( BSON( "x" << 1 ) << BSON( "y" << 2 ) ) ); BSONObj query2 = BSON( "$or" << BSON_ARRAY( query1 ) ); - StatusWithExpression result = ExpressionParser::parse( query2 ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query2 ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -53,10 +53,10 @@ namespace mongo { } - TEST( ExpressionParserTreeTest, AND1 ) { + TEST( MatchExpressionParserTreeTest, AND1 ) { BSONObj query = BSON( "$and" << BSON_ARRAY( BSON( "x" << 1 ) << BSON( "y" << 2 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -67,10 +67,10 @@ namespace mongo { ASSERT( !result.getValue()->matches( BSON( "x" << 2 << "y" << 2 ) ) ); } - TEST( ExpressionParserTreeTest, NOREmbedded ) { + TEST( MatchExpressionParserTreeTest, NOREmbedded ) { BSONObj query = BSON( "$nor" << BSON_ARRAY( BSON( "x" << 1 ) << BSON( "y" << 2 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << 1 ) ) ); @@ -79,20 +79,20 @@ namespace mongo { ASSERT( result.getValue()->matches( BSON( "y" << 1 ) ) ); } - TEST( ExpressionParserTreeTest, NOT1 ) { + TEST( MatchExpressionParserTreeTest, NOT1 ) { BSONObj query = BSON( "x" << BSON( "$not" << BSON( "$gt" << 5 ) ) ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( result.getValue()->matches( BSON( "x" << 2 ) ) ); ASSERT( !result.getValue()->matches( BSON( "x" << 8 ) ) ); } - TEST( ExpressionParserLeafTest, NotRegex1 ) { + TEST( MatchExpressionParserLeafTest, NotRegex1 ) { BSONObjBuilder b; b.appendRegex( "$not", "abc", "i" ); BSONObj query = BSON( "x" << b.obj() ); - StatusWithExpression result = ExpressionParser::parse( query ); + StatusWithMatchExpression result = MatchExpressionParser::parse( query ); ASSERT_TRUE( result.isOK() ); ASSERT( !result.getValue()->matches( BSON( "x" << "abc" ) ) ); diff --git a/src/mongo/db/matcher/expression_test.cpp b/src/mongo/db/matcher/expression_test.cpp index 30dae318e89..93c1d20af2a 100644 --- a/src/mongo/db/matcher/expression_test.cpp +++ b/src/mongo/db/matcher/expression_test.cpp @@ -16,7 +16,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" @@ -27,16 +27,16 @@ namespace mongo { - TEST( ExpressionTest, Parse1 ) { - //TreeExpression* e = NULL; - //Status s = Expression::parse( BSON( "x" << 1 ), &e ); + TEST( MatchExpressionTest, Parse1 ) { + //TreeMatchExpression* e = NULL; + //Status s = MatchExpression::parse( BSON( "x" << 1 ), &e ); //ASSERT_TRUE( s.isOK() ); } - TEST( LeafExpressionTest, Equal1 ) { + TEST( LeafMatchExpressionTest, Equal1 ) { BSONObj temp = BSON( "x" << 5 ); - ComparisonExpression e; - e.init( "x", ComparisonExpression::EQ, temp["x"] ); + ComparisonMatchExpression e; + e.init( "x", ComparisonMatchExpression::EQ, temp["x"] ); ASSERT_TRUE( e.matches( fromjson( "{ x : 5 }" ) ) ); ASSERT_TRUE( e.matches( fromjson( "{ x : [5] }" ) ) ); @@ -50,12 +50,12 @@ namespace mongo { ASSERT_FALSE( e.matches( fromjson( "{ x : [[5]] }" ) ) ); } - TEST( LeafExpressionTest, Comp1 ) { + TEST( LeafMatchExpressionTest, Comp1 ) { BSONObj temp = BSON( "x" << 5 ); { - ComparisonExpression e; - e.init( "x", ComparisonExpression::LTE, temp["x"] ); + ComparisonMatchExpression e; + e.init( "x", ComparisonMatchExpression::LTE, temp["x"] ); ASSERT_TRUE( e.matches( fromjson( "{ x : 5 }" ) ) ); ASSERT_TRUE( e.matches( fromjson( "{ x : 4 }" ) ) ); ASSERT_FALSE( e.matches( fromjson( "{ x : 6 }" ) ) ); @@ -63,8 +63,8 @@ namespace mongo { } { - ComparisonExpression e; - e.init( "x", ComparisonExpression::LT, temp["x"] ); + ComparisonMatchExpression e; + e.init( "x", ComparisonMatchExpression::LT, temp["x"] ); ASSERT_FALSE( e.matches( fromjson( "{ x : 5 }" ) ) ); ASSERT_TRUE( e.matches( fromjson( "{ x : 4 }" ) ) ); ASSERT_FALSE( e.matches( fromjson( "{ x : 6 }" ) ) ); @@ -72,8 +72,8 @@ namespace mongo { } { - ComparisonExpression e; - e.init( "x", ComparisonExpression::GTE, temp["x"] ); + ComparisonMatchExpression e; + e.init( "x", ComparisonMatchExpression::GTE, temp["x"] ); ASSERT_TRUE( e.matches( fromjson( "{ x : 5 }" ) ) ); ASSERT_FALSE( e.matches( fromjson( "{ x : 4 }" ) ) ); ASSERT_TRUE( e.matches( fromjson( "{ x : 6 }" ) ) ); @@ -81,8 +81,8 @@ namespace mongo { } { - ComparisonExpression e; - e.init( "x", ComparisonExpression::GT, temp["x"] ); + ComparisonMatchExpression e; + e.init( "x", ComparisonMatchExpression::GT, temp["x"] ); ASSERT_FALSE( e.matches( fromjson( "{ x : 5 }" ) ) ); ASSERT_FALSE( e.matches( fromjson( "{ x : 4 }" ) ) ); ASSERT_TRUE( e.matches( fromjson( "{ x : 6 }" ) ) ); diff --git a/src/mongo/db/matcher/expression_tree.cpp b/src/mongo/db/matcher/expression_tree.cpp index d0bc7db9055..840a4fdd96c 100644 --- a/src/mongo/db/matcher/expression_tree.cpp +++ b/src/mongo/db/matcher/expression_tree.cpp @@ -25,26 +25,26 @@ namespace mongo { - ListOfExpression::~ListOfExpression() { + ListOfMatchExpression::~ListOfMatchExpression() { for ( unsigned i = 0; i < _expressions.size(); i++ ) delete _expressions[i]; _expressions.clear(); } - void ListOfExpression::add( Expression* e ) { + void ListOfMatchExpression::add( MatchExpression* e ) { verify( e ); _expressions.push_back( e ); } - void ListOfExpression::_debugList( StringBuilder& debug, int level ) const { + void ListOfMatchExpression::_debugList( StringBuilder& debug, int level ) const { for ( unsigned i = 0; i < _expressions.size(); i++ ) _expressions[i]->debugString( debug, level + 1 ); } // ----- - bool AndExpression::matches( const BSONObj& doc, MatchDetails* details ) const { + bool AndMatchExpression::matches( const BSONObj& doc, MatchDetails* details ) const { for ( size_t i = 0; i < size(); i++ ) { if ( !get(i)->matches( doc, details ) ) { if ( details ) @@ -55,7 +55,7 @@ namespace mongo { return true; } - bool AndExpression::matchesSingleElement( const BSONElement& e ) const { + bool AndMatchExpression::matchesSingleElement( const BSONElement& e ) const { for ( size_t i = 0; i < size(); i++ ) { if ( !get(i)->matchesSingleElement( e ) ) { return false; @@ -65,7 +65,7 @@ namespace mongo { } - void AndExpression::debugString( StringBuilder& debug, int level ) const { + void AndMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << "$and\n"; _debugList( debug, level ); @@ -73,7 +73,7 @@ namespace mongo { // ----- - bool OrExpression::matches( const BSONObj& doc, MatchDetails* details ) const { + bool OrMatchExpression::matches( const BSONObj& doc, MatchDetails* details ) const { for ( size_t i = 0; i < size(); i++ ) { if ( get(i)->matches( doc, NULL ) ) { return true; @@ -82,7 +82,7 @@ namespace mongo { return false; } - bool OrExpression::matchesSingleElement( const BSONElement& e ) const { + bool OrMatchExpression::matchesSingleElement( const BSONElement& e ) const { for ( size_t i = 0; i < size(); i++ ) { if ( get(i)->matchesSingleElement( e ) ) { return true; @@ -92,7 +92,7 @@ namespace mongo { } - void OrExpression::debugString( StringBuilder& debug, int level ) const { + void OrMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << "$or\n"; _debugList( debug, level ); @@ -100,7 +100,7 @@ namespace mongo { // ---- - bool NorExpression::matches( const BSONObj& doc, MatchDetails* details ) const { + bool NorMatchExpression::matches( const BSONObj& doc, MatchDetails* details ) const { for ( size_t i = 0; i < size(); i++ ) { if ( get(i)->matches( doc, NULL ) ) { return false; @@ -109,7 +109,7 @@ namespace mongo { return true; } - bool NorExpression::matchesSingleElement( const BSONElement& e ) const { + bool NorMatchExpression::matchesSingleElement( const BSONElement& e ) const { for ( size_t i = 0; i < size(); i++ ) { if ( get(i)->matchesSingleElement( e ) ) { return false; @@ -118,7 +118,7 @@ namespace mongo { return true; } - void NorExpression::debugString( StringBuilder& debug, int level ) const { + void NorMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << "$nor\n"; _debugList( debug, level ); @@ -126,7 +126,7 @@ namespace mongo { // ------- - void NotExpression::debugString( StringBuilder& debug, int level ) const { + void NotMatchExpression::debugString( StringBuilder& debug, int level ) const { _debugAddSpace( debug, level ); debug << "$not\n"; _exp->debugString( debug, level + 1 ); diff --git a/src/mongo/db/matcher/expression_tree.h b/src/mongo/db/matcher/expression_tree.h index 4223b9a797b..8dd6885d26c 100644 --- a/src/mongo/db/matcher/expression_tree.h +++ b/src/mongo/db/matcher/expression_tree.h @@ -28,14 +28,14 @@ */ namespace mongo { - class ListOfExpression : public Expression { + class ListOfMatchExpression : public MatchExpression { public: - virtual ~ListOfExpression(); + virtual ~ListOfMatchExpression(); /** * @param e - I take ownership */ - void add( Expression* e ); + void add( MatchExpression* e ); /** * clears all the thingsd we own, and does NOT delete @@ -44,18 +44,18 @@ namespace mongo { void clearAndRelease() { _expressions.clear(); } size_t size() const { return _expressions.size(); } - Expression* get( size_t i ) const { return _expressions[i]; } + MatchExpression* get( size_t i ) const { return _expressions[i]; } protected: void _debugList( StringBuilder& debug, int level ) const; private: - std::vector< Expression* > _expressions; + std::vector< MatchExpression* > _expressions; }; - class AndExpression : public ListOfExpression { + class AndMatchExpression : public ListOfMatchExpression { public: - virtual ~AndExpression(){} + virtual ~AndMatchExpression(){} virtual bool matches( const BSONObj& doc, MatchDetails* details = 0 ) const; virtual bool matchesSingleElement( const BSONElement& e ) const; @@ -63,9 +63,9 @@ namespace mongo { virtual void debugString( StringBuilder& debug, int level = 0 ) const; }; - class OrExpression : public ListOfExpression { + class OrMatchExpression : public ListOfMatchExpression { public: - virtual ~OrExpression(){} + virtual ~OrMatchExpression(){} virtual bool matches( const BSONObj& doc, MatchDetails* details = 0 ) const; virtual bool matchesSingleElement( const BSONElement& e ) const; @@ -73,9 +73,9 @@ namespace mongo { virtual void debugString( StringBuilder& debug, int level = 0 ) const; }; - class NorExpression : public ListOfExpression { + class NorMatchExpression : public ListOfMatchExpression { public: - virtual ~NorExpression(){} + virtual ~NorMatchExpression(){} virtual bool matches( const BSONObj& doc, MatchDetails* details = 0 ) const; virtual bool matchesSingleElement( const BSONElement& e ) const; @@ -83,12 +83,12 @@ namespace mongo { virtual void debugString( StringBuilder& debug, int level = 0 ) const; }; - class NotExpression : public Expression { + class NotMatchExpression : public MatchExpression { public: /** * @param exp - I own it, and will delete */ - virtual Status init( Expression* exp ) { + virtual Status init( MatchExpression* exp ) { _exp.reset( exp ); return Status::OK(); } @@ -103,7 +103,7 @@ namespace mongo { virtual void debugString( StringBuilder& debug, int level = 0 ) const; private: - boost::scoped_ptr<Expression> _exp; + boost::scoped_ptr<MatchExpression> _exp; }; } diff --git a/src/mongo/db/matcher/expression_tree_test.cpp b/src/mongo/db/matcher/expression_tree_test.cpp index 485e154951e..a02d423c621 100644 --- a/src/mongo/db/matcher/expression_tree_test.cpp +++ b/src/mongo/db/matcher/expression_tree_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" @@ -26,21 +26,21 @@ namespace mongo { - TEST( NotExpression, MatchesScalar ) { + TEST( NotMatchExpression, MatchesScalar ) { BSONObj baseOperand = BSON( "$lt" << 5 ); - auto_ptr<ComparisonExpression> lt( new ComparisonExpression() ); - ASSERT( lt->init( "a", ComparisonExpression::LT, baseOperand[ "$lt" ] ).isOK() ); - NotExpression notOp; + auto_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); + ASSERT( lt->init( "a", ComparisonMatchExpression::LT, baseOperand[ "$lt" ] ).isOK() ); + NotMatchExpression notOp; ASSERT( notOp.init( lt.release() ).isOK() ); ASSERT( notOp.matches( BSON( "a" << 6 ), NULL ) ); ASSERT( !notOp.matches( BSON( "a" << 4 ), NULL ) ); } - TEST( NotExpression, MatchesArray ) { + TEST( NotMatchExpression, MatchesArray ) { BSONObj baseOperand = BSON( "$lt" << 5 ); - auto_ptr<ComparisonExpression> lt( new ComparisonExpression() ); - ASSERT( lt->init( "a", ComparisonExpression::LT, baseOperand[ "$lt" ] ).isOK() ); - NotExpression notOp; + auto_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); + ASSERT( lt->init( "a", ComparisonMatchExpression::LT, baseOperand[ "$lt" ] ).isOK() ); + NotMatchExpression notOp; ASSERT( notOp.init( lt.release() ).isOK() ); ASSERT( notOp.matches( BSON( "a" << BSON_ARRAY( 6 ) ), NULL ) ); ASSERT( !notOp.matches( BSON( "a" << BSON_ARRAY( 4 ) ), NULL ) ); @@ -48,11 +48,11 @@ namespace mongo { ASSERT( !notOp.matches( BSON( "a" << BSON_ARRAY( 4 << 5 << 6 ) ), NULL ) ); } - TEST( NotExpression, ElemMatchKey ) { + TEST( NotMatchExpression, ElemMatchKey ) { BSONObj baseOperand = BSON( "$lt" << 5 ); - auto_ptr<ComparisonExpression> lt( new ComparisonExpression() ); - ASSERT( lt->init( "a", ComparisonExpression::LT, baseOperand[ "$lt" ] ).isOK() ); - NotExpression notOp; + auto_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); + ASSERT( lt->init( "a", ComparisonMatchExpression::LT, baseOperand[ "$lt" ] ).isOK() ); + NotMatchExpression notOp; ASSERT( notOp.init( lt.release() ).isOK() ); MatchDetails details; details.requestElemMatchKey(); @@ -65,15 +65,15 @@ namespace mongo { ASSERT( !details.hasElemMatchKey() ); } /* - TEST( NotExpression, MatchesIndexKey ) { + TEST( NotMatchExpression, MatchesIndexKey ) { BSONObj baseOperand = BSON( "$lt" << 5 ); - auto_ptr<ComparisonExpression> lt( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); ASSERT( lt->init( "a", baseOperand[ "$lt" ] ).isOK() ); - NotExpression notOp; + NotMatchExpression notOp; ASSERT( notOp.init( lt.release() ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << "7" ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == notOp.matchesIndexKey( indexKey, indexSpec ) ); } */ @@ -83,20 +83,20 @@ namespace mongo { BSONObj baseOperand = BSON( "$lt" << 5 ); BSONObj match = BSON( "a" << 4 ); BSONObj notMatch = BSON( "a" << 5 ); - auto_ptr<ComparisonExpression> lt( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); ASSERT( lt->init( "", baseOperand[ "$lt" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( lt.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( lt.release() ); AndOp andOp; - ASSERT( andOp.init( &subExpressions ).isOK() ); + ASSERT( andOp.init( &subMatchExpressions ).isOK() ); ASSERT( andOp.matchesSingleElement( match[ "a" ] ) ); ASSERT( !andOp.matchesSingleElement( notMatch[ "a" ] ) ); } */ TEST( AndOp, NoClauses ) { - AndExpression andExpression; - ASSERT( andExpression.matches( BSONObj(), NULL ) ); + AndMatchExpression andMatchExpression; + ASSERT( andMatchExpression.matches( BSONObj(), NULL ) ); } TEST( AndOp, MatchesElementThreeClauses ) { @@ -107,14 +107,14 @@ namespace mongo { BSONObj notMatch2 = BSON( "a" << "a1" ); BSONObj notMatch3 = BSON( "a" << "r" ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); - ASSERT( sub1->init( "a", ComparisonExpression::LT, baseOperand1[ "$lt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); - ASSERT( sub2->init( "a", ComparisonExpression::GT, baseOperand2[ "$gt" ] ).isOK() ); - auto_ptr<RegexExpression> sub3( new RegexExpression() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); + ASSERT( sub1->init( "a", ComparisonMatchExpression::LT, baseOperand1[ "$lt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); + ASSERT( sub2->init( "a", ComparisonMatchExpression::GT, baseOperand2[ "$gt" ] ).isOK() ); + auto_ptr<RegexMatchExpression> sub3( new RegexMatchExpression() ); ASSERT( sub3->init( "a", "1", "" ).isOK() ); - AndExpression andOp; + AndMatchExpression andOp; andOp.add( sub1.release() ); andOp.add( sub2.release() ); andOp.add( sub3.release() ); @@ -127,10 +127,10 @@ namespace mongo { TEST( AndOp, MatchesSingleClause ) { BSONObj baseOperand = BSON( "$ne" << 5 ); - auto_ptr<ComparisonExpression> ne( new ComparisonExpression() ); - ASSERT( ne->init( "a", ComparisonExpression::NE, baseOperand[ "$ne" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> ne( new ComparisonMatchExpression() ); + ASSERT( ne->init( "a", ComparisonMatchExpression::NE, baseOperand[ "$ne" ] ).isOK() ); - AndExpression andOp; + AndMatchExpression andOp; andOp.add( ne.release() ); ASSERT( andOp.matches( BSON( "a" << 4 ), NULL ) ); @@ -144,16 +144,16 @@ namespace mongo { BSONObj baseOperand2 = BSON( "$lt" << 10 ); BSONObj baseOperand3 = BSON( "$lt" << 100 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); - ASSERT( sub1->init( "a", ComparisonExpression::GT, baseOperand1[ "$gt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); + ASSERT( sub1->init( "a", ComparisonMatchExpression::GT, baseOperand1[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); - ASSERT( sub2->init( "a", ComparisonExpression::LT, baseOperand2[ "$lt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); + ASSERT( sub2->init( "a", ComparisonMatchExpression::LT, baseOperand2[ "$lt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub3( new ComparisonExpression() ); - ASSERT( sub3->init( "b", ComparisonExpression::LT, baseOperand3[ "$lt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub3( new ComparisonMatchExpression() ); + ASSERT( sub3->init( "b", ComparisonMatchExpression::LT, baseOperand3[ "$lt" ] ).isOK() ); - AndExpression andOp; + AndMatchExpression andOp; andOp.add( sub1.release() ); andOp.add( sub2.release() ); andOp.add( sub3.release() ); @@ -169,13 +169,13 @@ namespace mongo { BSONObj baseOperand1 = BSON( "a" << 1 ); BSONObj baseOperand2 = BSON( "b" << 2 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); - ASSERT( sub1->init( "a", ComparisonExpression::EQ, baseOperand1[ "a" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); + ASSERT( sub1->init( "a", ComparisonMatchExpression::EQ, baseOperand1[ "a" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); - ASSERT( sub2->init( "b", ComparisonExpression::EQ, baseOperand2[ "b" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); + ASSERT( sub2->init( "b", ComparisonMatchExpression::EQ, baseOperand2[ "b" ] ).isOK() ); - AndExpression andOp; + AndMatchExpression andOp; andOp.add( sub1.release() ); andOp.add( sub2.release() ); @@ -196,21 +196,21 @@ namespace mongo { TEST( AndOp, MatchesIndexKeyWithoutUnknown ) { BSONObj baseOperand1 = BSON( "$gt" << 1 ); BSONObj baseOperand2 = BSON( "$lt" << 5 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); ASSERT( sub1->init( "a", baseOperand1[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); ASSERT( sub2->init( "a", baseOperand2[ "$lt" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( sub1.release() ); - subExpressions.mutableVector().push_back( sub2.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( sub1.release() ); + subMatchExpressions.mutableVector().push_back( sub2.release() ); AndOp andOp; - ASSERT( andOp.init( &subExpressions ).isOK() ); + ASSERT( andOp.init( &subMatchExpressions ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == andOp.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == andOp.matchesIndexKey( BSON( "" << 0 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == andOp.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); } @@ -219,24 +219,24 @@ namespace mongo { BSONObj baseOperand2 = BSON( "$lt" << 5 ); // This part will return PartialMatchResult_Unknown. BSONObj baseOperand3 = BSON( "$ne" << 5 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); ASSERT( sub1->init( "a", baseOperand1[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); ASSERT( sub2->init( "a", baseOperand2[ "$lt" ] ).isOK() ); auto_ptr<NeOp> sub3( new NeOp() ); ASSERT( sub3->init( "a", baseOperand3[ "$ne" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( sub1.release() ); - subExpressions.mutableVector().push_back( sub2.release() ); - subExpressions.mutableVector().push_back( sub3.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( sub1.release() ); + subMatchExpressions.mutableVector().push_back( sub2.release() ); + subMatchExpressions.mutableVector().push_back( sub3.release() ); AndOp andOp; - ASSERT( andOp.init( &subExpressions ).isOK() ); + ASSERT( andOp.init( &subMatchExpressions ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == andOp.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == andOp.matchesIndexKey( BSON( "" << 0 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == andOp.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); } */ @@ -246,19 +246,19 @@ namespace mongo { BSONObj baseOperand = BSON( "$lt" << 5 ); BSONObj match = BSON( "a" << 4 ); BSONObj notMatch = BSON( "a" << 5 ); - auto_ptr<ComparisonExpression> lt( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); ASSERT( lt->init( "a", baseOperand[ "$lt" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( lt.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( lt.release() ); OrOp orOp; - ASSERT( orOp.init( &subExpressions ).isOK() ); + ASSERT( orOp.init( &subMatchExpressions ).isOK() ); ASSERT( orOp.matchesSingleElement( match[ "a" ] ) ); ASSERT( !orOp.matchesSingleElement( notMatch[ "a" ] ) ); } */ TEST( OrOp, NoClauses ) { - OrExpression orOp; + OrMatchExpression orOp; ASSERT( !orOp.matches( BSONObj(), NULL ) ); } /* @@ -270,18 +270,18 @@ namespace mongo { BSONObj match2 = BSON( "a" << 11 ); BSONObj match3 = BSON( "a" << 5 ); BSONObj notMatch = BSON( "a" << "6" ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); ASSERT( sub1->init( "a", baseOperand1[ "$lt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); ASSERT( sub2->init( "a", baseOperand2[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub3( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub3( new ComparisonMatchExpression() ); ASSERT( sub3->init( "a", baseOperand3[ "a" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( sub1.release() ); - subExpressions.mutableVector().push_back( sub2.release() ); - subExpressions.mutableVector().push_back( sub3.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( sub1.release() ); + subMatchExpressions.mutableVector().push_back( sub2.release() ); + subMatchExpressions.mutableVector().push_back( sub3.release() ); OrOp orOp; - ASSERT( orOp.init( &subExpressions ).isOK() ); + ASSERT( orOp.init( &subMatchExpressions ).isOK() ); ASSERT( orOp.matchesSingleElement( match1[ "a" ] ) ); ASSERT( orOp.matchesSingleElement( match2[ "a" ] ) ); ASSERT( orOp.matchesSingleElement( match3[ "a" ] ) ); @@ -290,10 +290,10 @@ namespace mongo { */ TEST( OrOp, MatchesSingleClause ) { BSONObj baseOperand = BSON( "$ne" << 5 ); - auto_ptr<ComparisonExpression> ne( new ComparisonExpression() ); - ASSERT( ne->init( "a", ComparisonExpression::NE, baseOperand[ "$ne" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> ne( new ComparisonMatchExpression() ); + ASSERT( ne->init( "a", ComparisonMatchExpression::NE, baseOperand[ "$ne" ] ).isOK() ); - OrExpression orOp; + OrMatchExpression orOp; orOp.add( ne.release() ); ASSERT( orOp.matches( BSON( "a" << 4 ), NULL ) ); @@ -306,14 +306,14 @@ namespace mongo { BSONObj baseOperand1 = BSON( "$gt" << 10 ); BSONObj baseOperand2 = BSON( "$lt" << 0 ); BSONObj baseOperand3 = BSON( "b" << 100 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); - ASSERT( sub1->init( "a", ComparisonExpression::GT, baseOperand1[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); - ASSERT( sub2->init( "a", ComparisonExpression::LT, baseOperand2[ "$lt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub3( new ComparisonExpression() ); - ASSERT( sub3->init( "b", ComparisonExpression::EQ, baseOperand3[ "b" ] ).isOK() ); - - OrExpression orOp; + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); + ASSERT( sub1->init( "a", ComparisonMatchExpression::GT, baseOperand1[ "$gt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); + ASSERT( sub2->init( "a", ComparisonMatchExpression::LT, baseOperand2[ "$lt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub3( new ComparisonMatchExpression() ); + ASSERT( sub3->init( "b", ComparisonMatchExpression::EQ, baseOperand3[ "b" ] ).isOK() ); + + OrMatchExpression orOp; orOp.add( sub1.release() ); orOp.add( sub2.release() ); orOp.add( sub3.release() ); @@ -330,12 +330,12 @@ namespace mongo { TEST( OrOp, ElemMatchKey ) { BSONObj baseOperand1 = BSON( "a" << 1 ); BSONObj baseOperand2 = BSON( "b" << 2 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); - ASSERT( sub1->init( "a", ComparisonExpression::EQ, baseOperand1[ "a" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); - ASSERT( sub2->init( "b", ComparisonExpression::EQ, baseOperand2[ "b" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); + ASSERT( sub1->init( "a", ComparisonMatchExpression::EQ, baseOperand1[ "a" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); + ASSERT( sub2->init( "b", ComparisonMatchExpression::EQ, baseOperand2[ "b" ] ).isOK() ); - OrExpression orOp; + OrMatchExpression orOp; orOp.add( sub1.release() ); orOp.add( sub2.release() ); @@ -356,21 +356,21 @@ namespace mongo { TEST( OrOp, MatchesIndexKeyWithoutUnknown ) { BSONObj baseOperand1 = BSON( "$gt" << 5 ); BSONObj baseOperand2 = BSON( "$lt" << 1 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); ASSERT( sub1->init( "a", baseOperand1[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); ASSERT( sub2->init( "a", baseOperand2[ "$lt" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( sub1.release() ); - subExpressions.mutableVector().push_back( sub2.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( sub1.release() ); + subMatchExpressions.mutableVector().push_back( sub2.release() ); OrOp orOp; - ASSERT( orOp.init( &subExpressions ).isOK() ); + ASSERT( orOp.init( &subMatchExpressions ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_False == + ASSERT( MatchMatchExpression::PartialMatchResult_False == orOp.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == orOp.matchesIndexKey( BSON( "" << 0 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == orOp.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); } @@ -379,24 +379,24 @@ namespace mongo { BSONObj baseOperand2 = BSON( "$lt" << 1 ); // This part will return PartialMatchResult_Unknown. BSONObj baseOperand3 = BSON( "$ne" << 5 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); ASSERT( sub1->init( "a", baseOperand1[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); ASSERT( sub2->init( "a", baseOperand2[ "$lt" ] ).isOK() ); auto_ptr<NeOp> sub3( new NeOp() ); ASSERT( sub3->init( "a", baseOperand3[ "$ne" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( sub1.release() ); - subExpressions.mutableVector().push_back( sub2.release() ); - subExpressions.mutableVector().push_back( sub3.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( sub1.release() ); + subMatchExpressions.mutableVector().push_back( sub2.release() ); + subMatchExpressions.mutableVector().push_back( sub3.release() ); OrOp orOp; - ASSERT( orOp.init( &subExpressions ).isOK() ); + ASSERT( orOp.init( &subMatchExpressions ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == orOp.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == orOp.matchesIndexKey( BSON( "" << 0 ), indexSpec ) ); - ASSERT( MatchExpression::PartialMatchResult_True == + ASSERT( MatchMatchExpression::PartialMatchResult_True == orOp.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); } */ @@ -406,19 +406,19 @@ namespace mongo { BSONObj baseOperand = BSON( "$lt" << 5 ); BSONObj match = BSON( "a" << 5 ); BSONObj notMatch = BSON( "a" << 4 ); - auto_ptr<ComparisonExpression> lt( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); ASSERT( lt->init( "a", baseOperand[ "$lt" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( lt.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( lt.release() ); NorOp norOp; - ASSERT( norOp.init( &subExpressions ).isOK() ); + ASSERT( norOp.init( &subMatchExpressions ).isOK() ); ASSERT( norOp.matchesSingleElement( match[ "a" ] ) ); ASSERT( !norOp.matchesSingleElement( notMatch[ "a" ] ) ); } */ TEST( NorOp, NoClauses ) { - NorExpression norOp; + NorMatchExpression norOp; ASSERT( norOp.matches( BSONObj(), NULL ) ); } /* @@ -430,18 +430,18 @@ namespace mongo { BSONObj notMatch2 = BSON( "a" << 11 ); BSONObj notMatch3 = BSON( "a" << 5 ); BSONObj match = BSON( "a" << "6" ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); ASSERT( sub1->init( "a", baseOperand1[ "$lt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); ASSERT( sub2->init( "a", baseOperand2[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub3( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> sub3( new ComparisonMatchExpression() ); ASSERT( sub3->init( "a", baseOperand3[ "a" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( sub1.release() ); - subExpressions.mutableVector().push_back( sub2.release() ); - subExpressions.mutableVector().push_back( sub3.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( sub1.release() ); + subMatchExpressions.mutableVector().push_back( sub2.release() ); + subMatchExpressions.mutableVector().push_back( sub3.release() ); NorOp norOp; - ASSERT( norOp.init( &subExpressions ).isOK() ); + ASSERT( norOp.init( &subMatchExpressions ).isOK() ); ASSERT( !norOp.matchesSingleElement( notMatch1[ "a" ] ) ); ASSERT( !norOp.matchesSingleElement( notMatch2[ "a" ] ) ); ASSERT( !norOp.matchesSingleElement( notMatch3[ "a" ] ) ); @@ -451,10 +451,10 @@ namespace mongo { TEST( NorOp, MatchesSingleClause ) { BSONObj baseOperand = BSON( "$ne" << 5 ); - auto_ptr<ComparisonExpression> ne( new ComparisonExpression() ); - ASSERT( ne->init( "a", ComparisonExpression::NE, baseOperand[ "$ne" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> ne( new ComparisonMatchExpression() ); + ASSERT( ne->init( "a", ComparisonMatchExpression::NE, baseOperand[ "$ne" ] ).isOK() ); - NorExpression norOp; + NorMatchExpression norOp; norOp.add( ne.release() ); ASSERT( !norOp.matches( BSON( "a" << 4 ), NULL ) ); @@ -468,14 +468,14 @@ namespace mongo { BSONObj baseOperand2 = BSON( "$lt" << 0 ); BSONObj baseOperand3 = BSON( "b" << 100 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); - ASSERT( sub1->init( "a", ComparisonExpression::GT, baseOperand1[ "$gt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); - ASSERT( sub2->init( "a", ComparisonExpression::LT, baseOperand2[ "$lt" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub3( new ComparisonExpression() ); - ASSERT( sub3->init( "b", ComparisonExpression::EQ, baseOperand3[ "b" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); + ASSERT( sub1->init( "a", ComparisonMatchExpression::GT, baseOperand1[ "$gt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); + ASSERT( sub2->init( "a", ComparisonMatchExpression::LT, baseOperand2[ "$lt" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub3( new ComparisonMatchExpression() ); + ASSERT( sub3->init( "b", ComparisonMatchExpression::EQ, baseOperand3[ "b" ] ).isOK() ); - NorExpression norOp; + NorMatchExpression norOp; norOp.add( sub1.release() ); norOp.add( sub2.release() ); norOp.add( sub3.release() ); @@ -492,12 +492,12 @@ namespace mongo { TEST( NorOp, ElemMatchKey ) { BSONObj baseOperand1 = BSON( "a" << 1 ); BSONObj baseOperand2 = BSON( "b" << 2 ); - auto_ptr<ComparisonExpression> sub1( new ComparisonExpression() ); - ASSERT( sub1->init( "a", ComparisonExpression::EQ, baseOperand1[ "a" ] ).isOK() ); - auto_ptr<ComparisonExpression> sub2( new ComparisonExpression() ); - ASSERT( sub2->init( "b", ComparisonExpression::EQ, baseOperand2[ "b" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); + ASSERT( sub1->init( "a", ComparisonMatchExpression::EQ, baseOperand1[ "a" ] ).isOK() ); + auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); + ASSERT( sub2->init( "b", ComparisonMatchExpression::EQ, baseOperand2[ "b" ] ).isOK() ); - NorExpression norOp; + NorMatchExpression norOp; norOp.add( sub1.release() ); norOp.add( sub2.release() ); @@ -517,15 +517,15 @@ namespace mongo { /** TEST( NorOp, MatchesIndexKey ) { BSONObj baseOperand = BSON( "a" << 5 ); - auto_ptr<ComparisonExpression> eq( new ComparisonExpression() ); + auto_ptr<ComparisonMatchExpression> eq( new ComparisonMatchExpression() ); ASSERT( eq->init( "a", baseOperand[ "a" ] ).isOK() ); - OwnedPointerVector<MatchExpression> subExpressions; - subExpressions.mutableVector().push_back( eq.release() ); + OwnedPointerVector<MatchMatchExpression> subMatchExpressions; + subMatchExpressions.mutableVector().push_back( eq.release() ); NorOp norOp; - ASSERT( norOp.init( &subExpressions ).isOK() ); + ASSERT( norOp.init( &subMatchExpressions ).isOK() ); IndexSpec indexSpec( BSON( "a" << 1 ) ); BSONObj indexKey = BSON( "" << "7" ); - ASSERT( MatchExpression::PartialMatchResult_Unknown == + ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == norOp.matchesIndexKey( indexKey, indexSpec ) ); } */ diff --git a/src/mongo/db/matcher/matcher.cpp b/src/mongo/db/matcher/matcher.cpp index 4db18bb6e55..0db46c3fba2 100644 --- a/src/mongo/db/matcher/matcher.cpp +++ b/src/mongo/db/matcher/matcher.cpp @@ -27,7 +27,7 @@ namespace mongo { Matcher2::Matcher2( const BSONObj& pattern ) : _pattern( pattern ) { - StatusWithExpression result = ExpressionParser::parse( pattern ); + StatusWithMatchExpression result = MatchExpressionParser::parse( pattern ); uassert( 16810, mongoutils::str::stream() << "bad query: " << result.toString(), result.isOK() ); diff --git a/src/mongo/db/matcher/matcher.h b/src/mongo/db/matcher/matcher.h index 457c4c87fab..4e368f31838 100644 --- a/src/mongo/db/matcher/matcher.h +++ b/src/mongo/db/matcher/matcher.h @@ -37,7 +37,7 @@ namespace mongo { private: const BSONObj& _pattern; // this is owned by who created us - boost::scoped_ptr<Expression> _expression; + boost::scoped_ptr<MatchExpression> _expression; }; } |