From 634b83f56be69f297ada24b1cdc30b9b756f166a Mon Sep 17 00:00:00 2001 From: Ted Lyngmo Date: Mon, 10 Feb 2020 10:31:10 +0100 Subject: [PATCH] Add NodeTest EqualRepresentationAfterMoveAssignment Add check that a move assigned Node gets the same representation as the moved-from Node had before the move. Signed-off-by: Ted Lyngmo --- test/node/node_test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/node/node_test.cpp b/test/node/node_test.cpp index 4b0e236..f6106bd 100644 --- a/test/node/node_test.cpp +++ b/test/node/node_test.cpp @@ -9,6 +9,8 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#include + using ::testing::AnyOf; using ::testing::Eq; @@ -135,6 +137,20 @@ TEST(NodeTest, NodeAssignment) { EXPECT_EQ(node1[3], node2[3]); } +TEST(NodeTest, EqualRepresentationAfterMoveAssignment) { + Node node1; + Node node2; + std::ostringstream ss1, ss2; + node1["foo"] = "bar"; + ss1 << node1; + node2["hello"] = "world"; + node2 = std::move(node1); + ss2 << node2; + EXPECT_FALSE(node2["hello"]); + EXPECT_EQ("bar", node2["foo"].as()); + EXPECT_EQ(ss1.str(), ss2.str()); +} + TEST(NodeTest, MapElementRemoval) { Node node; node["foo"] = "bar";