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 # JSON_CHECK_POSITIVE_PY(TITLE, INPUT, OUTPUT, TEST-JSON-ARGS,
12 # PYTHON-CHCEK, PYTHON-BIN)
14 m4_define([JSON_CHECK_POSITIVE_PY],
16 AT_KEYWORDS([json positive Python])
17 AT_SKIP_IF([test $5 = no])
18 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
19 AT_CAPTURE_FILE([input])
20 AT_CHECK([$6 $srcdir/test-json.py $4 input], [0], [stdout], [])
21 AT_CHECK([cat stdout], [0], [$3
25 m4_define([JSON_CHECK_POSITIVE_UCS4PY],
27 AT_KEYWORDS([json positive Python])
28 AT_SKIP_IF([test $HAVE_PYTHON = no])
29 AT_XFAIL_IF([$PYTHON -c "exit(len(u'\U00010800'))"; test $? -ne 1])
30 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
31 AT_CAPTURE_FILE([input])
32 AT_CHECK([$PYTHON $srcdir/test-json.py $4 input], [0], [stdout], [])
33 AT_CHECK([cat stdout], [0], [$3
37 m4_define([JSON_CHECK_POSITIVE],
38 [JSON_CHECK_POSITIVE_C([$1 - C], [$2], [$3], [$4])
39 JSON_CHECK_POSITIVE_PY([$1 - Python2], [$2], [$3], [$4],
40 [$HAVE_PYTHON], [$PYTHON])
41 JSON_CHECK_POSITIVE_PY([$1 - Python3], [$2], [$3], [$4],
42 [$HAVE_PYTHON3], [$PYTHON3])])
44 m4_define([JSON_CHECK_NEGATIVE_C],
46 AT_KEYWORDS([json negative])
47 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
48 AT_CAPTURE_FILE([input])
49 AT_CHECK([ovstest test-json $4 input], [1], [stdout], [])
50 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
54 # JSON_CHECK_NEGATIVE_PY(TITLE, INPUT, OUTPUT, TEST-JSON-ARGS,
55 # PYTHON-CHCEK, PYTHON-BIN)
57 m4_define([JSON_CHECK_NEGATIVE_PY],
59 AT_KEYWORDS([json negative Python])
60 AT_SKIP_IF([test $5 = no])
61 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
62 AT_CAPTURE_FILE([input])
63 AT_CHECK([$6 $srcdir/test-json.py $4 input], [1], [stdout], [])
64 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
68 m4_define([JSON_CHECK_NEGATIVE],
69 [JSON_CHECK_NEGATIVE_C([$1 - C], [$2], [$3], [$4])
70 JSON_CHECK_NEGATIVE_PY([$1 - Python2], [$2], [$3], [$4],
71 [$HAVE_PYTHON], [$PYTHON])
72 JSON_CHECK_NEGATIVE_PY([$1 - Python3], [$2], [$3], [$4],
73 [$HAVE_PYTHON3], [$PYTHON3])])
75 AT_BANNER([JSON -- arrays])
77 JSON_CHECK_POSITIVE([empty array], [[ [ ] ]], [[[]]])
78 JSON_CHECK_POSITIVE([single-element array], [[ [ 1 ] ]], [[[1]]])
79 JSON_CHECK_POSITIVE([2-element array], [[ [ 1, 2 ] ]], [[[1,2]]])
80 JSON_CHECK_POSITIVE([many-element array],
81 [[ [ 1, 2, 3, 4, 5 ] ]],
83 JSON_CHECK_NEGATIVE([missing comma], [[ [ 1, 2, 3 4, 5 ] ]],
84 [error: syntax error expecting '@:>@' or ','])
85 JSON_CHECK_NEGATIVE([trailing comma not allowed],
86 [[[1,2,]]], [error: syntax error expecting value])
87 JSON_CHECK_NEGATIVE([doubled comma not allowed],
88 [[[1,,2]]], [error: syntax error expecting value])
90 AT_BANNER([JSON -- strings])
92 JSON_CHECK_POSITIVE([empty string], [[[ "" ]]], [[[""]]])
93 JSON_CHECK_POSITIVE([1-character strings],
94 [[[ "a", "b", "c" ]]],
96 JSON_CHECK_POSITIVE([escape sequences],
97 [[[ " \" \\ \/ \b \f \n \r \t" ]]],
98 [[[" \" \\ / \b \f \n \r \t"]]])
99 JSON_CHECK_POSITIVE([Unicode escape sequences],
100 [[[ " \u0022 \u005c \u002F \u0008 \u000c \u000A \u000d \u0009" ]]],
101 [[[" \" \\ / \b \f \n \r \t"]]])
102 JSON_CHECK_POSITIVE_C([surrogate pairs - C],
103 [[["\ud834\udd1e"]]],
105 JSON_CHECK_POSITIVE_UCS4PY([surrogate pairs - Python],
106 [[["\ud834\udd1e"]]],
108 JSON_CHECK_NEGATIVE([a string by itself is not valid JSON], ["xxx"],
109 [error: syntax error at beginning of input])
110 JSON_CHECK_NEGATIVE([end of line in quoted string],
113 [error: U+000A must be escaped in quoted string])
114 JSON_CHECK_NEGATIVE([formfeed in quoted string],
116 [error: U+000C must be escaped in quoted string])
117 JSON_CHECK_NEGATIVE([bad escape in quoted string],
119 [error: bad escape \x])
120 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (1)],
122 [error: quoted string ends within \u escape])
123 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (2)],
125 [error: malformed \u escape])
126 JSON_CHECK_NEGATIVE([isolated leading surrogate not allowed],
128 [error: malformed escaped surrogate pair])
129 JSON_CHECK_NEGATIVE([surrogatess must paired properly],
130 [[["\ud834\u1234"]]],
131 [error: second half of escaped surrogate pair is not trailing surrogate])
132 JSON_CHECK_NEGATIVE([null bytes not allowed],
134 [error: null bytes not supported in quoted strings])
135 dnl Check for regression against a prior bug.
136 JSON_CHECK_POSITIVE([properly quoted backslash at end of string],
139 JSON_CHECK_NEGATIVE([stray backslash at end of string],
141 [error: unexpected end of input in quoted string])
143 AT_SETUP([end of input in quoted string - C])
144 AT_KEYWORDS([json negative])
145 AT_CHECK([printf '"xxx' | ovstest test-json -], [1],
146 [error: line 0, column 4, byte 4: unexpected end of input in quoted string
150 AT_SETUP([end of input in quoted string - Python])
151 AT_KEYWORDS([json negative Python])
152 AT_SKIP_IF([test $HAVE_PYTHON = no])
153 AT_CHECK([printf '"xxx' > input
154 $PYTHON $srcdir/test-json.py input], [1],
155 [error: line 0, column 4, byte 4: unexpected end of input in quoted string
159 AT_BANNER([JSON -- objects])
161 JSON_CHECK_POSITIVE([empty object], [[{ }]], [[{}]])
162 JSON_CHECK_POSITIVE([simple object],
163 [[{"b": 2, "a": 1, "c": 3}]],
164 [[{"a":1,"b":2,"c":3}]])
165 JSON_CHECK_NEGATIVE([bad value], [[{"a": }, "b": 2]],
166 [error: syntax error expecting value])
167 JSON_CHECK_NEGATIVE([missing colon], [[{"b": 2, "a" 1, "c": 3}]],
168 [error: syntax error parsing object expecting ':'])
169 JSON_CHECK_NEGATIVE([missing comma], [[{"b": 2 "a" 1, "c": 3}]],
170 [error: syntax error expecting '}' or ','])
171 JSON_CHECK_NEGATIVE([trailing comma not allowed],
172 [[{"b": 2, "a": 1, "c": 3, }]],
173 [[error: syntax error parsing object expecting string]])
174 JSON_CHECK_NEGATIVE([doubled comma not allowed],
175 [[{"b": 2, "a": 1,, "c": 3}]],
176 [[error: syntax error parsing object expecting string]])
177 JSON_CHECK_NEGATIVE([names must be strings],
179 [[error: syntax error parsing object expecting string]])
181 AT_BANNER([JSON -- literal names])
183 JSON_CHECK_POSITIVE([null], [[[ null ]]], [[[null]]])
184 JSON_CHECK_POSITIVE([false], [[[ false ]]], [[[false]]])
185 JSON_CHECK_POSITIVE([true], [[[ true ]]], [[[true]]])
186 JSON_CHECK_NEGATIVE([a literal by itself is not valid JSON], [null],
187 [error: syntax error at beginning of input])
188 JSON_CHECK_NEGATIVE([nullify is invalid], [[[ nullify ]]],
189 [error: invalid keyword 'nullify'])
190 JSON_CHECK_NEGATIVE([nubs is invalid], [[[ nubs ]]],
191 [error: invalid keyword 'nubs'])
192 JSON_CHECK_NEGATIVE([xxx is invalid], [[[ xxx ]]],
193 [error: invalid keyword 'xxx'])
195 AT_BANNER([JSON -- numbers])
198 [integers expressed as reals],
200 2.00000000000000000000000000000000000,
206 [[[1,2,200000,21234,2123,0,0]]])
209 [[[9223372036854775807, -9223372036854775808]]],
210 [[[9223372036854775807,-9223372036854775808]]])
212 [large integers expressed as reals],
213 [[[9223372036854775807.0, -9223372036854775808.0,
214 92233720.36854775807e11, -9.223372036854775808e18]]],
215 [[[9223372036854775807,-9223372036854775808,9223372036854775807,-9223372036854775808]]])
216 # It seems likely that the following test will fail on some system that
217 # rounds slightly differently in arithmetic or in printf, but I'd like
218 # to keep it this way until we run into such a system.
220 [large integers that overflow to reals],
221 [[[9223372036854775807000, -92233720368547758080000]]],
222 [[[9.22337203685478e+21,-9.22337203685478e+22]]])
226 [[[-0, -0.0, 1e-9999, -1e-9999]]],
231 [[[0.0, 1.0, 2.0, 3.0, 3.5, 81.250]]],
232 [[[0,1,2,3,3.5,81.25]]])
234 [scientific notation],
235 [[[1e3, 1E3, 2.5E2, 1e+3, 125e-3, 3.125e-2, 3125e-05, 1.525878906e-5]]],
236 [[[1000,1000,250,1000,0.125,0.03125,0.03125,1.525878906e-05]]])
237 # It seems likely that the following test will fail on some system that
238 # rounds slightly differently in arithmetic or in printf, but I'd like
239 # to keep it this way until we run into such a system.
242 [[[1.7976931348623157e+308, -1.7976931348623157e+308]]],
243 [[[1.79769313486232e+308,-1.79769313486232e+308]]])
247 [[[-0, -1.0, -2.0, -3.0, -3.5, -8.1250]]],
248 [[[0,-1,-2,-3,-3.5,-8.125]]])
250 [negative scientific notation],
251 [[[-1e3, -1E3, -2.5E2, -1e+3, -125e-3, -3.125e-2, -3125e-05, -1.525878906e-5]]],
252 [[[-1000,-1000,-250,-1000,-0.125,-0.03125,-0.03125,-1.525878906e-05]]])
254 [1e-9999 underflows to 0],
257 JSON_CHECK_NEGATIVE([a number by itself is not valid JSON], [1],
258 [error: syntax error at beginning of input])
260 [leading zeros not allowed],
262 [error: leading zeros not allowed])
266 [error: number outside valid range])
268 [exponent bigger than INT_MAX],
269 [[[1e9999999999999999999]]],
270 [error: exponent outside valid range])
272 [decimal point must be followed by digit],
274 [error: decimal point must be followed by digit])
276 [exponent must contain at least one digit (1)],
278 [error: exponent must contain at least one digit])
280 [exponent must contain at least one digit (2)],
282 [error: exponent must contain at least one digit])
284 [exponent must contain at least one digit (3)],
286 [error: exponent must contain at least one digit])
288 AT_BANNER([JSON -- RFC 4627 examples])
290 JSON_CHECK_POSITIVE([RFC 4267 object example],
295 "Title": "View from 15th Floor",
297 "Url": "http://www.example.com/image/481989943",
301 "IDs": [116, 943, 234, 38793]
304 [[{"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}}]])
306 JSON_CHECK_POSITIVE([RFC 4267 array example],
311 "Longitude": -122.3959,
313 "City": "SAN FRANCISCO",
320 "Latitude": 37.371991,
321 "Longitude": -122.026020,
329 [[[{"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"}]]])
331 AT_BANNER([JSON -- pathological cases])
333 JSON_CHECK_NEGATIVE([trailing garbage], [[[1]null]],
334 [error: trailing garbage at end of input])
335 JSON_CHECK_NEGATIVE([formfeeds are not valid white space],
336 [[[
\f]]], [error: invalid character U+000c])
337 JSON_CHECK_NEGATIVE([';' is not a valid token],
338 [;], [error: invalid character ';'])
339 JSON_CHECK_NEGATIVE([arrays nesting too deep],
340 [m4_for([i], [0], [1002], [1], [@<:@])dnl
341 m4_for([i], [0], [1002], [1], [@:>@])],
342 [error: input exceeds maximum nesting depth 1000])
343 JSON_CHECK_NEGATIVE([objects nesting too deep],
344 [m4_for([i], [0], [1002], [1], [{"x":])dnl
345 m4_for([i], [0], [1002], [1], [}])],
346 [error: input exceeds maximum nesting depth 1000])
348 AT_SETUP([input may not be empty])
349 AT_KEYWORDS([json negative])
350 AT_CHECK([ovstest test-json /dev/null], [1], [error: line 0, column 0, byte 0: empty input stream
354 AT_BANNER([JSON -- multiple inputs])
356 JSON_CHECK_POSITIVE([multiple adjacent objects], [[{}{}{}]], [[{}
361 JSON_CHECK_POSITIVE([multiple space-separated objects], [[{} {} {}]], [[{}
366 JSON_CHECK_POSITIVE([multiple objects on separate lines], [[{}
373 JSON_CHECK_POSITIVE([multiple objects and arrays], [[{}[]{}[]]], [[{}
379 JSON_CHECK_NEGATIVE([garbage between multiple objects], [[{}x{}]], [[{}
380 error: invalid keyword 'x'
383 JSON_CHECK_NEGATIVE([garbage after multiple objects], [[{}{}x]], [[{}
385 error: invalid keyword 'x']], [--multiple])