@@ -2521,12 +2521,35 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithNoErrors) {
25212521 JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
25222522}
25232523
2524+ JSONTEST_FIXTURE_LOCAL (ReaderTest, parseComment) {
2525+ Json::Reader reader;
2526+ Json::Value root;
2527+ bool ok = reader.parse (" { /*commentBeforeValue*/"
2528+ " \" property\" : \" value\" }"
2529+ " //commentAfterValue\n " ,
2530+ root);
2531+ JSONTEST_ASSERT (ok);
2532+ JSONTEST_ASSERT (reader.getFormattedErrorMessages ().empty ());
2533+ JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
2534+ }
2535+
2536+ JSONTEST_FIXTURE_LOCAL (ReaderTest, streamParseWithNoErrors) {
2537+ Json::Reader reader;
2538+ std::string styled = " { \" property\" : \" value\" }" ;
2539+ std::istringstream iss (styled);
2540+ Json::Value root;
2541+ bool ok = reader.parse (iss, root);
2542+ JSONTEST_ASSERT (ok);
2543+ JSONTEST_ASSERT (reader.getFormattedErrorMessages ().empty ());
2544+ JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
2545+ }
2546+
25242547JSONTEST_FIXTURE_LOCAL (ReaderTest, parseWithNoErrorsTestingOffsets) {
25252548 Json::Reader reader;
25262549 Json::Value root;
25272550 bool ok = reader.parse (" { \" property\" : [\" value\" , \" value2\" ], \" obj\" : "
2528- " { \" nested\" : 123 , \" bool\" : true}, \" null\" : "
2529- " null, \" false\" : false }" ,
2551+ " { \" nested\" : -6.2e+15 , \" bool\" : true}, \" null\" :"
2552+ " null, \" false\" : false }" ,
25302553 root);
25312554 JSONTEST_ASSERT (ok);
25322555 JSONTEST_ASSERT (reader.getFormattedErrorMessages ().empty ());
@@ -2538,17 +2561,17 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithNoErrorsTestingOffsets) {
25382561 JSONTEST_ASSERT (root[" property" ][1 ].getOffsetStart () == 25 );
25392562 JSONTEST_ASSERT (root[" property" ][1 ].getOffsetLimit () == 33 );
25402563 JSONTEST_ASSERT (root[" obj" ].getOffsetStart () == 44 );
2541- JSONTEST_ASSERT (root[" obj" ].getOffsetLimit () == 76 );
2564+ JSONTEST_ASSERT (root[" obj" ].getOffsetLimit () == 81 );
25422565 JSONTEST_ASSERT (root[" obj" ][" nested" ].getOffsetStart () == 57 );
2543- JSONTEST_ASSERT (root[" obj" ][" nested" ].getOffsetLimit () == 60 );
2544- JSONTEST_ASSERT (root[" obj" ][" bool" ].getOffsetStart () == 71 );
2545- JSONTEST_ASSERT (root[" obj" ][" bool" ].getOffsetLimit () == 75 );
2546- JSONTEST_ASSERT (root[" null" ].getOffsetStart () == 87 );
2547- JSONTEST_ASSERT (root[" null" ].getOffsetLimit () == 91 );
2548- JSONTEST_ASSERT (root[" false" ].getOffsetStart () == 103 );
2549- JSONTEST_ASSERT (root[" false" ].getOffsetLimit () == 108 );
2566+ JSONTEST_ASSERT (root[" obj" ][" nested" ].getOffsetLimit () == 65 );
2567+ JSONTEST_ASSERT (root[" obj" ][" bool" ].getOffsetStart () == 76 );
2568+ JSONTEST_ASSERT (root[" obj" ][" bool" ].getOffsetLimit () == 80 );
2569+ JSONTEST_ASSERT (root[" null" ].getOffsetStart () == 92 );
2570+ JSONTEST_ASSERT (root[" null" ].getOffsetLimit () == 96 );
2571+ JSONTEST_ASSERT (root[" false" ].getOffsetStart () == 108 );
2572+ JSONTEST_ASSERT (root[" false" ].getOffsetLimit () == 113 );
25502573 JSONTEST_ASSERT (root.getOffsetStart () == 0 );
2551- JSONTEST_ASSERT (root.getOffsetLimit () == 110 );
2574+ JSONTEST_ASSERT (root.getOffsetLimit () == 115 );
25522575}
25532576
25542577JSONTEST_FIXTURE_LOCAL (ReaderTest, parseWithOneError) {
@@ -2568,6 +2591,26 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithOneError) {
25682591 " Syntax error: value, object or array expected." );
25692592}
25702593
2594+ JSONTEST_FIXTURE_LOCAL (ReaderTest, strictModeParseNumber) {
2595+ Json::Features feature;
2596+ Json::Reader reader (feature.strictMode ());
2597+ Json::Value root;
2598+ bool ok = reader.parse (" 123" , root);
2599+ JSONTEST_ASSERT (!ok);
2600+ JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2601+ " * Line 1, Column 1\n "
2602+ " A valid JSON document must be either an array or"
2603+ " an object value.\n " );
2604+ std::vector<Json::Reader::StructuredError> errors =
2605+ reader.getStructuredErrors ();
2606+ JSONTEST_ASSERT (errors.size () == 1 );
2607+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 0 );
2608+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 3 );
2609+ JSONTEST_ASSERT (errors.at (0 ).message ==
2610+ " A valid JSON document must be either an array or"
2611+ " an object value." );
2612+ }
2613+
25712614JSONTEST_FIXTURE_LOCAL (ReaderTest, parseChineseWithOneError) {
25722615 Json::Reader reader;
25732616 Json::Value root;
@@ -2621,7 +2664,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithNoErrorsTestingOffsets) {
26212664 Json::String errs;
26222665 Json::Value root;
26232666 char const doc[] = " { \" property\" : [\" value\" , \" value2\" ], \" obj\" : "
2624- " { \" nested\" : 123 , \" bool\" : true}, \" null\" : "
2667+ " { \" nested\" : -6.2e+15 , \" bool\" : true}, \" null\" : "
26252668 " null, \" false\" : false }" ;
26262669 bool ok = reader->parse (doc, doc + std::strlen (doc), &root, &errs);
26272670 JSONTEST_ASSERT (ok);
@@ -2695,6 +2738,14 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
26952738 }
26962739}
26972740
2741+ JSONTEST_FIXTURE_LOCAL (CharReaderTest, testOperator) {
2742+ const std::string styled = " { \" property\" : \" value\" }" ;
2743+ std::istringstream iss (styled);
2744+ Json::Value root;
2745+ iss >> root;
2746+ JSONTEST_ASSERT_EQUAL (" value" , root[" property" ]);
2747+ }
2748+
26982749struct CharReaderStrictModeTest : JsonTest::TestCase {};
26992750
27002751JSONTEST_FIXTURE_LOCAL (CharReaderStrictModeTest, dupKeys) {
@@ -2950,6 +3001,25 @@ JSONTEST_FIXTURE_LOCAL(CharReaderAllowDropNullTest, issue178) {
29503001 delete reader;
29513002}
29523003
3004+ struct CharReaderAllowNumericKeysTest : JsonTest::TestCase {};
3005+
3006+ JSONTEST_FIXTURE_LOCAL (CharReaderAllowNumericKeysTest, allowNumericKeys) {
3007+ Json::CharReaderBuilder b;
3008+ b.settings_ [" allowNumericKeys" ] = true ;
3009+ Json::Value root;
3010+ Json::String errs;
3011+ Json::CharReader* reader (b.newCharReader ());
3012+ char const doc[] = " {15:true,-16:true,12.01:true}" ;
3013+ bool ok = reader->parse (doc, doc + std::strlen (doc), &root, &errs);
3014+ JSONTEST_ASSERT (ok);
3015+ JSONTEST_ASSERT_STRING_EQUAL (" " , errs);
3016+ JSONTEST_ASSERT_EQUAL (3u , root.size ());
3017+ JSONTEST_ASSERT_EQUAL (true , root.get (" 15" , false ));
3018+ JSONTEST_ASSERT_EQUAL (true , root.get (" -16" , false ));
3019+ JSONTEST_ASSERT_EQUAL (true , root.get (" 12.01" , false ));
3020+ delete reader;
3021+ }
3022+
29533023struct CharReaderAllowSingleQuotesTest : JsonTest::TestCase {};
29543024
29553025JSONTEST_FIXTURE_LOCAL (CharReaderAllowSingleQuotesTest, issue182) {
@@ -3082,6 +3152,53 @@ JSONTEST_FIXTURE_LOCAL(CharReaderAllowSpecialFloatsTest, issue209) {
30823152 delete reader;
30833153}
30843154
3155+ struct EscapeSequenceTest : JsonTest::TestCase {};
3156+
3157+ JSONTEST_FIXTURE_LOCAL (EscapeSequenceTest, readerParseEscapeSequence) {
3158+ Json::Reader reader;
3159+ Json::Value root;
3160+ bool ok = reader.parse (" [\"\\\"\" ,\"\\ /\" ,\"\\\\\" ,\"\\ b\" ,"
3161+ " \"\\ f\" ,\"\\ n\" ,\"\\ r\" ,\"\\ t\" ,"
3162+ " \"\\ u0278\" ,\"\\ ud852\\ udf62\" ]\n " ,
3163+ root);
3164+ JSONTEST_ASSERT (ok);
3165+ JSONTEST_ASSERT (reader.getFormattedErrorMessages ().empty ());
3166+ JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
3167+ }
3168+
3169+ JSONTEST_FIXTURE_LOCAL (EscapeSequenceTest, charReaderParseEscapeSequence) {
3170+ Json::CharReaderBuilder b;
3171+ Json::CharReader* reader (b.newCharReader ());
3172+ Json::Value root;
3173+ Json::String errs;
3174+ char const doc[] = " [\"\\\"\" ,\"\\ /\" ,\"\\\\\" ,\"\\ b\" ,"
3175+ " \"\\ f\" ,\"\\ n\" ,\"\\ r\" ,\"\\ t\" ,"
3176+ " \"\\ u0278\" ,\"\\ ud852\\ udf62\" ]" ;
3177+ bool ok = reader->parse (doc, doc + std::strlen (doc), &root, &errs);
3178+ JSONTEST_ASSERT (ok);
3179+ JSONTEST_ASSERT (errs.empty ());
3180+ delete reader;
3181+ }
3182+
3183+ JSONTEST_FIXTURE_LOCAL (EscapeSequenceTest, writeEscapeSequence) {
3184+ Json::FastWriter writer;
3185+ const Json::String expected (" [\"\\\"\" ,\"\\\\\" ,\"\\ b\" ,"
3186+ " \"\\ f\" ,\"\\ n\" ,\"\\ r\" ,\"\\ t\" ,"
3187+ " \"\\ u0278\" ,\"\\ ud852\\ udf62\" ]\n " );
3188+ Json::Value root;
3189+ root[0 ] = " \" " ;
3190+ root[1 ] = " \\ " ;
3191+ root[2 ] = " \b " ;
3192+ root[3 ] = " \f " ;
3193+ root[4 ] = " \n " ;
3194+ root[5 ] = " \r " ;
3195+ root[6 ] = " \t " ;
3196+ root[7 ] = " ɸ" ;
3197+ root[8 ] = " 𤭢" ;
3198+ const Json::String result = writer.write (root);
3199+ JSONTEST_ASSERT_STRING_EQUAL (expected, result);
3200+ }
3201+
30853202struct BuilderTest : JsonTest::TestCase {};
30863203
30873204JSONTEST_FIXTURE_LOCAL (BuilderTest, settings) {
0 commit comments