diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2022-01-27 21:21:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-27 21:48:12 +0000 |
commit | 5cd04445c078f75d734d71d7b61a0a6fb63b960d (patch) | |
tree | 26092da998f315de409ce9bc1c19cbcb10b76db5 /src/mongo/idl/idl_test.cpp | |
parent | 59e5b09e6840c5d00fbc961f812d66a00f823938 (diff) | |
download | mongo-5cd04445c078f75d734d71d7b61a0a6fb63b960d.tar.gz |
SERVER-63024 Support default values for variants in IDL
Diffstat (limited to 'src/mongo/idl/idl_test.cpp')
-rw-r--r-- | src/mongo/idl/idl_test.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp index 4a1d30f422c..37133cb7566 100644 --- a/src/mongo/idl/idl_test.cpp +++ b/src/mongo/idl/idl_test.cpp @@ -1190,6 +1190,20 @@ TEST(IDLFieldTests, TestStrictDuplicateIgnoredFields) { ASSERT_EQUALS(testStruct.get##field_name(), new_value); \ } +#define TEST_DEFAULT_VALUES_VARIANT(field_name, default_type, default_value, new_type, new_value) \ + { \ + auto testDoc = BSONObj(); \ + auto testStruct = Default_values::parse(ctxt, testDoc); \ + ASSERT_TRUE(stdx::holds_alternative<default_type>(testStruct.get##field_name())); \ + ASSERT_EQUALS(stdx::get<default_type>(testStruct.get##field_name()), default_value); \ + } \ + { \ + auto testDoc = BSON(#field_name << new_value); \ + auto testStruct = Default_values::parse(ctxt, testDoc); \ + ASSERT_TRUE(stdx::holds_alternative<new_type>(testStruct.get##field_name())); \ + ASSERT_EQUALS(stdx::get<new_type>(testStruct.get##field_name()), new_value); \ + } + // Mixed: struct strict, and ignored field works TEST(IDLFieldTests, TestDefaultFields) { IDLParserErrorContext ctxt("root"); @@ -1199,6 +1213,8 @@ TEST(IDLFieldTests, TestDefaultFields) { TEST_DEFAULT_VALUES(V_long, 423, 4LL); TEST_DEFAULT_VALUES(V_double, 3.14159, 2.8); TEST_DEFAULT_VALUES(V_bool, true, false); + TEST_DEFAULT_VALUES_VARIANT(V_variant_string, std::string, "a default", int, 42); + TEST_DEFAULT_VALUES_VARIANT(V_variant_int, int, 42, std::string, "a default"); } // Positive: struct strict, and optional field works |