diff options
author | Blake Oler <blake.oler@10gen.com> | 2017-09-11 16:05:43 -0400 |
---|---|---|
committer | Kyle Suarez <kyle.suarez@mongodb.com> | 2017-11-14 13:52:23 -0500 |
commit | acde99b058c6e23302bc849015ed5e90b15b19fc (patch) | |
tree | cc1775bd2272048d55c936b3f4c259931f8409d6 /src/mongo/db/matcher/expression_tree_test.cpp | |
parent | 4abdc7aff5cd5d0531c53b0ff784826e96700418 (diff) | |
download | mongo-acde99b058c6e23302bc849015ed5e90b15b19fc.tar.gz |
SERVER-30783 Move init() logic to MatchExpression constructors
Diffstat (limited to 'src/mongo/db/matcher/expression_tree_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_tree_test.cpp | 320 |
1 files changed, 35 insertions, 285 deletions
diff --git a/src/mongo/db/matcher/expression_tree_test.cpp b/src/mongo/db/matcher/expression_tree_test.cpp index 6b65006cdd1..54e85206d75 100644 --- a/src/mongo/db/matcher/expression_tree_test.cpp +++ b/src/mongo/db/matcher/expression_tree_test.cpp @@ -43,20 +43,16 @@ using std::unique_ptr; TEST(NotMatchExpression, MatchesScalar) { BSONObj baseOperand = BSON("$lt" << 5); - unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression()); - ASSERT(lt->init("a", baseOperand["$lt"]).isOK()); - NotMatchExpression notOp; - ASSERT(notOp.init(lt.release()).isOK()); + unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression("a", baseOperand["$lt"])); + NotMatchExpression notOp(lt.release()); ASSERT(notOp.matchesBSON(BSON("a" << 6), NULL)); ASSERT(!notOp.matchesBSON(BSON("a" << 4), NULL)); } TEST(NotMatchExpression, MatchesArray) { BSONObj baseOperand = BSON("$lt" << 5); - unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression()); - ASSERT(lt->init("a", baseOperand["$lt"]).isOK()); - NotMatchExpression notOp; - ASSERT(notOp.init(lt.release()).isOK()); + unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression("a", baseOperand["$lt"])); + NotMatchExpression notOp(lt.release()); ASSERT(notOp.matchesBSON(BSON("a" << BSON_ARRAY(6)), NULL)); ASSERT(!notOp.matchesBSON(BSON("a" << BSON_ARRAY(4)), NULL)); // All array elements must match. @@ -65,10 +61,8 @@ TEST(NotMatchExpression, MatchesArray) { TEST(NotMatchExpression, ElemMatchKey) { BSONObj baseOperand = BSON("$lt" << 5); - unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression()); - ASSERT(lt->init("a", baseOperand["$lt"]).isOK()); - NotMatchExpression notOp; - ASSERT(notOp.init(lt.release()).isOK()); + unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression("a", baseOperand["$lt"])); + NotMatchExpression notOp(lt.release()); MatchDetails details; details.requestElemMatchKey(); ASSERT(!notOp.matchesBSON(BSON("a" << BSON_ARRAY(1)), &details)); @@ -83,10 +77,8 @@ TEST(NotMatchExpression, ElemMatchKey) { TEST(NotMatchExpression, SetCollatorPropagatesToChild) { BSONObj baseOperand = BSON("a" << "string"); - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); - ASSERT(eq->init("a", baseOperand["a"]).isOK()); - NotMatchExpression notOp; - ASSERT(notOp.init(eq.release()).isOK()); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression("a", baseOperand["a"])); + NotMatchExpression notOp(eq.release()); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); notOp.setCollator(&collator); ASSERT(!notOp.matchesBSON(BSON("a" @@ -94,36 +86,6 @@ TEST(NotMatchExpression, SetCollatorPropagatesToChild) { nullptr)); } -/* - TEST( NotMatchExpression, MatchesIndexKey ) { - BSONObj baseOperand = BSON( "$lt" << 5 ); - unique_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); - ASSERT( lt->init( "a", baseOperand[ "$lt" ] ).isOK() ); - NotMatchExpression notOp; - ASSERT( notOp.init( lt.release() ).isOK() ); - IndexSpec indexSpec( BSON( "a" << 1 ) ); - BSONObj indexKey = BSON( "" << "7" ); - ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == - notOp.matchesIndexKey( indexKey, indexSpec ) ); - } -*/ - -/** -TEST( AndOp, MatchesElementSingleClause ) { - BSONObj baseOperand = BSON( "$lt" << 5 ); - BSONObj match = BSON( "a" << 4 ); - BSONObj notMatch = BSON( "a" << 5 ); - unique_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); - ASSERT( lt->init( "", baseOperand[ "$lt" ] ).isOK() ); - std::vector<std::unique_ptr<<MatchMatchExpression>> subMatchExpressions; - subMatchExpressions.mutableVector().push_back( lt.release() ); - AndOp andOp; - ASSERT( andOp.init( &subMatchExpressions ).isOK() ); - ASSERT( andOp.matchesSingleElement( match[ "a" ] ) ); - ASSERT( !andOp.matchesSingleElement( notMatch[ "a" ] ) ); -} -*/ - TEST(AndOp, NoClauses) { AndMatchExpression andMatchExpression; ASSERT(andMatchExpression.matchesBSON(BSONObj(), NULL)); @@ -143,12 +105,9 @@ TEST(AndOp, MatchesElementThreeClauses) { BSONObj notMatch3 = BSON("a" << "r"); - unique_ptr<ComparisonMatchExpression> sub1(new LTMatchExpression()); - ASSERT(sub1->init("a", baseOperand1["$lt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new GTMatchExpression()); - ASSERT(sub2->init("a", baseOperand2["$gt"]).isOK()); - unique_ptr<RegexMatchExpression> sub3(new RegexMatchExpression()); - ASSERT(sub3->init("a", "1", "").isOK()); + unique_ptr<ComparisonMatchExpression> sub1(new LTMatchExpression("a", baseOperand1["$lt"])); + unique_ptr<ComparisonMatchExpression> sub2(new GTMatchExpression("a", baseOperand2["$gt"])); + unique_ptr<RegexMatchExpression> sub3(new RegexMatchExpression("a", "1", "")); AndMatchExpression andOp; andOp.add(sub1.release()); @@ -163,10 +122,8 @@ TEST(AndOp, MatchesElementThreeClauses) { TEST(AndOp, MatchesSingleClause) { BSONObj baseOperand = BSON("$ne" << 5); - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); - ASSERT(eq->init("a", baseOperand["$ne"]).isOK()); - unique_ptr<NotMatchExpression> ne(new NotMatchExpression()); - ASSERT(ne->init(eq.release()).isOK()); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression("a", baseOperand["$ne"])); + unique_ptr<NotMatchExpression> ne(new NotMatchExpression(eq.release())); AndMatchExpression andOp; andOp.add(ne.release()); @@ -182,14 +139,9 @@ TEST(AndOp, MatchesThreeClauses) { BSONObj baseOperand2 = BSON("$lt" << 10); BSONObj baseOperand3 = BSON("$lt" << 100); - unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression()); - ASSERT(sub1->init("a", baseOperand1["$gt"]).isOK()); - - unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression()); - ASSERT(sub2->init("a", baseOperand2["$lt"]).isOK()); - - unique_ptr<ComparisonMatchExpression> sub3(new LTMatchExpression()); - ASSERT(sub3->init("b", baseOperand3["$lt"]).isOK()); + unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression("a", baseOperand1["$gt"])); + unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression("a", baseOperand2["$lt"])); + unique_ptr<ComparisonMatchExpression> sub3(new LTMatchExpression("b", baseOperand3["$lt"])); AndMatchExpression andOp; andOp.add(sub1.release()); @@ -207,11 +159,8 @@ TEST(AndOp, ElemMatchKey) { BSONObj baseOperand1 = BSON("a" << 1); BSONObj baseOperand2 = BSON("b" << 2); - unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression()); - ASSERT(sub1->init("a", baseOperand1["a"]).isOK()); - - unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression()); - ASSERT(sub2->init("b", baseOperand2["b"]).isOK()); + unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression("a", baseOperand1["a"])); + unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression("b", baseOperand2["b"])); AndMatchExpression andOp; andOp.add(sub1.release()); @@ -229,108 +178,15 @@ TEST(AndOp, ElemMatchKey) { ASSERT_EQUALS("1", details.elemMatchKey()); } -/** -TEST( AndOp, MatchesIndexKeyWithoutUnknown ) { - BSONObj baseOperand1 = BSON( "$gt" << 1 ); - BSONObj baseOperand2 = BSON( "$lt" << 5 ); - unique_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); - ASSERT( sub1->init( "a", baseOperand1[ "$gt" ] ).isOK() ); - unique_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); - ASSERT( sub2->init( "a", baseOperand2[ "$lt" ] ).isOK() ); - std::vector<std::unique_ptr<<MatchMatchExpression>> subMatchExpressions; - subMatchExpressions.mutableVector().push_back( sub1.release() ); - subMatchExpressions.mutableVector().push_back( sub2.release() ); - AndOp andOp; - ASSERT( andOp.init( &subMatchExpressions ).isOK() ); - IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_True == - andOp.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_False == - andOp.matchesIndexKey( BSON( "" << 0 ), indexSpec ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_False == - andOp.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); -} - -TEST( AndOp, MatchesIndexKeyWithUnknown ) { - BSONObj baseOperand1 = BSON( "$gt" << 1 ); - BSONObj baseOperand2 = BSON( "$lt" << 5 ); - // This part will return PartialMatchResult_Unknown. - BSONObj baseOperand3 = BSON( "$ne" << 5 ); - unique_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); - ASSERT( sub1->init( "a", baseOperand1[ "$gt" ] ).isOK() ); - unique_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); - ASSERT( sub2->init( "a", baseOperand2[ "$lt" ] ).isOK() ); - unique_ptr<NeOp> sub3( new NeOp() ); - ASSERT( sub3->init( "a", baseOperand3[ "$ne" ] ).isOK() ); - std::vector<std::unique_ptr<<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( &subMatchExpressions ).isOK() ); - IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == - andOp.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_False == - andOp.matchesIndexKey( BSON( "" << 0 ), indexSpec ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_False == - andOp.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); -} -*/ - -/** -TEST( OrOp, MatchesElementSingleClause ) { - BSONObj baseOperand = BSON( "$lt" << 5 ); - BSONObj match = BSON( "a" << 4 ); - BSONObj notMatch = BSON( "a" << 5 ); - unique_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); - ASSERT( lt->init( "a", baseOperand[ "$lt" ] ).isOK() ); - std::vector<std::unique_ptr<<MatchMatchExpression>> subMatchExpressions; - subMatchExpressions.mutableVector().push_back( lt.release() ); - OrOp orOp; - ASSERT( orOp.init( &subMatchExpressions ).isOK() ); - ASSERT( orOp.matchesSingleElement( match[ "a" ] ) ); - ASSERT( !orOp.matchesSingleElement( notMatch[ "a" ] ) ); -} -*/ - TEST(OrOp, NoClauses) { OrMatchExpression orOp; ASSERT(!orOp.matchesBSON(BSONObj(), NULL)); } -/* -TEST( OrOp, MatchesElementThreeClauses ) { - BSONObj baseOperand1 = BSON( "$lt" << 0 ); - BSONObj baseOperand2 = BSON( "$gt" << 10 ); - BSONObj baseOperand3 = BSON( "a" << 5 ); - BSONObj match1 = BSON( "a" << -1 ); - BSONObj match2 = BSON( "a" << 11 ); - BSONObj match3 = BSON( "a" << 5 ); - BSONObj notMatch = BSON( "a" << "6" ); - unique_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); - ASSERT( sub1->init( "a", baseOperand1[ "$lt" ] ).isOK() ); - unique_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); - ASSERT( sub2->init( "a", baseOperand2[ "$gt" ] ).isOK() ); - unique_ptr<ComparisonMatchExpression> sub3( new ComparisonMatchExpression() ); - ASSERT( sub3->init( "a", baseOperand3[ "a" ] ).isOK() ); - std::vector<std::unique_ptr<<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( &subMatchExpressions ).isOK() ); - ASSERT( orOp.matchesSingleElement( match1[ "a" ] ) ); - ASSERT( orOp.matchesSingleElement( match2[ "a" ] ) ); - ASSERT( orOp.matchesSingleElement( match3[ "a" ] ) ); - ASSERT( !orOp.matchesSingleElement( notMatch[ "a" ] ) ); -} -*/ + TEST(OrOp, MatchesSingleClause) { BSONObj baseOperand = BSON("$ne" << 5); - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); - ASSERT(eq->init("a", baseOperand["$ne"]).isOK()); - unique_ptr<NotMatchExpression> ne(new NotMatchExpression()); - ASSERT(ne->init(eq.release()).isOK()); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression("a", baseOperand["$ne"])); + unique_ptr<NotMatchExpression> ne(new NotMatchExpression(eq.release())); OrMatchExpression orOp; orOp.add(ne.release()); @@ -345,12 +201,9 @@ TEST(OrOp, MatchesThreeClauses) { BSONObj baseOperand1 = BSON("$gt" << 10); BSONObj baseOperand2 = BSON("$lt" << 0); BSONObj baseOperand3 = BSON("b" << 100); - unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression()); - ASSERT(sub1->init("a", baseOperand1["$gt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression()); - ASSERT(sub2->init("a", baseOperand2["$lt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub3(new EqualityMatchExpression()); - ASSERT(sub3->init("b", baseOperand3["b"]).isOK()); + unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression("a", baseOperand1["$gt"])); + unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression("a", baseOperand2["$lt"])); + unique_ptr<ComparisonMatchExpression> sub3(new EqualityMatchExpression("b", baseOperand3["b"])); OrMatchExpression orOp; orOp.add(sub1.release()); @@ -369,10 +222,8 @@ TEST(OrOp, MatchesThreeClauses) { TEST(OrOp, ElemMatchKey) { BSONObj baseOperand1 = BSON("a" << 1); BSONObj baseOperand2 = BSON("b" << 2); - unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression()); - ASSERT(sub1->init("a", baseOperand1["a"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression()); - ASSERT(sub2->init("b", baseOperand2["b"]).isOK()); + unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression("a", baseOperand1["a"])); + unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression("b", baseOperand2["b"])); OrMatchExpression orOp; orOp.add(sub1.release()); @@ -389,109 +240,15 @@ TEST(OrOp, ElemMatchKey) { ASSERT(!details.hasElemMatchKey()); } -/** -TEST( OrOp, MatchesIndexKeyWithoutUnknown ) { - BSONObj baseOperand1 = BSON( "$gt" << 5 ); - BSONObj baseOperand2 = BSON( "$lt" << 1 ); - unique_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); - ASSERT( sub1->init( "a", baseOperand1[ "$gt" ] ).isOK() ); - unique_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); - ASSERT( sub2->init( "a", baseOperand2[ "$lt" ] ).isOK() ); - std::vector<std::unique_ptr<<MatchMatchExpression>> subMatchExpressions; - subMatchExpressions.mutableVector().push_back( sub1.release() ); - subMatchExpressions.mutableVector().push_back( sub2.release() ); - OrOp orOp; - ASSERT( orOp.init( &subMatchExpressions ).isOK() ); - IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_False == - orOp.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_True == - orOp.matchesIndexKey( BSON( "" << 0 ), indexSpec ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_True == - orOp.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); -} - -TEST( OrOp, MatchesIndexKeyWithUnknown ) { - BSONObj baseOperand1 = BSON( "$gt" << 5 ); - BSONObj baseOperand2 = BSON( "$lt" << 1 ); - // This part will return PartialMatchResult_Unknown. - BSONObj baseOperand3 = BSON( "$ne" << 5 ); - unique_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); - ASSERT( sub1->init( "a", baseOperand1[ "$gt" ] ).isOK() ); - unique_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); - ASSERT( sub2->init( "a", baseOperand2[ "$lt" ] ).isOK() ); - unique_ptr<NeOp> sub3( new NeOp() ); - ASSERT( sub3->init( "a", baseOperand3[ "$ne" ] ).isOK() ); - std::vector<std::unique_ptr<<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( &subMatchExpressions ).isOK() ); - IndexSpec indexSpec( BSON( "a" << 1 ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == - orOp.matchesIndexKey( BSON( "" << 3 ), indexSpec ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_True == - orOp.matchesIndexKey( BSON( "" << 0 ), indexSpec ) ); - ASSERT( MatchMatchExpression::PartialMatchResult_True == - orOp.matchesIndexKey( BSON( "" << 6 ), indexSpec ) ); -} -*/ - -/** -TEST( NorOp, MatchesElementSingleClause ) { - BSONObj baseOperand = BSON( "$lt" << 5 ); - BSONObj match = BSON( "a" << 5 ); - BSONObj notMatch = BSON( "a" << 4 ); - unique_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() ); - ASSERT( lt->init( "a", baseOperand[ "$lt" ] ).isOK() ); - std::vector<std::unique_ptr<<MatchMatchExpression>> subMatchExpressions; - subMatchExpressions.mutableVector().push_back( lt.release() ); - NorOp norOp; - ASSERT( norOp.init( &subMatchExpressions ).isOK() ); - ASSERT( norOp.matchesSingleElement( match[ "a" ] ) ); - ASSERT( !norOp.matchesSingleElement( notMatch[ "a" ] ) ); -} -*/ - TEST(NorOp, NoClauses) { NorMatchExpression norOp; ASSERT(norOp.matchesBSON(BSONObj(), NULL)); } -/* -TEST( NorOp, MatchesElementThreeClauses ) { - BSONObj baseOperand1 = BSON( "$lt" << 0 ); - BSONObj baseOperand2 = BSON( "$gt" << 10 ); - BSONObj baseOperand3 = BSON( "a" << 5 ); - BSONObj notMatch1 = BSON( "a" << -1 ); - BSONObj notMatch2 = BSON( "a" << 11 ); - BSONObj notMatch3 = BSON( "a" << 5 ); - BSONObj match = BSON( "a" << "6" ); - unique_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); - ASSERT( sub1->init( "a", baseOperand1[ "$lt" ] ).isOK() ); - unique_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); - ASSERT( sub2->init( "a", baseOperand2[ "$gt" ] ).isOK() ); - unique_ptr<ComparisonMatchExpression> sub3( new ComparisonMatchExpression() ); - ASSERT( sub3->init( "a", baseOperand3[ "a" ] ).isOK() ); - std::vector<std::unique_ptr<<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( &subMatchExpressions ).isOK() ); - ASSERT( !norOp.matchesSingleElement( notMatch1[ "a" ] ) ); - ASSERT( !norOp.matchesSingleElement( notMatch2[ "a" ] ) ); - ASSERT( !norOp.matchesSingleElement( notMatch3[ "a" ] ) ); - ASSERT( norOp.matchesSingleElement( match[ "a" ] ) ); -} -*/ TEST(NorOp, MatchesSingleClause) { BSONObj baseOperand = BSON("$ne" << 5); - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); - ASSERT(eq->init("a", baseOperand["$ne"]).isOK()); - unique_ptr<NotMatchExpression> ne(new NotMatchExpression()); - ASSERT(ne->init(eq.release()).isOK()); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression("a", baseOperand["$ne"])); + unique_ptr<NotMatchExpression> ne(new NotMatchExpression(eq.release())); NorMatchExpression norOp; norOp.add(ne.release()); @@ -507,12 +264,9 @@ TEST(NorOp, MatchesThreeClauses) { BSONObj baseOperand2 = BSON("$lt" << 0); BSONObj baseOperand3 = BSON("b" << 100); - unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression()); - ASSERT(sub1->init("a", baseOperand1["$gt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression()); - ASSERT(sub2->init("a", baseOperand2["$lt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub3(new EqualityMatchExpression()); - ASSERT(sub3->init("b", baseOperand3["b"]).isOK()); + unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression("a", baseOperand1["$gt"])); + unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression("a", baseOperand2["$lt"])); + unique_ptr<ComparisonMatchExpression> sub3(new EqualityMatchExpression("b", baseOperand3["b"])); NorMatchExpression norOp; norOp.add(sub1.release()); @@ -531,10 +285,8 @@ TEST(NorOp, MatchesThreeClauses) { TEST(NorOp, ElemMatchKey) { BSONObj baseOperand1 = BSON("a" << 1); BSONObj baseOperand2 = BSON("b" << 2); - unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression()); - ASSERT(sub1->init("a", baseOperand1["a"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression()); - ASSERT(sub2->init("b", baseOperand2["b"]).isOK()); + unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression("a", baseOperand1["a"])); + unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression("b", baseOperand2["b"])); NorMatchExpression norOp; norOp.add(sub1.release()); @@ -555,10 +307,8 @@ TEST(NorOp, ElemMatchKey) { TEST(NorOp, Equivalent) { BSONObj baseOperand1 = BSON("a" << 1); BSONObj baseOperand2 = BSON("b" << 2); - EqualityMatchExpression sub1; - ASSERT(sub1.init("a", baseOperand1["a"]).isOK()); - EqualityMatchExpression sub2; - ASSERT(sub2.init("b", baseOperand2["b"]).isOK()); + EqualityMatchExpression sub1("a", baseOperand1["a"]); + EqualityMatchExpression sub2("b", baseOperand2["b"]); NorMatchExpression e1; e1.add(sub1.shallowClone().release()); |