summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_expr_test.cpp
diff options
context:
space:
mode:
authorMindaugas Malinauskas <mindaugas.malinauskas@mongodb.com>2020-10-15 12:42:08 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-10-27 14:26:33 +0000
commit1a51c07054bd50917ce49952e5259a4fd8a3ee26 (patch)
treea154194ce6681762e268151c58e0fd17206eef39 /src/mongo/db/matcher/expression_expr_test.cpp
parentb3f249ce671e96b3ec0b9c7406fe828357b63d62 (diff)
downloadmongo-1a51c07054bd50917ce49952e5259a4fd8a3ee26.tar.gz
SERVER-51399 Validation errors for $expr should report result of evaluation, not result after coercion to a boolean
Diffstat (limited to 'src/mongo/db/matcher/expression_expr_test.cpp')
-rw-r--r--src/mongo/db/matcher/expression_expr_test.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_expr_test.cpp b/src/mongo/db/matcher/expression_expr_test.cpp
index e9e2e6eab4b..6f88314a6f5 100644
--- a/src/mongo/db/matcher/expression_expr_test.cpp
+++ b/src/mongo/db/matcher/expression_expr_test.cpp
@@ -29,6 +29,7 @@
#include "mongo/platform/basic.h"
+#include "mongo/base/checked_cast.h"
#include "mongo/bson/json.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_expr.h"
@@ -76,6 +77,10 @@ public:
return _matchExpression->matchesBSON(doc);
}
+ ExprMatchExpression* getExprMatchExpression() {
+ return checked_cast<ExprMatchExpression*>(_matchExpression.get());
+ }
+
private:
const boost::intrusive_ptr<ExpressionContextForTest> _expCtx;
std::unique_ptr<MatchExpression> _matchExpression;
@@ -722,5 +727,13 @@ TEST(ExprMatchTest, OptimizingExprAbsorbsAndOfAnd) {
ASSERT_BSONOBJ_EQ(serialized, expectedSerialization);
}
+TEST_F(ExprMatchTest, ExpressionEvaluationReturnsResultsCorrectly) {
+ createMatcher(fromjson("{$expr: -2}"));
+ BSONMatchableDocument document{BSONObj{}};
+ auto expressionResult = getExprMatchExpression()->evaluateExpression(&document);
+ ASSERT_TRUE(expressionResult.integral());
+ ASSERT_EQUALS(-2, expressionResult.coerceToInt());
+}
+
} // namespace
} // namespace mongo