Skip to content

Commit 80ca11b

Browse files
committed
test commentBefore
for issue open-source-parsers#203
1 parent 2fc08b4 commit 80ca11b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test_lib_json/main.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,22 @@ JSONTEST_FIXTURE(ValueTest, StaticString) {
15411541
}
15421542
}
15431543

1544+
JSONTEST_FIXTURE(ValueTest, CommentBefore) {
1545+
Json::Value val; // fill val
1546+
val.setComment("// this comment should appear before", Json::CommentPlacement::commentBefore);
1547+
// Configure the Builder, then ...
1548+
Json::StreamWriterBuilder wbuilder;
1549+
wbuilder.settings_["commentStyle"] = "All";
1550+
char const expected[] = "// this comment should appear before\nnull";
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+
15441560
JSONTEST_FIXTURE(ValueTest, zeroes) {
15451561
std::string binary("hi", 3); // include trailing 0
15461562
JSONTEST_ASSERT_EQUAL(3, binary.length());
@@ -2239,6 +2255,7 @@ int main(int argc, const char* argv[]) {
22392255
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, offsetAccessors);
22402256
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, typeChecksThrowExceptions);
22412257
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, StaticString);
2258+
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, CommentBefore);
22422259
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroes);
22432260
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroesInKeys);
22442261

0 commit comments

Comments
 (0)