From 3976f17ffd7ee47b4ea0341e362a1e6eca1878ac Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Fri, 6 Mar 2015 09:01:43 -0600 Subject: [PATCH] test assignment over-writes comments, but swapPayload() does not --- src/test_lib_json/main.cpp | 45 ++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 3dff874..5e4c0de 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -1544,17 +1544,44 @@ JSONTEST_FIXTURE(ValueTest, StaticString) { JSONTEST_FIXTURE(ValueTest, CommentBefore) { Json::Value val; // fill val val.setComment("// this comment should appear before", Json::CommentPlacement::commentBefore); - // Configure the Builder, then ... Json::StreamWriterBuilder wbuilder; wbuilder.settings_["commentStyle"] = "All"; - char const expected[] = "// this comment should appear before\nnull"; - std::string result = Json::writeString(wbuilder, val); - JSONTEST_ASSERT_STRING_EQUAL(expected, result); - std::string res2 = val.toStyledString(); - std::string exp2 = "\n"; - exp2 += expected; - exp2 += "\n"; - JSONTEST_ASSERT_STRING_EQUAL(exp2, res2); + { + char const expected[] = "// this comment should appear before\nnull"; + std::string result = Json::writeString(wbuilder, val); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + std::string res2 = val.toStyledString(); + std::string exp2 = "\n"; + exp2 += expected; + exp2 += "\n"; + JSONTEST_ASSERT_STRING_EQUAL(exp2, res2); + } + Json::Value other = "hello"; + val.swapPayload(other); + { + char const expected[] = "// this comment should appear before\n\"hello\""; + std::string result = Json::writeString(wbuilder, val); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + std::string res2 = val.toStyledString(); + std::string exp2 = "\n"; + exp2 += expected; + exp2 += "\n"; + JSONTEST_ASSERT_STRING_EQUAL(exp2, res2); + JSONTEST_ASSERT_STRING_EQUAL("null\n", other.toStyledString()); + } + val = "hello"; + // val.setComment("// this comment should appear before", Json::CommentPlacement::commentBefore); + // Assignment over-writes comments. + { + char const expected[] = "\"hello\""; + std::string result = Json::writeString(wbuilder, val); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + std::string res2 = val.toStyledString(); + std::string exp2 = ""; + exp2 += expected; + exp2 += "\n"; + JSONTEST_ASSERT_STRING_EQUAL(exp2, res2); + } } JSONTEST_FIXTURE(ValueTest, zeroes) {