Skip to content

Commit 5793856

Browse files
committed
cc formats/yaml: add an extra test for key uniqueness check
commit_hash:f4441e49117c977c189630fb55c6ad859be1cb09
1 parent 9a0b7ad commit 5793856

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

universal/src/formats/yaml/serialize_test.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,30 @@ TEST(FormatsYamlDuplicateKeys, VariousScalarsInMapKeys) {
113113
}
114114

115115
TEST(FormatsYamlDuplicateKeys, NonScalarsInMapKeys) {
116-
{
117-
const std::string yaml_string = R"(
118-
[1, 2, 3]: foo
119-
[1, 2, 3]: bar
120-
)";
121-
formats::yaml::Value value;
122-
// This check relies on implementation of FromString. Currently, we do not throw an exception in this case,
123-
// but we could do so in the future. In that case the test should be changed.
124-
// Anyway, we should not hang or crash here.
125-
UEXPECT_NO_THROW(value = formats::yaml::FromString(yaml_string));
126-
EXPECT_EQ(value.GetSize(), 2);
127-
}
116+
const std::string yaml_string = R"(
117+
[1, 2, 3]: foo
118+
[1, 2, 3]: bar
119+
)";
120+
formats::yaml::Value value;
121+
// This check relies on implementation of FromString. Currently, we do not throw an exception in this case,
122+
// but we could do so in the future. In that case the test should be changed.
123+
// Anyway, we should not hang or crash here.
124+
UEXPECT_NO_THROW(value = formats::yaml::FromString(yaml_string));
125+
EXPECT_EQ(value.GetSize(), 2);
126+
}
127+
128+
TEST(FormatsYamlDuplicateKeys, SameKeysInDifferentNestingLevels) {
129+
const std::string yaml_string = R"(
130+
Key1: &values
131+
Key1: &keys
132+
Key1: 1
133+
Key2: 2
134+
Key3: 3
135+
Key2: *keys
136+
Key3: *keys
137+
Key2: *values
138+
)";
139+
UEXPECT_NO_THROW(formats::yaml::FromString(yaml_string));
128140
}
129141

130142
USERVER_NAMESPACE_END

0 commit comments

Comments
 (0)