From 1d8542ad327e696bbe1e5dc28f94e13021d63782 Mon Sep 17 00:00:00 2001 From: Ted Lyngmo Date: Wed, 8 Apr 2020 03:08:56 +0200 Subject: [PATCH] Add NodeTest EqualRepresentationAfterMoveAssignment (#816) Add check that a move assigned Node gets the same representation as the moved-from Node had before the move. --- 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";