From 1eb1301c7cd4ef9c95abd526a9c8ba157e48b60a Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sat, 17 Mar 2018 14:48:10 +0100 Subject: [PATCH 1/2] unittest for accessing aliases --- test/integration/load_node_test.cpp | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/integration/load_node_test.cpp b/test/integration/load_node_test.cpp index 02bb8fe58..e880e4be6 100644 --- a/test/integration/load_node_test.cpp +++ b/test/integration/load_node_test.cpp @@ -78,6 +78,36 @@ TEST(LoadNodeTest, IterateMap) { EXPECT_EQ(3, i); } +TEST(LoadNodeTest, AliasAccess) { + const Node doc = Load("{A: &DEFAULT {str: string, int: 42, float: 3.1415}, B: *DEFAULT}"); + const Node& A = doc["A"]; + const Node& B = doc["B"]; + + // A and B have the same content + ASSERT_TRUE(A); + ASSERT_TRUE(A.IsMap()); + ASSERT_TRUE(B); + ASSERT_TRUE(B.IsMap()); + + // A and B have the same content + std::map values = {{"str", "string"}, {"float", "3.1415"}, {"int", "42"}}; + for (YAML::const_iterator it = A.begin(); it != A.end(); ++it) { + const std::string& key = it->first.as(); + SCOPED_TRACE("key " + key); + const Node& a = A[key]; + const Node& b = B[key]; + EXPECT_TRUE(a); + EXPECT_TRUE(b); + EXPECT_TRUE(a.IsScalar()); + EXPECT_TRUE(b.IsScalar()); + + // a and b should be identical + EXPECT_EQ(a.as(), b.as()); + // ... and have the values given in the map + EXPECT_EQ(a.as(), values[key]); + } +} + #ifdef BOOST_FOREACH TEST(LoadNodeTest, ForEach) { Node node = Load("[1, 3, 5, 7]"); From 67bd61531da940b1c50089073ad3bf81e487956e Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sat, 10 Mar 2018 21:22:30 +0100 Subject: [PATCH 2/2] start unittest from well-defined working dir --- test/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3633da578..65cfaf98d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,4 +41,5 @@ set_target_properties(run-tests PROPERTIES ) target_link_libraries(run-tests yaml-cpp gmock) -add_test(yaml-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/run-tests) +add_test(NAME yaml-test COMMAND run-tests + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})