Exemplo n.º 1
0
TEST(NorOp, 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());

    NorMatchExpression norOp;
    norOp.add(sub1.release());
    norOp.add(sub2.release());
    norOp.add(sub3.release());

    ASSERT(!norOp.matchesBSON(BSON("a" << -1), NULL));
    ASSERT(!norOp.matchesBSON(BSON("a" << 11), NULL));
    ASSERT(norOp.matchesBSON(BSON("a" << 5), NULL));
    ASSERT(!norOp.matchesBSON(BSON("b" << 100), NULL));
    ASSERT(norOp.matchesBSON(BSON("b" << 101), NULL));
    ASSERT(norOp.matchesBSON(BSONObj(), NULL));
    ASSERT(!norOp.matchesBSON(BSON("a" << 11 << "b" << 100), NULL));
}
Exemplo n.º 2
0
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());

    NorMatchExpression norOp;
    norOp.add(sub1.release());
    norOp.add(sub2.release());

    MatchDetails details;
    details.requestElemMatchKey();
    ASSERT(!norOp.matchesBSON(BSON("a" << 1), &details));
    ASSERT(!details.hasElemMatchKey());
    ASSERT(!norOp.matchesBSON(BSON("a" << BSON_ARRAY(1) << "b" << BSON_ARRAY(10)), &details));
    ASSERT(!details.hasElemMatchKey());
    ASSERT(norOp.matchesBSON(BSON("a" << BSON_ARRAY(3) << "b" << BSON_ARRAY(4)), &details));
    // The elem match key feature is not implemented for $nor.
    ASSERT(!details.hasElemMatchKey());
}
Exemplo n.º 3
0
    TEST( NorOp, MatchesSingleClause ) {
        BSONObj baseOperand = BSON( "$ne" << 5 );
        auto_ptr<ComparisonMatchExpression> ne( new ComparisonMatchExpression() );
        ASSERT( ne->init( "a", ComparisonMatchExpression::NE, baseOperand[ "$ne" ] ).isOK() );

        NorMatchExpression norOp;
        norOp.add( ne.release() );

        ASSERT( !norOp.matches( BSON( "a" << 4 ), NULL ) );
        ASSERT( !norOp.matches( BSON( "a" << BSON_ARRAY( 4 << 6 ) ), NULL ) );
        ASSERT( norOp.matches( BSON( "a" << 5 ), NULL ) );
        ASSERT( norOp.matches( BSON( "a" << BSON_ARRAY( 4 << 5 ) ), NULL ) );
    }
Exemplo n.º 4
0
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());

    NorMatchExpression norOp;
    norOp.add(ne.release());

    ASSERT(!norOp.matchesBSON(BSON("a" << 4), NULL));
    ASSERT(!norOp.matchesBSON(BSON("a" << BSON_ARRAY(4 << 6)), NULL));
    ASSERT(norOp.matchesBSON(BSON("a" << 5), NULL));
    ASSERT(norOp.matchesBSON(BSON("a" << BSON_ARRAY(4 << 5)), NULL));
}
Exemplo n.º 5
0
TEST(NorOp, NoClauses) {
    NorMatchExpression norOp;
    ASSERT(norOp.matchesBSON(BSONObj(), NULL));
}