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([ovstest 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_UCS4PY],
24 AT_KEYWORDS([json positive Python])
25 AT_SKIP_IF([test $HAVE_PYTHON = no])
26 AT_XFAIL_IF([$PYTHON -c "exit(len(u'\U00010800'))"; test $? -ne 1])
27 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
28 AT_CAPTURE_FILE([input])
29 AT_CHECK([$PYTHON $srcdir/test-json.py $4 input], [0], [stdout], [])
30 AT_CHECK([cat stdout], [0], [$3
34 m4_define([JSON_CHECK_POSITIVE],
35 [JSON_CHECK_POSITIVE_C([$1 - C], [$2], [$3], [$4])
36 JSON_CHECK_POSITIVE_PY([$1 - Python], [$2], [$3], [$4])])
38 m4_define([JSON_CHECK_NEGATIVE_C],
40 AT_KEYWORDS([json negative])
41 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
42 AT_CAPTURE_FILE([input])
43 AT_CHECK([ovstest test-json $4 input], [1], [stdout], [])
44 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
48 m4_define([JSON_CHECK_NEGATIVE_PY],
50 AT_KEYWORDS([json negative Python])
51 AT_SKIP_IF([test $HAVE_PYTHON = no])
52 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
53 AT_CAPTURE_FILE([input])
54 AT_CHECK([$PYTHON $srcdir/test-json.py $4 input], [1], [stdout], [])
55 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
59 m4_define([JSON_CHECK_NEGATIVE],
60 [JSON_CHECK_NEGATIVE_C([$1 - C], [$2], [$3], [$4])
61 JSON_CHECK_NEGATIVE_PY([$1 - Python], [$2], [$3], [$4])])
63 AT_BANNER([JSON -- arrays])
65 JSON_CHECK_POSITIVE([empty array], [[ [ ] ]], [[[]]])
66 JSON_CHECK_POSITIVE([single-element array], [[ [ 1 ] ]], [[[1]]])
67 JSON_CHECK_POSITIVE([2-element array], [[ [ 1, 2 ] ]], [[[1,2]]])
68 JSON_CHECK_POSITIVE([many-element array],
69 [[ [ 1, 2, 3, 4, 5 ] ]],
71 JSON_CHECK_NEGATIVE([missing comma], [[ [ 1, 2, 3 4, 5 ] ]],
72 [error: syntax error expecting '@:>@' or ','])
73 JSON_CHECK_NEGATIVE([trailing comma not allowed],
74 [[[1,2,]]], [error: syntax error expecting value])
75 JSON_CHECK_NEGATIVE([doubled comma not allowed],
76 [[[1,,2]]], [error: syntax error expecting value])
78 AT_BANNER([JSON -- strings])
80 JSON_CHECK_POSITIVE([empty string], [[[ "" ]]], [[[""]]])
81 JSON_CHECK_POSITIVE([1-character strings],
82 [[[ "a", "b", "c" ]]],
84 JSON_CHECK_POSITIVE([escape sequences],
85 [[[ " \" \\ \/ \b \f \n \r \t" ]]],
86 [[[" \" \\ / \b \f \n \r \t"]]])
87 JSON_CHECK_POSITIVE([Unicode escape sequences],
88 [[[ " \u0022 \u005c \u002F \u0008 \u000c \u000A \u000d \u0009" ]]],
89 [[[" \" \\ / \b \f \n \r \t"]]])
90 JSON_CHECK_POSITIVE_C([surrogate pairs - C],
93 JSON_CHECK_POSITIVE_UCS4PY([surrogate pairs - Python],
96 JSON_CHECK_NEGATIVE([a string by itself is not valid JSON], ["xxx"],
97 [error: syntax error at beginning of input])
98 JSON_CHECK_NEGATIVE([end of line in quoted string],
101 [error: U+000A must be escaped in quoted string])
102 JSON_CHECK_NEGATIVE([formfeed in quoted string],
104 [error: U+000C must be escaped in quoted string])
105 JSON_CHECK_NEGATIVE([bad escape in quoted string],
107 [error: bad escape \x])
108 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (1)],
110 [error: quoted string ends within \u escape])
111 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (2)],
113 [error: malformed \u escape])
114 JSON_CHECK_NEGATIVE([isolated leading surrogate not allowed],
116 [error: malformed escaped surrogate pair])
117 JSON_CHECK_NEGATIVE([surrogatess must paired properly],
118 [[["\ud834\u1234"]]],
119 [error: second half of escaped surrogate pair is not trailing surrogate])
120 JSON_CHECK_NEGATIVE([null bytes not allowed],
122 [error: null bytes not supported in quoted strings])
123 dnl Check for regression against a prior bug.
124 JSON_CHECK_POSITIVE([properly quoted backslash at end of string],
127 JSON_CHECK_NEGATIVE([stray backslash at end of string],
129 [error: unexpected end of input in quoted string])
131 AT_SETUP([end of input in quoted string - C])
132 AT_KEYWORDS([json negative])
133 AT_CHECK([printf '"xxx' | ovstest test-json -], [1],
134 [error: line 0, column 4, byte 4: unexpected end of input in quoted string
138 AT_SETUP([end of input in quoted string - Python])
139 AT_KEYWORDS([json negative Python])
140 AT_SKIP_IF([test $HAVE_PYTHON = no])
141 AT_CHECK([printf '"xxx' > input
142 $PYTHON $srcdir/test-json.py input], [1],
143 [error: line 0, column 4, byte 4: unexpected end of input in quoted string
147 AT_BANNER([JSON -- objects])
149 JSON_CHECK_POSITIVE([empty object], [[{ }]], [[{}]])
150 JSON_CHECK_POSITIVE([simple object],
151 [[{"b": 2, "a": 1, "c": 3}]],
152 [[{"a":1,"b":2,"c":3}]])
153 JSON_CHECK_NEGATIVE([bad value], [[{"a": }, "b": 2]],
154 [error: syntax error expecting value])
155 JSON_CHECK_NEGATIVE([missing colon], [[{"b": 2, "a" 1, "c": 3}]],
156 [error: syntax error parsing object expecting ':'])
157 JSON_CHECK_NEGATIVE([missing comma], [[{"b": 2 "a" 1, "c": 3}]],
158 [error: syntax error expecting '}' or ','])
159 JSON_CHECK_NEGATIVE([trailing comma not allowed],
160 [[{"b": 2, "a": 1, "c": 3, }]],
161 [[error: syntax error parsing object expecting string]])
162 JSON_CHECK_NEGATIVE([doubled comma not allowed],
163 [[{"b": 2, "a": 1,, "c": 3}]],
164 [[error: syntax error parsing object expecting string]])
165 JSON_CHECK_NEGATIVE([names must be strings],
167 [[error: syntax error parsing object expecting string]])
169 AT_BANNER([JSON -- literal names])
171 JSON_CHECK_POSITIVE([null], [[[ null ]]], [[[null]]])
172 JSON_CHECK_POSITIVE([false], [[[ false ]]], [[[false]]])
173 JSON_CHECK_POSITIVE([true], [[[ true ]]], [[[true]]])
174 JSON_CHECK_NEGATIVE([a literal by itself is not valid JSON], [null],
175 [error: syntax error at beginning of input])
176 JSON_CHECK_NEGATIVE([nullify is invalid], [[[ nullify ]]],
177 [error: invalid keyword 'nullify'])
178 JSON_CHECK_NEGATIVE([nubs is invalid], [[[ nubs ]]],
179 [error: invalid keyword 'nubs'])
180 JSON_CHECK_NEGATIVE([xxx is invalid], [[[ xxx ]]],
181 [error: invalid keyword 'xxx'])
183 AT_BANNER([JSON -- numbers])
186 [integers expressed as reals],
188 2.00000000000000000000000000000000000,
194 [[[1,2,200000,21234,2123,0,0]]])
197 [[[9223372036854775807, -9223372036854775808]]],
198 [[[9223372036854775807,-9223372036854775808]]])
200 [large integers expressed as reals],
201 [[[9223372036854775807.0, -9223372036854775808.0,
202 92233720.36854775807e11, -9.223372036854775808e18]]],
203 [[[9223372036854775807,-9223372036854775808,9223372036854775807,-9223372036854775808]]])
204 # It seems likely that the following test will fail on some system that
205 # rounds slightly differently in arithmetic or in printf, but I'd like
206 # to keep it this way until we run into such a system.
208 [large integers that overflow to reals],
209 [[[9223372036854775807000, -92233720368547758080000]]],
210 [[[9.22337203685478e+21,-9.22337203685478e+22]]])
214 [[[-0, -0.0, 1e-9999, -1e-9999]]],
219 [[[0.0, 1.0, 2.0, 3.0, 3.5, 81.250]]],
220 [[[0,1,2,3,3.5,81.25]]])
222 [scientific notation],
223 [[[1e3, 1E3, 2.5E2, 1e+3, 125e-3, 3.125e-2, 3125e-05, 1.525878906e-5]]],
224 [[[1000,1000,250,1000,0.125,0.03125,0.03125,1.525878906e-05]]])
225 # It seems likely that the following test will fail on some system that
226 # rounds slightly differently in arithmetic or in printf, but I'd like
227 # to keep it this way until we run into such a system.
230 [[[1.7976931348623157e+308, -1.7976931348623157e+308]]],
231 [[[1.79769313486232e+308,-1.79769313486232e+308]]])
235 [[[-0, -1.0, -2.0, -3.0, -3.5, -8.1250]]],
236 [[[0,-1,-2,-3,-3.5,-8.125]]])
238 [negative scientific notation],
239 [[[-1e3, -1E3, -2.5E2, -1e+3, -125e-3, -3.125e-2, -3125e-05, -1.525878906e-5]]],
240 [[[-1000,-1000,-250,-1000,-0.125,-0.03125,-0.03125,-1.525878906e-05]]])
242 [1e-9999 underflows to 0],
245 JSON_CHECK_NEGATIVE([a number by itself is not valid JSON], [1],
246 [error: syntax error at beginning of input])
248 [leading zeros not allowed],
250 [error: leading zeros not allowed])
254 [error: number outside valid range])
256 [exponent bigger than INT_MAX],
257 [[[1e9999999999999999999]]],
258 [error: exponent outside valid range])
260 [decimal point must be followed by digit],
262 [error: decimal point must be followed by digit])
264 [exponent must contain at least one digit (1)],
266 [error: exponent must contain at least one digit])
268 [exponent must contain at least one digit (2)],
270 [error: exponent must contain at least one digit])
272 [exponent must contain at least one digit (3)],
274 [error: exponent must contain at least one digit])
276 AT_BANNER([JSON -- RFC 4627 examples])
278 JSON_CHECK_POSITIVE([RFC 4267 object example],
283 "Title": "View from 15th Floor",
285 "Url": "http://www.example.com/image/481989943",
289 "IDs": [116, 943, 234, 38793]
292 [[{"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}}]])
294 JSON_CHECK_POSITIVE([RFC 4267 array example],
299 "Longitude": -122.3959,
301 "City": "SAN FRANCISCO",
308 "Latitude": 37.371991,
309 "Longitude": -122.026020,
317 [[[{"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"}]]])
319 AT_BANNER([JSON -- pathological cases])
321 JSON_CHECK_NEGATIVE([trailing garbage], [[[1]null]],
322 [error: trailing garbage at end of input])
323 JSON_CHECK_NEGATIVE([formfeeds are not valid white space],
324 [[[
\f]]], [error: invalid character U+000c])
325 JSON_CHECK_NEGATIVE([';' is not a valid token],
326 [;], [error: invalid character ';'])
327 JSON_CHECK_NEGATIVE([arrays nesting too deep],
328 [m4_for([i], [0], [1002], [1], [@<:@])dnl
329 m4_for([i], [0], [1002], [1], [@:>@])],
330 [error: input exceeds maximum nesting depth 1000])
331 JSON_CHECK_NEGATIVE([objects nesting too deep],
332 [m4_for([i], [0], [1002], [1], [{"x":])dnl
333 m4_for([i], [0], [1002], [1], [}])],
334 [error: input exceeds maximum nesting depth 1000])
336 AT_SETUP([input may not be empty])
337 AT_KEYWORDS([json negative])
338 AT_CHECK([ovstest test-json /dev/null], [1], [error: line 0, column 0, byte 0: empty input stream
342 AT_BANNER([JSON -- multiple inputs])
344 JSON_CHECK_POSITIVE([multiple adjacent objects], [[{}{}{}]], [[{}
349 JSON_CHECK_POSITIVE([multiple space-separated objects], [[{} {} {}]], [[{}
354 JSON_CHECK_POSITIVE([multiple objects on separate lines], [[{}
361 JSON_CHECK_POSITIVE([multiple objects and arrays], [[{}[]{}[]]], [[{}
367 JSON_CHECK_NEGATIVE([garbage between multiple objects], [[{}x{}]], [[{}
368 error: invalid keyword 'x'
371 JSON_CHECK_NEGATIVE([garbage after multiple objects], [[{}{}x]], [[{}
373 error: invalid keyword 'x']], [--multiple])