mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-10-28 11:31:57 +01:00
PrettyWriter formatting options.
This change adds PrettyWriter::SetFormatOptions with a corresponding bitfield enum PrettyFormatOptions. This allows options affecting the format of the PrettyWriter to be set. The first option to be provided is kFormatSingleLineArray, which instructs the PrettyWriter to write arrays on a single line, rather than breaking them up onto a line per element.
This commit is contained in:
@@ -39,6 +39,19 @@ static const char kPrettyJson[] =
|
||||
" \"i64\": -1234567890123456789\n"
|
||||
"}";
|
||||
|
||||
static const char kPrettyJson_FormatOptions_SLA[] =
|
||||
"{\n"
|
||||
" \"hello\": \"world\",\n"
|
||||
" \"t\": true,\n"
|
||||
" \"f\": false,\n"
|
||||
" \"n\": null,\n"
|
||||
" \"i\": 123,\n"
|
||||
" \"pi\": 3.1416,\n"
|
||||
" \"a\": [1, 2, 3, -1],\n"
|
||||
" \"u64\": 1234567890123456789,\n"
|
||||
" \"i64\": -1234567890123456789\n"
|
||||
"}";
|
||||
|
||||
TEST(PrettyWriter, Basic) {
|
||||
StringBuffer buffer;
|
||||
PrettyWriter<StringBuffer> writer(buffer);
|
||||
@@ -48,6 +61,16 @@ TEST(PrettyWriter, Basic) {
|
||||
EXPECT_STREQ(kPrettyJson, buffer.GetString());
|
||||
}
|
||||
|
||||
TEST(PrettyWriter, FormatOptions) {
|
||||
StringBuffer buffer;
|
||||
PrettyWriter<StringBuffer> writer(buffer);
|
||||
writer.SetFormatOptions(kFormatSingleLineArray);
|
||||
Reader reader;
|
||||
StringStream s(kJson);
|
||||
reader.Parse(s, writer);
|
||||
EXPECT_STREQ(kPrettyJson_FormatOptions_SLA, buffer.GetString());
|
||||
}
|
||||
|
||||
TEST(PrettyWriter, SetIndent) {
|
||||
StringBuffer buffer;
|
||||
PrettyWriter<StringBuffer> writer(buffer);
|
||||
|
||||
Reference in New Issue
Block a user