summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/query_shape_test.cpp
diff options
context:
space:
mode:
authorDavis Haupt <davis.haupt@mongodb.com>2023-04-14 14:52:08 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-14 16:38:07 +0000
commit2e2d748fe01758dfd5e112c7b96a2d56a2fa8b51 (patch)
tree8479cfe25a9c2e39655e40bf6f8eda6f5bd3f541 /src/mongo/db/query/query_shape_test.cpp
parent5e8b3e0a2da9129602c5a86774d6392dd6f2563e (diff)
downloadmongo-2e2d748fe01758dfd5e112c7b96a2d56a2fa8b51.tar.gz
SERVER-75110 Support SerializationOptions in IDL generated serializers
Diffstat (limited to 'src/mongo/db/query/query_shape_test.cpp')
-rw-r--r--src/mongo/db/query/query_shape_test.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/mongo/db/query/query_shape_test.cpp b/src/mongo/db/query/query_shape_test.cpp
index e15d5f8b485..ba87fe8ba74 100644
--- a/src/mongo/db/query/query_shape_test.cpp
+++ b/src/mongo/db/query/query_shape_test.cpp
@@ -34,6 +34,8 @@
#include "mongo/db/matcher/parsed_match_expression_for_test.h"
#include "mongo/db/pipeline/expression_context_for_test.h"
#include "mongo/db/query/query_shape.h"
+#include "mongo/db/query/query_shape_test_gen.h"
+#include "mongo/unittest/bson_test_util.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
@@ -519,4 +521,130 @@ TEST(QueryPredicateShape, OptimizedExprPredicates) {
queryShapeForOptimizedExprExpression("{$expr: {$gte: ['$a', 2]}}"));
}
+TEST(QueryShapeIDL, ShapifyIDLStruct) {
+ SerializationOptions options;
+ options.redactIdentifiers = true;
+ options.identifierRedactionPolicy = [](StringData s) -> std::string {
+ return str::stream() << "HASH<" << s << ">";
+ };
+ options.replacementForLiteralArgs = "?"_sd;
+
+ auto nested = NestedStruct("value",
+ ExampleEnumEnum::Value1,
+ 1337,
+ "hello",
+ {1, 2, 3, 4},
+ "field.path",
+ {"field.path.1", "fieldpath2"});
+ ASSERT_BSONOBJ_EQ_AUTO( // NOLINT
+ R"({
+ "stringField": "value",
+ "enumField": "EnumValue1",
+ "stringIntVariant": 1337,
+ "stringIntVariantEnum": "hello",
+ "arrayOfInts": [
+ 1,
+ 2,
+ 3,
+ 4
+ ],
+ "fieldpath": "field.path",
+ "fieldpathList": [
+ "field.path.1",
+ "fieldpath2"
+ ]
+ })",
+ nested.toBSON());
+
+ ASSERT_BSONOBJ_EQ_AUTO( // NOLINT
+ R"({
+ "stringField": "?",
+ "enumField": "EnumValue1",
+ "stringIntVariant": "?",
+ "stringIntVariantEnum": "hello",
+ "arrayOfInts": "?",
+ "fieldpath": "HASH<field>.HASH<path>",
+ "fieldpathList": [
+ "HASH<field>.HASH<path>.HASH<1>",
+ "HASH<fieldpath2>"
+ ]
+ })",
+ nested.toBSON(options));
+
+
+ auto parent = ParentStruct(nested, nested);
+ ASSERT_BSONOBJ_EQ_AUTO( // NOLINT
+ R"({
+ "nested_shape": {
+ "stringField": "value",
+ "enumField": "EnumValue1",
+ "stringIntVariant": 1337,
+ "stringIntVariantEnum": "hello",
+ "arrayOfInts": [
+ 1,
+ 2,
+ 3,
+ 4
+ ],
+ "fieldpath": "field.path",
+ "fieldpathList": [
+ "field.path.1",
+ "fieldpath2"
+ ]
+ },
+ "nested_no_shape": {
+ "stringField": "value",
+ "enumField": "EnumValue1",
+ "stringIntVariant": 1337,
+ "stringIntVariantEnum": "hello",
+ "arrayOfInts": [
+ 1,
+ 2,
+ 3,
+ 4
+ ],
+ "fieldpath": "field.path",
+ "fieldpathList": [
+ "field.path.1",
+ "fieldpath2"
+ ]
+ }
+ })",
+ parent.toBSON());
+
+ ASSERT_BSONOBJ_EQ_AUTO( // NOLINT
+ R"({
+ "nested_shape": {
+ "stringField": "?",
+ "enumField": "EnumValue1",
+ "stringIntVariant": "?",
+ "stringIntVariantEnum": "hello",
+ "arrayOfInts": "?",
+ "fieldpath": "HASH<field>.HASH<path>",
+ "fieldpathList": [
+ "HASH<field>.HASH<path>.HASH<1>",
+ "HASH<fieldpath2>"
+ ]
+ },
+ "nested_no_shape": {
+ "stringField": "value",
+ "enumField": "EnumValue1",
+ "stringIntVariant": 1337,
+ "stringIntVariantEnum": "hello",
+ "arrayOfInts": [
+ 1,
+ 2,
+ 3,
+ 4
+ ],
+ "fieldpath": "field.path",
+ "fieldpathList": [
+ "field.path.1",
+ "fieldpath2"
+ ]
+ }
+ })",
+ parent.toBSON(options));
+}
+
} // namespace mongo