23 RAPIDJSON_DIAG_OFF(c++98-compat)
28 static const char kJson[] =
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,-1],\"u64\":1234567890123456789,\"i64\":-1234567890123456789}";
31 " \"hello\": \"world\",\n" 43 " \"u64\": 1234567890123456789,\n" 44 " \"i64\": -1234567890123456789\n" 49 " \"hello\": \"world\",\n" 55 " \"a\": [1, 2, 3, -1],\n" 56 " \"u64\": 1234567890123456789,\n" 57 " \"i64\": -1234567890123456789\n" 65 reader.
Parse(s, writer);
66 EXPECT_STREQ(kPrettyJson, buffer.
GetString());
75 reader.
Parse(s, writer);
76 EXPECT_STREQ(kPrettyJson_FormatOptions_SLA, buffer.
GetString());
85 reader.
Parse(s, writer);
88 "\t\"hello\": \"world\",\n" 100 "\t\"u64\": 1234567890123456789,\n" 101 "\t\"i64\": -1234567890123456789\n" 110 EXPECT_TRUE(writer.
String(
"Hello\n"));
112 EXPECT_STREQ(
"[\n \"Hello\\n\"\n]", buffer.
GetString());
115 #if RAPIDJSON_HAS_STDSTRING 120 EXPECT_TRUE(writer.
String(std::string(
"Hello\n")));
122 EXPECT_STREQ(
"[\n \"Hello\\n\"\n]", buffer.
GetString());
134 Ch
Peek()
const { assert(
false);
return '\0'; }
135 Ch
Take() { assert(
false);
return '\0'; }
136 size_t Tell()
const {
return 0; }
139 void Put(Ch c) { os_.put(c); }
141 size_t PutEnd(Ch*) { assert(
false);
return 0; }
154 std::stringstream ss;
160 reader.
Parse(s, writer);
162 std::string actual = ss.str();
163 EXPECT_STREQ(kPrettyJson, actual.c_str());
168 char filename[L_tmpnam];
170 ASSERT_TRUE(fp!=NULL);
176 reader.
Parse(s, writer);
179 fp = fopen(filename,
"rb");
180 fseek(fp, 0, SEEK_END);
181 size_t size =
static_cast<size_t>(ftell(fp));
182 fseek(fp, 0, SEEK_SET);
183 char*
json =
static_cast<char*
>(malloc(size + 1));
184 size_t readLength = fread(json, 1, size, fp);
185 json[readLength] =
'\0';
188 EXPECT_STREQ(kPrettyJson, json);
199 const char json[] =
"[\"Hello\\nWorld\", 123.456]";
206 " \"raw\": [\"Hello\\nWorld\", 123.456]\n" 263 double nan = std::numeric_limits<double>::quiet_NaN();
269 EXPECT_FALSE(writer.
Double(nan));
273 EXPECT_TRUE(writer.
Double(nan));
278 EXPECT_FALSE(writer2.
Double(nan));
282 double inf = std::numeric_limits<double>::infinity();
288 EXPECT_FALSE(writer.
Double(inf));
292 EXPECT_FALSE(writer.
Double(-inf));
296 EXPECT_TRUE(writer.
Double(inf));
300 EXPECT_TRUE(writer.
Double(-inf));
302 EXPECT_STREQ(
"Infinity-Infinity", buffer.
GetString());
306 char buf[100] =
"Hello";
314 EXPECT_STREQ(
"[\n \"Hello\"\n]", buffer.
GetString());
319 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
TEST(PrettyWriter, Basic)
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
bool RawValue(const Ch *json, size_t length, Type type)
Write a raw JSON value.
const Ch * GetString() const
PrettyWriter & SetIndent(Ch indentChar, unsigned indentCharCount)
Set custom indentation.
bool Key(const Ch *str, SizeType length, bool copy=false)
FILE * TempFile(char *filename)
Wrapper of C file stream for input using fread().
OStreamWrapper(std::ostream &os)
static const char kJson[]
bool EndObject(SizeType memberCount=0)
BasicOStreamWrapper< std::ostream > OStreamWrapper
static const char kPrettyJson_FormatOptions_SLA[]
C-runtime library allocator.
bool IsComplete() const
Checks whether the output is a complete JSON.
bool EndArray(SizeType memberCount=0)
static const char kPrettyJson[]
bool String(const Ch *str, SizeType length, bool copy=false)
Allow writing of Infinity, -Infinity and NaN.
Format arrays on a single line.
PrettyWriter & SetFormatOptions(PrettyFormatOptions options)
Set pretty writer formatting options.
Writer with indentation and spacing.