@@ -2653,16 +2653,193 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithNoErrors) {
2653
2653
JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
2654
2654
}
2655
2655
2656
+ JSONTEST_FIXTURE_LOCAL (ReaderTest, parseObject) {
2657
+ Json::Reader reader;
2658
+ Json::Value root;
2659
+ {
2660
+ bool ok = reader.parse (" {\" property\" }" , root);
2661
+ JSONTEST_ASSERT (!ok);
2662
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2663
+ " * Line 1, Column 12\n Missing ':' after object "
2664
+ " member name\n " );
2665
+ std::vector<Json::Reader::StructuredError> errors =
2666
+ reader.getStructuredErrors ();
2667
+ JSONTEST_ASSERT (errors.size () == 1 );
2668
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 11 );
2669
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 12 );
2670
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2671
+ " Missing ':' after object member name" );
2672
+ }
2673
+ {
2674
+ bool ok = reader.parse (" {\" property\" : \" value\" " , root);
2675
+ JSONTEST_ASSERT (!ok);
2676
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2677
+ " * Line 1, Column 23\n Missing ',' or '}' in object "
2678
+ " declaration\n " );
2679
+ std::vector<Json::Reader::StructuredError> errors =
2680
+ reader.getStructuredErrors ();
2681
+ JSONTEST_ASSERT (errors.size () == 1 );
2682
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 22 );
2683
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 22 );
2684
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2685
+ " Missing ',' or '}' in object declaration" );
2686
+ }
2687
+ {
2688
+ bool ok = reader.parse (" {\" property\" : \" value\" , " , root);
2689
+ JSONTEST_ASSERT (!ok);
2690
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2691
+ " * Line 1, Column 24\n Missing '}' or object "
2692
+ " member name\n " );
2693
+ std::vector<Json::Reader::StructuredError> errors =
2694
+ reader.getStructuredErrors ();
2695
+ JSONTEST_ASSERT (errors.size () == 1 );
2696
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 23 );
2697
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 23 );
2698
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2699
+ " Missing '}' or object member name" );
2700
+ }
2701
+ }
2702
+
2703
+ JSONTEST_FIXTURE_LOCAL (ReaderTest, parseArray) {
2704
+ Json::Reader reader;
2705
+ Json::Value root;
2706
+ {
2707
+ bool ok = reader.parse (" [ \" value\" " , root);
2708
+ JSONTEST_ASSERT (!ok);
2709
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2710
+ " * Line 1, Column 11\n Missing ',' or ']' in array "
2711
+ " declaration\n " );
2712
+ std::vector<Json::Reader::StructuredError> errors =
2713
+ reader.getStructuredErrors ();
2714
+ JSONTEST_ASSERT (errors.size () == 1 );
2715
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 10 );
2716
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 10 );
2717
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2718
+ " Missing ',' or ']' in array declaration" );
2719
+ }
2720
+ {
2721
+ bool ok = reader.parse (" [ \" value1\" \" value2\" ] " , root);
2722
+ JSONTEST_ASSERT (!ok);
2723
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2724
+ " * Line 1, Column 12\n Missing ',' or ']' in array "
2725
+ " declaration\n " );
2726
+ std::vector<Json::Reader::StructuredError> errors =
2727
+ reader.getStructuredErrors ();
2728
+ JSONTEST_ASSERT (errors.size () == 1 );
2729
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 11 );
2730
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 19 );
2731
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2732
+ " Missing ',' or ']' in array declaration" );
2733
+ }
2734
+ }
2735
+
2736
+ JSONTEST_FIXTURE_LOCAL (ReaderTest, parseString) {
2737
+ Json::Reader reader;
2738
+ Json::Value root;
2739
+ {
2740
+ bool ok = reader.parse (" [ \"\\ u8A2a\" ]" , root);
2741
+ JSONTEST_ASSERT (ok);
2742
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages ().empty ());
2743
+ JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
2744
+ }
2745
+ {
2746
+ bool ok = reader.parse (" [ \"\\ uD801\" ]" , root);
2747
+ JSONTEST_ASSERT (!ok);
2748
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2749
+ " * Line 1, Column 3\n "
2750
+ " additional six characters expected to "
2751
+ " parse unicode surrogate pair.\n "
2752
+ " See Line 1, Column 10 for detail.\n " );
2753
+ std::vector<Json::Reader::StructuredError> errors =
2754
+ reader.getStructuredErrors ();
2755
+ JSONTEST_ASSERT (errors.size () == 1 );
2756
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 2 );
2757
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 10 );
2758
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2759
+ " additional six characters expected to "
2760
+ " parse unicode surrogate pair." );
2761
+ }
2762
+ {
2763
+ bool ok = reader.parse (" [ \"\\ uD801\\ d1234\" ]" , root);
2764
+ JSONTEST_ASSERT (!ok);
2765
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2766
+ " * Line 1, Column 3\n "
2767
+ " expecting another \\ u token to begin the "
2768
+ " second half of a unicode surrogate pair\n "
2769
+ " See Line 1, Column 12 for detail.\n " );
2770
+ std::vector<Json::Reader::StructuredError> errors =
2771
+ reader.getStructuredErrors ();
2772
+ JSONTEST_ASSERT (errors.size () == 1 );
2773
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 2 );
2774
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 16 );
2775
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2776
+ " expecting another \\ u token to begin the "
2777
+ " second half of a unicode surrogate pair" );
2778
+ }
2779
+ {
2780
+ bool ok = reader.parse (" [ \"\\ ua3t@\" ]" , root);
2781
+ JSONTEST_ASSERT (!ok);
2782
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2783
+ " * Line 1, Column 3\n "
2784
+ " Bad unicode escape sequence in string: "
2785
+ " hexadecimal digit expected.\n "
2786
+ " See Line 1, Column 9 for detail.\n " );
2787
+ std::vector<Json::Reader::StructuredError> errors =
2788
+ reader.getStructuredErrors ();
2789
+ JSONTEST_ASSERT (errors.size () == 1 );
2790
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 2 );
2791
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 10 );
2792
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2793
+ " Bad unicode escape sequence in string: "
2794
+ " hexadecimal digit expected." );
2795
+ }
2796
+ {
2797
+ bool ok = reader.parse (" [ \"\\ ua3t\" ]" , root);
2798
+ JSONTEST_ASSERT (!ok);
2799
+ JSONTEST_ASSERT (
2800
+ reader.getFormattedErrorMessages () ==
2801
+ " * Line 1, Column 3\n "
2802
+ " Bad unicode escape sequence in string: four digits expected.\n "
2803
+ " See Line 1, Column 6 for detail.\n " );
2804
+ std::vector<Json::Reader::StructuredError> errors =
2805
+ reader.getStructuredErrors ();
2806
+ JSONTEST_ASSERT (errors.size () == 1 );
2807
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 2 );
2808
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 9 );
2809
+ JSONTEST_ASSERT (
2810
+ errors.at (0 ).message ==
2811
+ " Bad unicode escape sequence in string: four digits expected." );
2812
+ }
2813
+ }
2814
+
2656
2815
JSONTEST_FIXTURE_LOCAL (ReaderTest, parseComment) {
2657
2816
Json::Reader reader;
2658
2817
Json::Value root;
2659
- bool ok = reader.parse (" { /*commentBeforeValue*/"
2660
- " \" property\" : \" value\" }"
2661
- " //commentAfterValue\n " ,
2662
- root);
2663
- JSONTEST_ASSERT (ok);
2664
- JSONTEST_ASSERT (reader.getFormattedErrorMessages ().empty ());
2665
- JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
2818
+ {
2819
+ bool ok = reader.parse (" { /*commentBeforeValue*/"
2820
+ " \" property\" : \" value\" }"
2821
+ " //commentAfterValue\n " ,
2822
+ root);
2823
+ JSONTEST_ASSERT (ok);
2824
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages ().empty ());
2825
+ JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
2826
+ }
2827
+ {
2828
+ bool ok = reader.parse (" { \" property\" : \" value\" } "
2829
+ " //trailing\n //comment\n " ,
2830
+ root);
2831
+ JSONTEST_ASSERT (ok);
2832
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages ().empty ());
2833
+ JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
2834
+ }
2835
+ {
2836
+ bool ok = reader.parse (" true //comment1\n //comment2\r "
2837
+ " //comment3\r\n " ,
2838
+ root);
2839
+ JSONTEST_ASSERT (ok);
2840
+ JSONTEST_ASSERT (reader.getFormattedErrorMessages ().empty ());
2841
+ JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
2842
+ }
2666
2843
}
2667
2844
2668
2845
JSONTEST_FIXTURE_LOCAL (ReaderTest, streamParseWithNoErrors) {
@@ -2709,18 +2886,71 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithNoErrorsTestingOffsets) {
2709
2886
JSONTEST_FIXTURE_LOCAL (ReaderTest, parseWithOneError) {
2710
2887
Json::Reader reader;
2711
2888
Json::Value root;
2712
- bool ok = reader.parse (" { \" property\" :: \" value\" }" , root);
2713
- JSONTEST_ASSERT (!ok);
2714
- JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2715
- " * Line 1, Column 15\n Syntax error: value, object or array "
2716
- " expected.\n " );
2717
- std::vector<Json::Reader::StructuredError> errors =
2718
- reader.getStructuredErrors ();
2719
- JSONTEST_ASSERT (errors.size () == 1 );
2720
- JSONTEST_ASSERT (errors.at (0 ).offset_start == 14 );
2721
- JSONTEST_ASSERT (errors.at (0 ).offset_limit == 15 );
2722
- JSONTEST_ASSERT (errors.at (0 ).message ==
2723
- " Syntax error: value, object or array expected." );
2889
+ {
2890
+ bool ok = reader.parse (" { \" property\" :: \" value\" }" , root);
2891
+ JSONTEST_ASSERT (!ok);
2892
+ JSONTEST_ASSERT (
2893
+ reader.getFormattedErrorMessages () ==
2894
+ " * Line 1, Column 15\n Syntax error: value, object or array "
2895
+ " expected.\n " );
2896
+ std::vector<Json::Reader::StructuredError> errors =
2897
+ reader.getStructuredErrors ();
2898
+ JSONTEST_ASSERT (errors.size () == 1 );
2899
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 14 );
2900
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 15 );
2901
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2902
+ " Syntax error: value, object or array expected." );
2903
+ }
2904
+ {
2905
+ bool ok = reader.parse (" s" , root);
2906
+ JSONTEST_ASSERT (!ok);
2907
+ JSONTEST_ASSERT (
2908
+ reader.getFormattedErrorMessages () ==
2909
+ " * Line 1, Column 1\n Syntax error: value, object or array "
2910
+ " expected.\n " );
2911
+ std::vector<Json::Reader::StructuredError> errors =
2912
+ reader.getStructuredErrors ();
2913
+ JSONTEST_ASSERT (errors.size () == 1 );
2914
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 0 );
2915
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 1 );
2916
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2917
+ " Syntax error: value, object or array expected." );
2918
+ }
2919
+ }
2920
+
2921
+ JSONTEST_FIXTURE_LOCAL (ReaderTest, parseSpecialFloat) {
2922
+ Json::Reader reader;
2923
+ Json::Value root;
2924
+ {
2925
+ bool ok = reader.parse (" { \" a\" : Infi }" , root);
2926
+ JSONTEST_ASSERT (!ok);
2927
+ JSONTEST_ASSERT (
2928
+ reader.getFormattedErrorMessages () ==
2929
+ " * Line 1, Column 9\n Syntax error: value, object or array "
2930
+ " expected.\n " );
2931
+ std::vector<Json::Reader::StructuredError> errors =
2932
+ reader.getStructuredErrors ();
2933
+ JSONTEST_ASSERT (errors.size () == 1 );
2934
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 8 );
2935
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 9 );
2936
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2937
+ " Syntax error: value, object or array expected." );
2938
+ }
2939
+ {
2940
+ bool ok = reader.parse (" { \" a\" : Infiniaa }" , root);
2941
+ JSONTEST_ASSERT (!ok);
2942
+ JSONTEST_ASSERT (
2943
+ reader.getFormattedErrorMessages () ==
2944
+ " * Line 1, Column 9\n Syntax error: value, object or array "
2945
+ " expected.\n " );
2946
+ std::vector<Json::Reader::StructuredError> errors =
2947
+ reader.getStructuredErrors ();
2948
+ JSONTEST_ASSERT (errors.size () == 1 );
2949
+ JSONTEST_ASSERT (errors.at (0 ).offset_start == 8 );
2950
+ JSONTEST_ASSERT (errors.at (0 ).offset_limit == 9 );
2951
+ JSONTEST_ASSERT (errors.at (0 ).message ==
2952
+ " Syntax error: value, object or array expected." );
2953
+ }
2724
2954
}
2725
2955
2726
2956
JSONTEST_FIXTURE_LOCAL (ReaderTest, strictModeParseNumber) {
0 commit comments