Add NodeTest EqualRepresentationAfterMoveAssignment (#816)

Add check that a move assigned Node gets the same representation as the
moved-from Node had before the move.
This commit is contained in:
Ted Lyngmo
2020-04-08 03:08:56 +02:00
committed by GitHub
parent 6f7ead5171
commit 1d8542ad32

View File

@@ -9,6 +9,8 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <sstream>
using ::testing::AnyOf; using ::testing::AnyOf;
using ::testing::Eq; using ::testing::Eq;
@@ -135,6 +137,20 @@ TEST(NodeTest, NodeAssignment) {
EXPECT_EQ(node1[3], node2[3]); 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<std::string>());
EXPECT_EQ(ss1.str(), ss2.str());
}
TEST(NodeTest, MapElementRemoval) { TEST(NodeTest, MapElementRemoval) {
Node node; Node node;
node["foo"] = "bar"; node["foo"] = "bar";