mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-05-17 11:30:13 +02: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) {
|
JSONTEST_FIXTURE(ValueTest, CommentBefore) {
|
||||||
Json::Value val; // fill val
|
Json::Value val; // fill val
|
||||||
val.setComment("// this comment should appear before", Json::CommentPlacement::commentBefore);
|
val.setComment("// this comment should appear before", Json::CommentPlacement::commentBefore);
|
||||||
// Configure the Builder, then ...
|
|
||||||
Json::StreamWriterBuilder wbuilder;
|
Json::StreamWriterBuilder wbuilder;
|
||||||
wbuilder.settings_["commentStyle"] = "All";
|
wbuilder.settings_["commentStyle"] = "All";
|
||||||
char const expected[] = "// this comment should appear before\nnull";
|
{
|
||||||
std::string result = Json::writeString(wbuilder, val);
|
char const expected[] = "// this comment should appear before\nnull";
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
std::string result = Json::writeString(wbuilder, val);
|
||||||
std::string res2 = val.toStyledString();
|
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||||
std::string exp2 = "\n";
|
std::string res2 = val.toStyledString();
|
||||||
exp2 += expected;
|
std::string exp2 = "\n";
|
||||||
exp2 += "\n";
|
exp2 += expected;
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(exp2, res2);
|
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) {
|
JSONTEST_FIXTURE(ValueTest, zeroes) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user