summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_leaf_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/matcher/expression_leaf_test.cpp')
-rw-r--r--src/mongo/db/matcher/expression_leaf_test.cpp66
1 files changed, 40 insertions, 26 deletions
diff --git a/src/mongo/db/matcher/expression_leaf_test.cpp b/src/mongo/db/matcher/expression_leaf_test.cpp
index 293ed59c85c..1c3f7795a95 100644
--- a/src/mongo/db/matcher/expression_leaf_test.cpp
+++ b/src/mongo/db/matcher/expression_leaf_test.cpp
@@ -1501,7 +1501,8 @@ TEST(InMatchExpression, MatchesElementSingle) {
BSONObj match = BSON("a" << 1);
BSONObj notMatch = BSON("a" << 2);
InMatchExpression in;
- in.addEquality(operand.firstElement());
+ std::vector<BSONElement> equalities{operand.firstElement()};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(in.matchesSingleElement(match["a"]));
ASSERT(!in.matchesSingleElement(notMatch["a"]));
}
@@ -1519,10 +1520,8 @@ TEST(InMatchExpression, MatchesEmpty) {
TEST(InMatchExpression, MatchesElementMultiple) {
BSONObj operand = BSON_ARRAY(1 << "r" << true << 1);
InMatchExpression in;
- in.addEquality(operand[0]);
- in.addEquality(operand[1]);
- in.addEquality(operand[2]);
- in.addEquality(operand[3]);
+ std::vector<BSONElement> equalities{operand[0], operand[1], operand[2], operand[3]};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
BSONObj matchFirst = BSON("a" << 1);
BSONObj matchSecond = BSON("a"
@@ -1540,7 +1539,8 @@ TEST(InMatchExpression, MatchesScalar) {
BSONObj operand = BSON_ARRAY(5);
InMatchExpression in;
in.init("a");
- in.addEquality(operand.firstElement());
+ std::vector<BSONElement> equalities{operand.firstElement()};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(in.matchesBSON(BSON("a" << 5.0), NULL));
ASSERT(!in.matchesBSON(BSON("a" << 4), NULL));
@@ -1550,7 +1550,8 @@ TEST(InMatchExpression, MatchesArrayValue) {
BSONObj operand = BSON_ARRAY(5);
InMatchExpression in;
in.init("a");
- in.addEquality(operand.firstElement());
+ std::vector<BSONElement> equalities{operand.firstElement()};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(in.matchesBSON(BSON("a" << BSON_ARRAY(5.0 << 6)), NULL));
ASSERT(!in.matchesBSON(BSON("a" << BSON_ARRAY(6 << 7)), NULL));
@@ -1562,7 +1563,8 @@ TEST(InMatchExpression, MatchesNull) {
InMatchExpression in;
in.init("a");
- in.addEquality(operand.firstElement());
+ std::vector<BSONElement> equalities{operand.firstElement()};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(in.matchesBSON(BSONObj(), NULL));
ASSERT(in.matchesBSON(BSON("a" << BSONNULL), NULL));
@@ -1576,15 +1578,16 @@ TEST(InMatchExpression, MatchesUndefined) {
InMatchExpression in;
in.init("a");
- Status s = in.addEquality(operand.firstElement());
- ASSERT_NOT_OK(s);
+ std::vector<BSONElement> equalities{operand.firstElement()};
+ ASSERT_NOT_OK(in.setEqualities(std::move(equalities)));
}
TEST(InMatchExpression, MatchesMinKey) {
BSONObj operand = BSON_ARRAY(MinKey);
InMatchExpression in;
in.init("a");
- in.addEquality(operand.firstElement());
+ std::vector<BSONElement> equalities{operand.firstElement()};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(in.matchesBSON(BSON("a" << MinKey), NULL));
ASSERT(!in.matchesBSON(BSON("a" << MaxKey), NULL));
@@ -1595,7 +1598,8 @@ TEST(InMatchExpression, MatchesMaxKey) {
BSONObj operand = BSON_ARRAY(MaxKey);
InMatchExpression in;
in.init("a");
- in.addEquality(operand.firstElement());
+ std::vector<BSONElement> equalities{operand.firstElement()};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(in.matchesBSON(BSON("a" << MaxKey), NULL));
ASSERT(!in.matchesBSON(BSON("a" << MinKey), NULL));
@@ -1606,9 +1610,8 @@ TEST(InMatchExpression, MatchesFullArray) {
BSONObj operand = BSON_ARRAY(BSON_ARRAY(1 << 2) << 4 << 5);
InMatchExpression in;
in.init("a");
- in.addEquality(operand[0]);
- in.addEquality(operand[1]);
- in.addEquality(operand[2]);
+ std::vector<BSONElement> equalities{operand[0], operand[1], operand[2]};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(in.matchesBSON(BSON("a" << BSON_ARRAY(1 << 2)), NULL));
ASSERT(!in.matchesBSON(BSON("a" << BSON_ARRAY(1 << 2 << 3)), NULL));
@@ -1620,8 +1623,8 @@ TEST(InMatchExpression, ElemMatchKey) {
BSONObj operand = BSON_ARRAY(5 << 2);
InMatchExpression in;
in.init("a");
- in.addEquality(operand[0]);
- in.addEquality(operand[1]);
+ std::vector<BSONElement> equalities{operand[0], operand[1]};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
MatchDetails details;
details.requestElemMatchKey();
@@ -1639,7 +1642,8 @@ TEST(InMatchExpression, InMatchExpressionsWithDifferentNumbersOfElementsAreUnequ
<< "string");
InMatchExpression eq1;
InMatchExpression eq2;
- eq1.addEquality(obj.firstElement());
+ std::vector<BSONElement> equalities{obj.firstElement()};
+ ASSERT_OK(eq1.setEqualities(std::move(equalities)));
ASSERT(!eq1.equivalent(&eq2));
}
@@ -1675,8 +1679,12 @@ TEST(InMatchExpression, InMatchExpressionsWithCollationEquivalentElementsAreEqua
InMatchExpression eq2;
eq2.setCollator(&collator2);
- eq1.addEquality(obj1.firstElement());
- eq2.addEquality(obj2.firstElement());
+ std::vector<BSONElement> equalities1{obj1.firstElement()};
+ ASSERT_OK(eq1.setEqualities(std::move(equalities1)));
+
+ std::vector<BSONElement> equalities2{obj2.firstElement()};
+ ASSERT_OK(eq2.setEqualities(std::move(equalities2)));
+
ASSERT(eq1.equivalent(&eq2));
}
@@ -1692,8 +1700,12 @@ TEST(InMatchExpression, InMatchExpressionsWithCollationNonEquivalentElementsAreU
InMatchExpression eq2;
eq2.setCollator(&collator2);
- eq1.addEquality(obj1.firstElement());
- eq2.addEquality(obj2.firstElement());
+ std::vector<BSONElement> equalities1{obj1.firstElement()};
+ ASSERT_OK(eq1.setEqualities(std::move(equalities1)));
+
+ std::vector<BSONElement> equalities2{obj2.firstElement()};
+ ASSERT_OK(eq2.setEqualities(std::move(equalities2)));
+
ASSERT(!eq1.equivalent(&eq2));
}
@@ -1702,7 +1714,8 @@ TEST(InMatchExpression, StringMatchingWithNullCollatorUsesBinaryComparison) {
BSONObj notMatch = BSON("a"
<< "string2");
InMatchExpression in;
- in.addEquality(operand.firstElement());
+ std::vector<BSONElement> equalities{operand.firstElement()};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(!in.matchesSingleElement(notMatch["a"]));
}
@@ -1713,7 +1726,8 @@ TEST(InMatchExpression, StringMatchingRespectsCollation) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
InMatchExpression in;
in.setCollator(&collator);
- in.addEquality(operand.firstElement());
+ std::vector<BSONElement> equalities{operand.firstElement()};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(in.matchesSingleElement(match["a"]));
}
@@ -1726,8 +1740,8 @@ TEST(InMatchExpression, ChangingCollationAfterAddingEqualitiesPreservesEqualitie
CollatorInterfaceMock collatorReverseString(CollatorInterfaceMock::MockType::kReverseString);
InMatchExpression in;
in.setCollator(&collatorAlwaysEqual);
- in.addEquality(obj1.firstElement());
- in.addEquality(obj2.firstElement());
+ std::vector<BSONElement> equalities{obj1.firstElement(), obj2.firstElement()};
+ ASSERT_OK(in.setEqualities(std::move(equalities)));
ASSERT(in.getEqualities().size() == 1);
in.setCollator(&collatorReverseString);
ASSERT(in.getEqualities().size() == 2);