add tests for mandatory key validations considering super tags

This commit is contained in:
Rafael Fillipe Silva 2023-12-20 01:11:27 -03:00 committed by Pentarctagon
parent c421d7e8be
commit 0f78777dee
7 changed files with 143 additions and 0 deletions

View file

@ -268,3 +268,6 @@ test_schema_validator/test_super_cycle_only_if_used
test_schema_validator/test_super_cycle_crashes_on_unknown_key
test_schema_validator/test_super_missing
test_schema_validator/test_super_missing_only_if_used
test_schema_validator/test_super_mandatory
test_schema_validator/test_super_mandatory_missing
test_schema_validator/test_super_cycle_mandatory

View file

@ -153,4 +153,71 @@ BOOST_AUTO_TEST_CASE( test_super_missing_only_if_used )
BOOST_CHECK_NO_THROW(read(result, *stream, &validator));
}
BOOST_AUTO_TEST_CASE( test_super_mandatory )
{
constexpr auto schema_path = "src/tests/wml/schema/test_schema_validator/test_schema_super_mandatory_missing.cfg";
constexpr auto config_path = "src/tests/wml/schema/test_schema_validator/test_super_mandatory.cfg";
auto validator = schema_validation::schema_validator(schema_path, false);
validator.set_create_exceptions(true);
preproc_map defines_map;
defines_map["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str());
defines_map["SCHEMA_VALIDATION"] = preproc_define();
auto stream = preprocess_file(config_path, &defines_map);
config result;
BOOST_CHECK_NO_THROW(read(result, *stream, &validator));
}
BOOST_AUTO_TEST_CASE( test_super_mandatory_missing )
{
constexpr auto schema_path = "src/tests/wml/schema/test_schema_validator/test_schema_super_mandatory_missing.cfg";
constexpr auto config_path = "src/tests/wml/schema/test_schema_validator/test_super_mandatory_missing.cfg";
auto validator = schema_validation::schema_validator(schema_path, false);
validator.set_create_exceptions(true);
preproc_map defines_map;
defines_map["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str());
defines_map["SCHEMA_VALIDATION"] = preproc_define();
auto stream = preprocess_file(config_path, &defines_map);
config result;
BOOST_CHECK_EXCEPTION(
read(result, *stream, &validator),
wml_exception,
[] (const wml_exception& e) {
return boost::algorithm::contains(
e.dev_message,
"Missing key 'id=' in tag [campaign]"
);
}
);
}
BOOST_AUTO_TEST_CASE( test_super_cycle_mandatory )
{
constexpr auto schema_path = "src/tests/wml/schema/test_schema_validator/test_schema_super_cycle_mandatory.cfg";
constexpr auto config_path = "src/tests/wml/schema/test_schema_validator/test_super_cycle_mandatory.cfg";
auto validator = schema_validation::schema_validator(schema_path, false);
validator.set_create_exceptions(true);
preproc_map defines_map;
defines_map["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str());
defines_map["SCHEMA_VALIDATION"] = preproc_define();
auto stream = preprocess_file(config_path, &defines_map);
config result;
BOOST_CHECK_NO_THROW(read(result, *stream, &validator));
}
BOOST_AUTO_TEST_SUITE_END()

View file

@ -0,0 +1,32 @@
[wml_schema]
[type]
name=id
value="[a-zA-Z0-9_~$]+"
[/type]
[tag]
name="root"
[tag]
name="main"
[tag]
name="first"
super="second"
[/tag]
[/tag]
[tag]
name="other"
[tag]
name="second"
super="main/first"
[key]
name=id
type=id
mandatory=true
[/key]
[/tag]
[/tag]
[tag]
name="second"
super="other/second"
[/tag]
[/tag]
[/wml_schema]

View file

@ -0,0 +1,29 @@
# https://github.com/wesnoth/wesnoth/issues/7897
[wml_schema]
[type]
name=id
value="[a-zA-Z0-9_~$]+"
[/type]
[tag]
name="root"
min=1
[tag]
name="virtual~super"
max=0
[key]
name=id
type=id
mandatory=true
[/key]
[/tag]
[tag]
name="mytag"
min=1
[tag]
name="campaign"
max=infinite
super="virtual~super"
[/tag]
[/tag]
[/tag]
[/wml_schema]

View file

@ -0,0 +1,3 @@
[second]
id=id_1
[/second]

View file

@ -0,0 +1,5 @@
[mytag]
[campaign]
id=id_1
[/campaign]
[/mytag]

View file

@ -0,0 +1,4 @@
[mytag]
[campaign]
[/campaign]
[/mytag]