mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-12 18:10:27 +01:00
test assignment over-writes comments, but swapPayload() does not
This commit is contained in:
parent
80ca11bb41
commit
3976f17ffd
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user