1 m4_define([JSON_CHECK_POSITIVE_C],
3 AT_KEYWORDS([json positive])
4 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
5 AT_CAPTURE_FILE([input])
6 AT_CHECK([test-json $4 input], [0], [stdout], [])
7 AT_CHECK([cat stdout], [0], [$3
11 m4_define([JSON_CHECK_POSITIVE_PY],
13 AT_KEYWORDS([json positive Python])
14 AT_SKIP_IF([test $HAVE_PYTHON = no])
15 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
16 AT_CAPTURE_FILE([input])
17 AT_CHECK([$PYTHON $srcdir/test-json.py $4 input], [0], [stdout], [])
18 AT_CHECK([cat stdout], [0], [$3
22 m4_define([JSON_CHECK_POSITIVE],
23 [JSON_CHECK_POSITIVE_C([$1 - C], [$2], [$3], [$4])
24 JSON_CHECK_POSITIVE_PY([$1 - Python], [$2], [$3], [$4])])
26 m4_define([JSON_CHECK_NEGATIVE_C],
28 AT_KEYWORDS([json negative])
29 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
30 AT_CAPTURE_FILE([input])
31 AT_CHECK([test-json $4 input], [1], [stdout], [])
32 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
36 m4_define([JSON_CHECK_NEGATIVE_PY],
38 AT_KEYWORDS([json negative Python])
39 AT_SKIP_IF([test $HAVE_PYTHON = no])
40 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
41 AT_CAPTURE_FILE([input])
42 AT_CHECK([$PYTHON $srcdir/test-json.py $4 input], [1], [stdout], [])
43 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
47 m4_define([JSON_CHECK_NEGATIVE],
48 [JSON_CHECK_NEGATIVE_C([$1 - C], [$2], [$3], [$4])
49 JSON_CHECK_NEGATIVE_PY([$1 - Python], [$2], [$3], [$4])])
51 AT_BANNER([JSON -- arrays])
53 JSON_CHECK_POSITIVE([empty array], [[ [ ] ]], [[[]]])
54 JSON_CHECK_POSITIVE([single-element array], [[ [ 1 ] ]], [[[1]]])
55 JSON_CHECK_POSITIVE([2-element array], [[ [ 1, 2 ] ]], [[[1,2]]])
56 JSON_CHECK_POSITIVE([many-element array],
57 [[ [ 1, 2, 3, 4, 5 ] ]],
59 JSON_CHECK_NEGATIVE([missing comma], [[ [ 1, 2, 3 4, 5 ] ]],
60 [error: syntax error expecting '@:>@' or ','])
61 JSON_CHECK_NEGATIVE([trailing comma not allowed],
62 [[[1,2,]]], [error: syntax error expecting value])
63 JSON_CHECK_NEGATIVE([doubled comma not allowed],
64 [[[1,,2]]], [error: syntax error expecting value])
66 AT_BANNER([JSON -- strings])
68 JSON_CHECK_POSITIVE([empty string], [[[ "" ]]], [[[""]]])
69 JSON_CHECK_POSITIVE([1-character strings],
70 [[[ "a", "b", "c" ]]],
72 JSON_CHECK_POSITIVE([escape sequences],
73 [[[ " \" \\ \/ \b \f \n \r \t" ]]],
74 [[[" \" \\ / \b \f \n \r \t"]]])
75 JSON_CHECK_POSITIVE([Unicode escape sequences],
76 [[[ " \u0022 \u005c \u002F \u0008 \u000c \u000A \u000d \u0009" ]]],
77 [[[" \" \\ / \b \f \n \r \t"]]])
78 JSON_CHECK_POSITIVE([surrogate pairs],
81 JSON_CHECK_NEGATIVE([a string by itself is not valid JSON], ["xxx"],
82 [error: syntax error at beginning of input])
83 JSON_CHECK_NEGATIVE([end of line in quoted string],
86 [error: U+000A must be escaped in quoted string])
87 JSON_CHECK_NEGATIVE([formfeed in quoted string],
89 [error: U+000C must be escaped in quoted string])
90 JSON_CHECK_NEGATIVE([bad escape in quoted string],
92 [error: bad escape \x])
93 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (1)],
95 [error: quoted string ends within \u escape])
96 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (2)],
98 [error: malformed \u escape])
99 JSON_CHECK_NEGATIVE([isolated leading surrogate not allowed],
101 [error: malformed escaped surrogate pair])
102 JSON_CHECK_NEGATIVE([surrogatess must paired properly],
103 [[["\ud834\u1234"]]],
104 [error: second half of escaped surrogate pair is not trailing surrogate])
105 JSON_CHECK_NEGATIVE([null bytes not allowed],
107 [error: null bytes not supported in quoted strings])
109 AT_SETUP([end of input in quoted string - C])
110 AT_KEYWORDS([json negative])
111 AT_CHECK([printf '"xxx' | test-json -], [1],
112 [error: line 0, column 4, byte 4: unexpected end of input in quoted string
116 AT_SETUP([end of input in quoted string - Python])
117 AT_KEYWORDS([json negative Python])
118 AT_SKIP_IF([test $HAVE_PYTHON = no])
119 AT_CHECK([printf '"xxx' > input
120 $PYTHON $srcdir/test-json.py input], [1],
121 [error: line 0, column 4, byte 4: unexpected end of input in quoted string
125 AT_BANNER([JSON -- objects])
127 JSON_CHECK_POSITIVE([empty object], [[{ }]], [[{}]])
128 JSON_CHECK_POSITIVE([simple object],
129 [[{"b": 2, "a": 1, "c": 3}]],
130 [[{"a":1,"b":2,"c":3}]])
131 JSON_CHECK_NEGATIVE([bad value], [[{"a": }, "b": 2]],
132 [error: syntax error expecting value])
133 JSON_CHECK_NEGATIVE([missing colon], [[{"b": 2, "a" 1, "c": 3}]],
134 [error: syntax error parsing object expecting ':'])
135 JSON_CHECK_NEGATIVE([missing comma], [[{"b": 2 "a" 1, "c": 3}]],
136 [error: syntax error expecting '}' or ','])
137 JSON_CHECK_NEGATIVE([trailing comma not allowed],
138 [[{"b": 2, "a": 1, "c": 3, }]],
139 [[error: syntax error parsing object expecting string]])
140 JSON_CHECK_NEGATIVE([doubled comma not allowed],
141 [[{"b": 2, "a": 1,, "c": 3}]],
142 [[error: syntax error parsing object expecting string]])
143 JSON_CHECK_NEGATIVE([names must be strings],
145 [[error: syntax error parsing object expecting string]])
147 AT_BANNER([JSON -- literal names])
149 JSON_CHECK_POSITIVE([null], [[[ null ]]], [[[null]]])
150 JSON_CHECK_POSITIVE([false], [[[ false ]]], [[[false]]])
151 JSON_CHECK_POSITIVE([true], [[[ true ]]], [[[true]]])
152 JSON_CHECK_NEGATIVE([a literal by itself is not valid JSON], [null],
153 [error: syntax error at beginning of input])
154 JSON_CHECK_NEGATIVE([nullify is invalid], [[[ nullify ]]],
155 [error: invalid keyword 'nullify'])
156 JSON_CHECK_NEGATIVE([nubs is invalid], [[[ nubs ]]],
157 [error: invalid keyword 'nubs'])
158 JSON_CHECK_NEGATIVE([xxx is invalid], [[[ xxx ]]],
159 [error: invalid keyword 'xxx'])
161 AT_BANNER([JSON -- numbers])
164 [integers expressed as reals],
166 2.00000000000000000000000000000000000,
172 [[[1,2,200000,21234,2123,0,0]]])
175 [[[9223372036854775807, -9223372036854775808]]],
176 [[[9223372036854775807,-9223372036854775808]]])
178 [large integers expressed as reals],
179 [[[9223372036854775807.0, -9223372036854775808.0,
180 92233720.36854775807e11, -9.223372036854775808e18]]],
181 [[[9223372036854775807,-9223372036854775808,9223372036854775807,-9223372036854775808]]])
182 # It seems likely that the following test will fail on some system that
183 # rounds slightly differently in arithmetic or in printf, but I'd like
184 # to keep it this way until we run into such a system.
186 [large integers that overflow to reals],
187 [[[9223372036854775807000, -92233720368547758080000]]],
188 [[[9.22337203685478e+21,-9.22337203685478e+22]]])
192 [[[-0, -0.0, 1e-9999, -1e-9999]]],
197 [[[0.0, 1.0, 2.0, 3.0, 3.5, 81.250]]],
198 [[[0,1,2,3,3.5,81.25]]])
200 [scientific notation],
201 [[[1e3, 1E3, 2.5E2, 1e+3, 125e-3, 3.125e-2, 3125e-05, 1.525878906e-5]]],
202 [[[1000,1000,250,1000,0.125,0.03125,0.03125,1.525878906e-05]]])
203 # It seems likely that the following test will fail on some system that
204 # rounds slightly differently in arithmetic or in printf, but I'd like
205 # to keep it this way until we run into such a system.
208 [[[1.7976931348623157e+308, -1.7976931348623157e+308]]],
209 [[[1.79769313486232e+308,-1.79769313486232e+308]]])
213 [[[-0, -1.0, -2.0, -3.0, -3.5, -8.1250]]],
214 [[[0,-1,-2,-3,-3.5,-8.125]]])
216 [negative scientific notation],
217 [[[-1e3, -1E3, -2.5E2, -1e+3, -125e-3, -3.125e-2, -3125e-05, -1.525878906e-5]]],
218 [[[-1000,-1000,-250,-1000,-0.125,-0.03125,-0.03125,-1.525878906e-05]]])
220 [1e-9999 underflows to 0],
223 JSON_CHECK_NEGATIVE([a number by itself is not valid JSON], [1],
224 [error: syntax error at beginning of input])
226 [leading zeros not allowed],
228 [error: leading zeros not allowed])
232 [error: number outside valid range])
234 [exponent bigger than INT_MAX],
235 [[[1e9999999999999999999]]],
236 [error: exponent outside valid range])
238 [decimal point must be followed by digit],
240 [error: decimal point must be followed by digit])
242 [exponent must contain at least one digit (1)],
244 [error: exponent must contain at least one digit])
246 [exponent must contain at least one digit (2)],
248 [error: exponent must contain at least one digit])
250 [exponent must contain at least one digit (3)],
252 [error: exponent must contain at least one digit])
254 AT_BANNER([JSON -- RFC 4627 examples])
256 JSON_CHECK_POSITIVE([RFC 4267 object example],
261 "Title": "View from 15th Floor",
263 "Url": "http://www.example.com/image/481989943",
267 "IDs": [116, 943, 234, 38793]
270 [[{"Image":{"Height":600,"IDs":[116,943,234,38793],"Thumbnail":{"Height":125,"Url":"http://www.example.com/image/481989943","Width":"100"},"Title":"View from 15th Floor","Width":800}}]])
272 JSON_CHECK_POSITIVE([RFC 4267 array example],
277 "Longitude": -122.3959,
279 "City": "SAN FRANCISCO",
286 "Latitude": 37.371991,
287 "Longitude": -122.026020,
295 [[[{"Address":"","City":"SAN FRANCISCO","Country":"US","Latitude":37.7668,"Longitude":-122.3959,"State":"CA","Zip":"94107","precision":"zip"},{"Address":"","City":"SUNNYVALE","Country":"US","Latitude":37.371991,"Longitude":-122.02602,"State":"CA","Zip":"94085","precision":"zip"}]]])
297 AT_BANNER([JSON -- pathological cases])
299 JSON_CHECK_NEGATIVE([trailing garbage], [[[1]null]],
300 [error: trailing garbage at end of input])
301 JSON_CHECK_NEGATIVE([formfeeds are not valid white space],
302 [[[
\f]]], [error: invalid character U+000c])
303 JSON_CHECK_NEGATIVE([';' is not a valid token],
304 [;], [error: invalid character ';'])
305 JSON_CHECK_NEGATIVE([arrays nesting too deep],
306 [m4_for([i], [0], [1002], [1], [@<:@])dnl
307 m4_for([i], [0], [1002], [1], [@:>@])],
308 [error: input exceeds maximum nesting depth 1000])
309 JSON_CHECK_NEGATIVE([objects nesting too deep],
310 [m4_for([i], [0], [1002], [1], [{"x":])dnl
311 m4_for([i], [0], [1002], [1], [}])],
312 [error: input exceeds maximum nesting depth 1000])
314 AT_SETUP([input may not be empty])
315 AT_KEYWORDS([json negative])
316 AT_CHECK([test-json /dev/null], [1], [error: line 0, column 0, byte 0: empty input stream
320 AT_BANNER([JSON -- multiple inputs])
322 JSON_CHECK_POSITIVE([multiple adjacent objects], [[{}{}{}]], [[{}
327 JSON_CHECK_POSITIVE([multiple space-separated objects], [[{} {} {}]], [[{}
332 JSON_CHECK_POSITIVE([multiple objects on separate lines], [[{}
339 JSON_CHECK_POSITIVE([multiple objects and arrays], [[{}[]{}[]]], [[{}
345 JSON_CHECK_NEGATIVE([garbage between multiple objects], [[{}x{}]], [[{}
346 error: invalid keyword 'x'
349 JSON_CHECK_NEGATIVE([garbage after multiple objects], [[{}{}x]], [[{}
351 error: invalid keyword 'x']], [--multiple])