Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary since you're not using files, right?

30 changes: 30 additions & 0 deletions test/integration/load_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think A and B are actually the same node, so you can just check

ASSERT_TRUE(A.is(B));

or

ASSERT_TRUE(A == B);

(which is the same thing).

std::map<std::string, std::string> 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<std::string>();
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<std::string>(), b.as<std::string>());
// ... and have the values given in the map
EXPECT_EQ(a.as<std::string>(), values[key]);
}
}

#ifdef BOOST_FOREACH
TEST(LoadNodeTest, ForEach) {
Node node = Load("[1, 3, 5, 7]");
Expand Down