@@ -2642,7 +2642,21 @@ JSONTEST_FIXTURE_LOCAL(StreamWriterTest, unicode) {
2642
2642
" \"\\ t\\ n\\ ud806\\ udca1=\\ u0133\\ ud82c\\ udd1b\\ uff67\"\n }" );
2643
2643
}
2644
2644
2645
- struct ReaderTest : JsonTest::TestCase {};
2645
+ struct ReaderTest : JsonTest::TestCase {
2646
+ void testStructuredError (Json::Reader reader, Json::ArrayIndex errors_size,
2647
+ Json::Reader::StructuredError structederror[]) {
2648
+ std::vector<Json::Reader::StructuredError> errors =
2649
+ reader.getStructuredErrors ();
2650
+ JSONTEST_ASSERT (errors.size () == errors_size);
2651
+ for (size_t i = 0 ; i < errors_size; i++) {
2652
+ JSONTEST_ASSERT (errors.at (i).offset_start ==
2653
+ structederror[i].offset_start );
2654
+ JSONTEST_ASSERT (errors.at (i).offset_limit ==
2655
+ structederror[i].offset_limit );
2656
+ JSONTEST_ASSERT (errors.at (i).message == structederror[i].message );
2657
+ }
2658
+ }
2659
+ };
2646
2660
2647
2661
JSONTEST_FIXTURE_LOCAL (ReaderTest, parseWithNoErrors) {
2648
2662
Json::Reader reader;
@@ -2662,20 +2676,29 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseObject) {
2662
2676
JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2663
2677
" * Line 1, Column 12\n Missing ':' after object "
2664
2678
" member name\n " );
2679
+ Json::Reader::StructuredError structuredError[] = {
2680
+ {11 , 12 , " Missing ':' after object member name" }};
2681
+ testStructuredError (reader, 1 , structuredError);
2665
2682
}
2666
2683
{
2667
2684
bool ok = reader.parse (" {\" property\" : \" value\" " , root);
2668
2685
JSONTEST_ASSERT (!ok);
2669
2686
JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2670
2687
" * Line 1, Column 23\n Missing ',' or '}' in object "
2671
2688
" declaration\n " );
2689
+ Json::Reader::StructuredError structuredError[] = {
2690
+ {22 , 22 , " Missing ',' or '}' in object declaration" }};
2691
+ testStructuredError (reader, 1 , structuredError);
2672
2692
}
2673
2693
{
2674
2694
bool ok = reader.parse (" {\" property\" : \" value\" , " , root);
2675
2695
JSONTEST_ASSERT (!ok);
2676
2696
JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2677
2697
" * Line 1, Column 24\n Missing '}' or object "
2678
2698
" member name\n " );
2699
+ Json::Reader::StructuredError structuredError[] = {
2700
+ {23 , 23 , " Missing '}' or object member name" }};
2701
+ testStructuredError (reader, 1 , structuredError);
2679
2702
}
2680
2703
}
2681
2704
@@ -2688,13 +2711,19 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseArray) {
2688
2711
JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2689
2712
" * Line 1, Column 11\n Missing ',' or ']' in array "
2690
2713
" declaration\n " );
2714
+ Json::Reader::StructuredError structuredError[] = {
2715
+ {10 , 10 , " Missing ',' or ']' in array declaration" }};
2716
+ testStructuredError (reader, 1 , structuredError);
2691
2717
}
2692
2718
{
2693
2719
bool ok = reader.parse (" [ \" value1\" \" value2\" ] " , root);
2694
2720
JSONTEST_ASSERT (!ok);
2695
2721
JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2696
2722
" * Line 1, Column 12\n Missing ',' or ']' in array "
2697
2723
" declaration\n " );
2724
+ Json::Reader::StructuredError structuredError[] = {
2725
+ {11 , 19 , " Missing ',' or ']' in array declaration" }};
2726
+ testStructuredError (reader, 1 , structuredError);
2698
2727
}
2699
2728
}
2700
2729
@@ -2708,13 +2737,18 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseString) {
2708
2737
JSONTEST_ASSERT (reader.getStructuredErrors ().empty ());
2709
2738
}
2710
2739
{
2711
- bool ok = reader.parse (" [ \"\\ uD801 \" ]" , root);
2740
+ bool ok = reader.parse (" [ \"\\ ud801 \" ]" , root);
2712
2741
JSONTEST_ASSERT (!ok);
2713
2742
JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2714
2743
" * Line 1, Column 3\n "
2715
2744
" additional six characters expected to "
2716
2745
" parse unicode surrogate pair.\n "
2717
2746
" See Line 1, Column 10 for detail.\n " );
2747
+ Json::Reader::StructuredError structuredError[] = {
2748
+ {2 , 10 ,
2749
+ " additional six characters expected to "
2750
+ " parse unicode surrogate pair." }};
2751
+ testStructuredError (reader, 1 , structuredError);
2718
2752
}
2719
2753
{
2720
2754
bool ok = reader.parse (" [ \"\\ ud801\\ d1234\" ]" , root);
@@ -2724,6 +2758,11 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseString) {
2724
2758
" expecting another \\ u token to begin the "
2725
2759
" second half of a unicode surrogate pair\n "
2726
2760
" See Line 1, Column 12 for detail.\n " );
2761
+ Json::Reader::StructuredError structuredError[] = {
2762
+ {2 , 16 ,
2763
+ " expecting another \\ u token to begin the "
2764
+ " second half of a unicode surrogate pair" }};
2765
+ testStructuredError (reader, 1 , structuredError);
2727
2766
}
2728
2767
{
2729
2768
bool ok = reader.parse (" [ \"\\ ua3t@\" ]" , root);
@@ -2733,6 +2772,11 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseString) {
2733
2772
" Bad unicode escape sequence in string: "
2734
2773
" hexadecimal digit expected.\n "
2735
2774
" See Line 1, Column 9 for detail.\n " );
2775
+ Json::Reader::StructuredError structuredError[] = {
2776
+ {2 , 10 ,
2777
+ " Bad unicode escape sequence in string: "
2778
+ " hexadecimal digit expected." }};
2779
+ testStructuredError (reader, 1 , structuredError);
2736
2780
}
2737
2781
{
2738
2782
bool ok = reader.parse (" [ \"\\ ua3t\" ]" , root);
@@ -2742,6 +2786,9 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseString) {
2742
2786
" * Line 1, Column 3\n "
2743
2787
" Bad unicode escape sequence in string: four digits expected.\n "
2744
2788
" See Line 1, Column 6 for detail.\n " );
2789
+ Json::Reader::StructuredError structuredError[] = {
2790
+ {2 , 9 , " Bad unicode escape sequence in string: four digits expected." }};
2791
+ testStructuredError (reader, 1 , structuredError);
2745
2792
}
2746
2793
}
2747
2794
@@ -2816,7 +2863,7 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithNoErrorsTestingOffsets) {
2816
2863
JSONTEST_ASSERT (root.getOffsetLimit () == 115 );
2817
2864
}
2818
2865
2819
- JSONTEST_FIXTURE_LOCAL (ReaderTest, parseWithOneErrorTestingOffsets ) {
2866
+ JSONTEST_FIXTURE_LOCAL (ReaderTest, parseWithOneError ) {
2820
2867
Json::Reader reader;
2821
2868
Json::Value root;
2822
2869
{
@@ -2826,13 +2873,9 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithOneErrorTestingOffsets) {
2826
2873
reader.getFormattedErrorMessages () ==
2827
2874
" * Line 1, Column 15\n Syntax error: value, object or array "
2828
2875
" expected.\n " );
2829
- std::vector<Json::Reader::StructuredError> errors =
2830
- reader.getStructuredErrors ();
2831
- JSONTEST_ASSERT (errors.size () == 1 );
2832
- JSONTEST_ASSERT (errors.at (0 ).offset_start == 14 );
2833
- JSONTEST_ASSERT (errors.at (0 ).offset_limit == 15 );
2834
- JSONTEST_ASSERT (errors.at (0 ).message ==
2835
- " Syntax error: value, object or array expected." );
2876
+ Json::Reader::StructuredError structuredError[] = {
2877
+ {14 , 15 , " Syntax error: value, object or array expected." }};
2878
+ testStructuredError (reader, 1 , structuredError);
2836
2879
}
2837
2880
{
2838
2881
bool ok = reader.parse (" s" , root);
@@ -2841,13 +2884,9 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithOneErrorTestingOffsets) {
2841
2884
reader.getFormattedErrorMessages () ==
2842
2885
" * Line 1, Column 1\n Syntax error: value, object or array "
2843
2886
" expected.\n " );
2844
- std::vector<Json::Reader::StructuredError> errors =
2845
- reader.getStructuredErrors ();
2846
- JSONTEST_ASSERT (errors.size () == 1 );
2847
- JSONTEST_ASSERT (errors.at (0 ).offset_start == 0 );
2848
- JSONTEST_ASSERT (errors.at (0 ).offset_limit == 1 );
2849
- JSONTEST_ASSERT (errors.at (0 ).message ==
2850
- " Syntax error: value, object or array expected." );
2887
+ Json::Reader::StructuredError structuredError[] = {
2888
+ {0 , 1 , " Syntax error: value, object or array expected." }};
2889
+ testStructuredError (reader, 1 , structuredError);
2851
2890
}
2852
2891
}
2853
2892
@@ -2861,6 +2900,9 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseSpecialFloat) {
2861
2900
reader.getFormattedErrorMessages () ==
2862
2901
" * Line 1, Column 9\n Syntax error: value, object or array "
2863
2902
" expected.\n " );
2903
+ Json::Reader::StructuredError structuredError[] = {
2904
+ {8 , 9 , " Syntax error: value, object or array expected." }};
2905
+ testStructuredError (reader, 1 , structuredError);
2864
2906
}
2865
2907
{
2866
2908
bool ok = reader.parse (" { \" a\" : Infiniaa }" , root);
@@ -2869,6 +2911,9 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseSpecialFloat) {
2869
2911
reader.getFormattedErrorMessages () ==
2870
2912
" * Line 1, Column 9\n Syntax error: value, object or array "
2871
2913
" expected.\n " );
2914
+ Json::Reader::StructuredError structuredError[] = {
2915
+ {8 , 9 , " Syntax error: value, object or array expected." }};
2916
+ testStructuredError (reader, 1 , structuredError);
2872
2917
}
2873
2918
}
2874
2919
@@ -2882,6 +2927,11 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, strictModeParseNumber) {
2882
2927
" * Line 1, Column 1\n "
2883
2928
" A valid JSON document must be either an array or"
2884
2929
" an object value.\n " );
2930
+ Json::Reader::StructuredError structuredError[] = {
2931
+ {0 , 3 ,
2932
+ " A valid JSON document must be either an array or"
2933
+ " an object value." }};
2934
+ testStructuredError (reader, 1 , structuredError);
2885
2935
}
2886
2936
2887
2937
JSONTEST_FIXTURE_LOCAL (ReaderTest, parseChineseWithOneError) {
@@ -2892,6 +2942,9 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseChineseWithOneError) {
2892
2942
JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2893
2943
" * Line 1, Column 19\n Syntax error: value, object or array "
2894
2944
" expected.\n " );
2945
+ Json::Reader::StructuredError structuredError[] = {
2946
+ {18 , 19 , " Syntax error: value, object or array expected." }};
2947
+ testStructuredError (reader, 1 , structuredError);
2895
2948
}
2896
2949
2897
2950
JSONTEST_FIXTURE_LOCAL (ReaderTest, parseWithDetailError) {
@@ -2902,6 +2955,9 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithDetailError) {
2902
2955
JSONTEST_ASSERT (reader.getFormattedErrorMessages () ==
2903
2956
" * Line 1, Column 16\n Bad escape sequence in string\n See "
2904
2957
" Line 1, Column 20 for detail.\n " );
2958
+ Json::Reader::StructuredError structuredError[] = {
2959
+ {15 , 23 , " Bad escape sequence in string" }};
2960
+ testStructuredError (reader, 1 , structuredError);
2905
2961
}
2906
2962
2907
2963
JSONTEST_FIXTURE_LOCAL (ReaderTest, pushErrorTest) {
0 commit comments