mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Add tests to check that the YAML parser supports merge keys
This is useful as it's an optional addition to the YAML spec, and LOOT's masterlists heavily rely on it being supported.
This commit is contained in:
@@ -66,6 +66,12 @@ TEST(ModuloOperator, shouldConformToTheCpp11Standard) {
|
||||
EXPECT_EQ(-2, -9 % -7);
|
||||
}
|
||||
|
||||
TEST(YamlCpp, shouldSupportMergeKeys) {
|
||||
YAML::Node node = YAML::Load("{<<: {a: 1}}");
|
||||
ASSERT_TRUE(node["a"]);
|
||||
EXPECT_EQ(1, node["a"].as<int>());
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Set the locale to get encoding conversions working correctly.
|
||||
std::locale::global(boost::locale::generator().generate(""));
|
||||
|
||||
@@ -142,6 +142,33 @@ TEST_P(MetadataListTest, loadShouldLoadGroups) {
|
||||
groups.find(Group("group2"))->GetAfterGroups());
|
||||
}
|
||||
|
||||
TEST_P(MetadataListTest, loadYamlParsingShouldSupportMergeKeys) {
|
||||
using std::endl;
|
||||
|
||||
boost::filesystem::ofstream out(metadataPath);
|
||||
out << "common:" << endl
|
||||
<< " - &earlier" << endl
|
||||
<< " name: earlier" << endl
|
||||
<< " after:" << endl
|
||||
<< " - earliest" << endl
|
||||
<< "groups:" << endl
|
||||
<< " - name: default" << endl
|
||||
<< " <<: *earlier" << endl;
|
||||
|
||||
out.close();
|
||||
|
||||
MetadataList metadataList;
|
||||
ASSERT_NO_THROW(metadataList.Load(metadataPath));
|
||||
|
||||
auto groups = metadataList.Groups();
|
||||
|
||||
EXPECT_EQ(1, groups.size());
|
||||
|
||||
EXPECT_EQ(1, groups.count(Group("default")));
|
||||
EXPECT_EQ(std::unordered_set<std::string>({ "earliest" }),
|
||||
groups.find(Group("default"))->GetAfterGroups());
|
||||
}
|
||||
|
||||
TEST_P(MetadataListTest, loadShouldThrowIfAnInvalidMetadataFileIsGiven) {
|
||||
MetadataList ml;
|
||||
for (const auto& path : invalidMetadataPaths) {
|
||||
|
||||
Reference in New Issue
Block a user