Skip to content

Commit 15feb79

Browse files
authored
Guarantee backwards compatibility in SchemaConfig (#1994)
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent c71f3dc commit 15feb79

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/schemaconfig/schemaconfig_from_json_test.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,28 @@ TEST(SchemaConfig_from_json, invalid_14) {
288288
"The values in the resolve object must represent valid URIs",
289289
"/resolve/foo");
290290
}
291+
292+
// For backwards compatibility when we add new fields
293+
TEST(SchemaConfig_from_json, unknown_field_ignored) {
294+
const auto input{sourcemeta::core::parse_json(R"JSON({
295+
"title": "Test Project",
296+
"unknown": 1
297+
})JSON")};
298+
299+
const auto manifest{
300+
sourcemeta::core::SchemaConfig::from_json(input, TEST_DIRECTORY)};
301+
302+
EXPECT_TRUE(manifest.title.has_value());
303+
EXPECT_EQ(manifest.title.value(), "Test Project");
304+
EXPECT_FALSE(manifest.description.has_value());
305+
EXPECT_FALSE(manifest.email.has_value());
306+
EXPECT_FALSE(manifest.github.has_value());
307+
EXPECT_FALSE(manifest.website.has_value());
308+
EXPECT_EQ(manifest.absolute_path, TEST_DIRECTORY);
309+
EXPECT_EQ(
310+
manifest.base,
311+
sourcemeta::core::URI::from_path(manifest.absolute_path).recompose());
312+
EXPECT_FALSE(manifest.default_dialect.has_value());
313+
EXPECT_EQ(manifest.resolve.size(), 0);
314+
EXPECT_EQ(manifest.extra.size(), 0);
315+
}

0 commit comments

Comments
 (0)