diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 5a9b4175..985c898d 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -43,7 +43,6 @@ set(LIBLOOT_SRC_TESTS_INTERNALS_H_FILES "${CMAKE_SOURCE_DIR}/src/tests/api/internals/game/load_order_handler_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/crc_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/text_test.h" - "${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/yaml_set_helpers_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/condition_evaluator_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/conditional_metadata_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/file_test.h" diff --git a/src/tests/api/internals/helpers/yaml_set_helpers_test.h b/src/tests/api/internals/helpers/yaml_set_helpers_test.h deleted file mode 100644 index c4320404..00000000 --- a/src/tests/api/internals/helpers/yaml_set_helpers_test.h +++ /dev/null @@ -1,142 +0,0 @@ -/* LOOT - -A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and -Fallout: New Vegas. - -Copyright (C) 2014-2016 WrinklyNinja - -This file is part of LOOT. - -LOOT is free software: you can redistribute -it and/or modify it under the terms of the GNU General Public License -as published by the Free Software Foundation, either version 3 of -the License, or (at your option) any later version. - -LOOT is distributed in the hope that it will -be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with LOOT. If not, see -. -*/ - -#ifndef LOOT_TESTS_API_INTERNALS_HELPERS_YAML_SET_HELPERS_TEST -#define LOOT_TESTS_API_INTERNALS_HELPERS_YAML_SET_HELPERS_TEST - -#include - -#include "api/metadata/yaml/set.h" - -namespace loot { -namespace test { -TEST(set, encodingAsYamlShouldStoreAllValuesInSetOrder) { - std::set stringSet({"a", "b", "c"}); - YAML::Node node; - node = stringSet; - - EXPECT_TRUE(node.IsSequence()); - ASSERT_EQ(3, node.size()); - EXPECT_EQ("a", node[0].as()); - EXPECT_EQ("b", node[1].as()); - EXPECT_EQ("c", node[2].as()); -} - -TEST(set, decodingFromAYamlListShouldStoreValuesCorrectly) { - YAML::Node node = YAML::Load("[a, b, c]"); - std::set stringSet = node.as>(); - std::set expectedStringSet({"a", "b", "c"}); - - EXPECT_EQ(expectedStringSet, stringSet); -} - -TEST(set, decodingFromAYamlListThatContainsDuplicateElementsShouldThrow) { - YAML::Node node = YAML::Load("[a, b, c, c]"); - EXPECT_THROW(node.as>(), YAML::RepresentationException); -} - -TEST(set, emittingAsYamlShouldOutputAYamlListContainingAllValues) { - std::set stringSet({"a", "b", "c"}); - YAML::Emitter e1; - e1 << stringSet; - - YAML::Node node = YAML::Load(e1.c_str()); - EXPECT_TRUE(node.IsSequence()); - ASSERT_EQ(3, node.size()); - EXPECT_EQ("a", node[0].as()); - EXPECT_EQ("b", node[1].as()); - EXPECT_EQ("c", node[2].as()); -} - -class unordered_set : public ::testing::Test { -protected: - static bool nodeContains(const YAML::Node& node, const std::string& value) { - for (const auto& element : node) { - if (element.as() == value) - return true; - } - return false; - } - - static bool isSequenceOf(const std::string& sequence, - const std::vector& values) { - std::set sortedValues(std::begin(values), std::end(values)); - - std::set found; - size_t i = 2; - while (i < sequence.length()) { - size_t separatorPos = sequence.find("\n- ", i); - found.insert(sequence.substr(i, separatorPos)); - } - - return sortedValues == found; - } -}; - -TEST_F(unordered_set, encodingAsYamlShouldStoreAllValuesInUndefinedOrder) { - std::unordered_set stringSet({"a", "b", "c"}); - YAML::Node node; - node = stringSet; - - EXPECT_TRUE(node.IsSequence()); - ASSERT_EQ(3, node.size()); - EXPECT_PRED2(&nodeContains, node, "a"); - EXPECT_PRED2(&nodeContains, node, "b"); - EXPECT_PRED2(&nodeContains, node, "c"); -} - -TEST_F(unordered_set, decodingFromAYamlListShouldStoreValuesCorrectly) { - YAML::Node node = YAML::Load("[a, b, c]"); - std::unordered_set stringSet = - node.as>(); - - EXPECT_EQ(1, stringSet.count("a")); - EXPECT_EQ(1, stringSet.count("b")); - EXPECT_EQ(1, stringSet.count("c")); -} - -TEST_F(unordered_set, - decodingFromAYamlListThatContainsDuplicateElementsShouldThrow) { - YAML::Node node = YAML::Load("[a, b, c, c]"); - - EXPECT_THROW(node.as>(), - YAML::RepresentationException); -} - -TEST_F(unordered_set, emittingAsYamlShouldOutputAYamlListContainingAllValues) { - std::unordered_set stringSet({"a", "b", "c"}); - YAML::Emitter e1; - e1 << stringSet; - - YAML::Node node = YAML::Load(e1.c_str()); - EXPECT_TRUE(node.IsSequence()); - ASSERT_EQ(3, node.size()); - EXPECT_PRED2(&nodeContains, node, "a"); - EXPECT_PRED2(&nodeContains, node, "b"); - EXPECT_PRED2(&nodeContains, node, "c"); -} -} -} - -#endif diff --git a/src/tests/api/internals/main.cpp b/src/tests/api/internals/main.cpp index ea14ba7b..8e0cdc71 100644 --- a/src/tests/api/internals/main.cpp +++ b/src/tests/api/internals/main.cpp @@ -28,7 +28,6 @@ #include "tests/api/internals/game/load_order_handler_test.h" #include "tests/api/internals/helpers/crc_test.h" #include "tests/api/internals/helpers/text_test.h" -#include "tests/api/internals/helpers/yaml_set_helpers_test.h" #include "tests/api/internals/metadata/condition_evaluator_test.h" #include "tests/api/internals/metadata/conditional_metadata_test.h" #include "tests/api/internals/metadata/file_test.h"