@@ -1544,17 +1544,44 @@ JSONTEST_FIXTURE(ValueTest, StaticString) {
15441544JSONTEST_FIXTURE (ValueTest, CommentBefore) {
15451545 Json::Value val; // fill val
15461546 val.setComment (" // this comment should appear before" , Json::CommentPlacement::commentBefore);
1547- // Configure the Builder, then ...
15481547 Json::StreamWriterBuilder wbuilder;
15491548 wbuilder.settings_ [" commentStyle" ] = " All" ;
1550- char const expected[] = " // this comment should appear before\n null" ;
1551- std::string result = Json::writeString (wbuilder, val);
1552- JSONTEST_ASSERT_STRING_EQUAL (expected, result);
1553- std::string res2 = val.toStyledString ();
1554- std::string exp2 = " \n " ;
1555- exp2 += expected;
1556- exp2 += " \n " ;
1557- JSONTEST_ASSERT_STRING_EQUAL (exp2, res2);
1549+ {
1550+ char const expected[] = " // this comment should appear before\n null" ;
1551+ std::string result = Json::writeString (wbuilder, val);
1552+ JSONTEST_ASSERT_STRING_EQUAL (expected, result);
1553+ std::string res2 = val.toStyledString ();
1554+ std::string exp2 = " \n " ;
1555+ exp2 += expected;
1556+ exp2 += " \n " ;
1557+ JSONTEST_ASSERT_STRING_EQUAL (exp2, res2);
1558+ }
1559+ Json::Value other = " hello" ;
1560+ val.swapPayload (other);
1561+ {
1562+ char const expected[] = " // this comment should appear before\n\" hello\" " ;
1563+ std::string result = Json::writeString (wbuilder, val);
1564+ JSONTEST_ASSERT_STRING_EQUAL (expected, result);
1565+ std::string res2 = val.toStyledString ();
1566+ std::string exp2 = " \n " ;
1567+ exp2 += expected;
1568+ exp2 += " \n " ;
1569+ JSONTEST_ASSERT_STRING_EQUAL (exp2, res2);
1570+ JSONTEST_ASSERT_STRING_EQUAL (" null\n " , other.toStyledString ());
1571+ }
1572+ val = " hello" ;
1573+ // val.setComment("// this comment should appear before", Json::CommentPlacement::commentBefore);
1574+ // Assignment over-writes comments.
1575+ {
1576+ char const expected[] = " \" hello\" " ;
1577+ std::string result = Json::writeString (wbuilder, val);
1578+ JSONTEST_ASSERT_STRING_EQUAL (expected, result);
1579+ std::string res2 = val.toStyledString ();
1580+ std::string exp2 = " " ;
1581+ exp2 += expected;
1582+ exp2 += " \n " ;
1583+ JSONTEST_ASSERT_STRING_EQUAL (exp2, res2);
1584+ }
15581585}
15591586
15601587JSONTEST_FIXTURE (ValueTest, zeroes) {
0 commit comments