]> mj.ucw.cz Git - libucw.git/blob - ucw-json/json-test.t
JSON: Tests and bug fixes
[libucw.git] / ucw-json / json-test.t
1 # Tests for the JSON library
2 # (c) 2015 Martin Mares <mj@ucw.cz>
3
4 Name:   Empty input
5 Run:    ../obj/ucw-json/json-test -rw
6 Exit:   1
7 Err:    ERROR: Empty input at line 1:0
8
9 ### Literals ###
10
11 Name:   Null
12 In:     null
13 Out:    null
14
15 Name:   True
16 In:     true
17 Out:    true
18
19 Name:   False
20 In:     false
21 Out:    false
22
23 Name:   Invalid literal 1
24 In:     lomikel
25 Exit:   1
26 Err:    ERROR: Invalid literal name at line 1:8
27
28 Name:   Invalid literal 2
29 In:     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
30 Exit:   1
31 Err:    ERROR: Invalid literal name at line 1:101
32
33 ### Numbers ###
34
35 Name:   Plain number
36 In:     42
37 Out:    42
38
39 Name:   Negative number
40 In:     -42
41 Out:    -42
42
43 Name:   Zero number
44 In:     0
45 Out:    0
46
47 # The largest number guaranteed to be precise by RFC 7159
48 Name:   Large number
49 In:     9007199254740991
50 Out:    9007199254740991
51
52 Name:   Fractional number 1
53 In:     12345.54321
54 Out:    12345.54321
55
56 Name:   Fractional number 2
57 In:     0.333333333
58 Out:    0.333333333
59
60 Name:   Number in scientific notation 1
61 In:     3.14159e20
62 Out:    3.14159e+20
63
64 Name:   Number in scientific notation 2
65 In:     3.14159e+20
66 Out:    3.14159e+20
67
68 Name:   Number in scientific notation 3
69 In:     3.14159e-20
70 Out:    3.14159e-20
71
72 Name:   No leading zero allowed
73 In:     01234
74 Exit:   1
75 Err:    ERROR: Malformed number: leading zero at line 1:2
76
77 Name:   Bare sign is not a number
78 In:     -
79 Exit:   1
80 Err:    ERROR: Malformed number: just minus at line 1:2
81
82 Name:   No leading decimal point allowed
83 In:     .1234
84 Exit:   1
85 Err:    ERROR: Numbers must start with a digit at line 1:1
86
87 Name:   Digits after decimal point required
88 In:     1234.
89 Exit:   1
90 Err:    ERROR: Malformed number: no digits after decimal point at line 1:6
91
92 Name:   Exponent part must be non-empty 1
93 In:     1e
94 Exit:   1
95 Err:    ERROR: Malformed number: empty exponent at line 1:3
96
97 Name:   Exponent part must be non-empty 2
98 In:     1e+
99 Exit:   1
100 Err:    ERROR: Malformed number: empty exponent at line 1:4
101
102 Name:   Number out of range
103 In:     1e3000000
104 Exit:   1:
105 Err:    ERROR: Number out of range at line 1:10
106
107 ### Strings ###
108
109 Name:   Plain string
110 In:     "foo"
111 Out:    "foo"
112
113 Name:   Empty string
114 In:     ""
115 Out:    ""
116
117 Name:   UTF-8 string
118 In:     "šelmička"
119 Out:    "šelmička"
120
121 Name:   Unterminated string
122 In:     "infinity
123 Exit:   1
124 Err:    ERROR: Unterminated string at line 1:10
125
126 Name:   Multi-line string
127 In:     "infi
128         nity"
129 Exit:   1
130 Err:    ERROR: Unterminated string at line 1:6
131
132 # Some characters are written as \uXXXX on output, which is correct
133 Name:   Escaped characters
134 In:     "\"\\\/\b\f\n\r\t"
135 Out:    "\"\\/\u0008\u000c\n\r\t"
136
137 Name:   Improper escaped characters
138 In:     "\a"
139 Exit:   1
140 Err:    ERROR: Invalid backslash sequence in string at line 1:3
141
142 Name:   Unicode escapes
143 In:     "\u0041\u010d\u010D\u0001"
144 Out:    "Ačč\u0001"
145
146 Name:   Improper Unicode escapes 1
147 In:     "\u"
148 Exit:   1
149 Err:    ERROR: Invalid Unicode escape sequence at line 1:4
150
151 Name:   Improper Unicode escapes 2
152 In:     "\u
153 Exit:   1
154 Err:    ERROR: Invalid Unicode escape sequence at line 1:4
155
156 Name:   Improper Unicode escapes 3
157 In:     "\uABCZ"
158 Exit:   1
159 Err:    ERROR: Invalid Unicode escape sequence at line 1:7
160
161 ### Unicode magic ###
162
163 # TAB is forbidden
164 Name:   Control characters 1
165 Run:    ../obj/ucw-json/json-test -RW
166 In:     "<09>"
167 Exit:   1
168 Err:    ERROR: Invalid control character in string at line 1:2
169
170 # Surprisingly, DEL is not
171 Name:   Control characters 2
172 In:     "<7f>"
173 Out:    "<7f>"<0a>
174
175 # U+31234
176 Name:   UTF-8 outside BMP
177 In:     "<f0><b1><88><b4>"
178 Out:    "<f0><b1><88><b4>"<0a>
179
180 Name:   Private use characters in BMP
181 In:     "<ef><80><80>"
182 Exit:   1
183 Err:    ERROR: Invalid private-use character in string at line 1:2
184
185 Name:   UTF-8 outside BMP
186 In:     "<f0><b1><88><b4>"
187 Out:    "<f0><b1><88><b4>"<0a>
188
189 Name:   Private use characters outside BMP
190 In:     "<f3><b0><80><80>"
191 Exit:   1
192 Err:    ERROR: Invalid private-use character in string at line 1:2
193
194 # U+FF0000
195 Name:   UTF-8 outside UCS
196 In:     "<f8><bf><b0><80><80>"
197 Exit:   1
198 Err:    ERROR: Invalid non-Unicode character in string at line 1:2
199
200 # U+D800
201 Name:   UTF-8 surrogate 1
202 In:     "<ed><a0><80>"
203 Exit:   1
204 Err:    ERROR: Invalid surrogate character in string at line 1:2
205
206 # U+DC00
207 Name:   UTF-8 surrogate 2
208 In:     "<ed><b0><80>"
209 Exit:   1
210 Err:    ERROR: Invalid surrogate character in string at line 1:2
211
212 # U+FEFF
213 Name:   UTF-8 BOM
214 In:     <ef><bb><bf>
215 Exit:   1
216 Err:    ERROR: Misplaced byte-order mark, complain in Redmond at line 1:1
217
218 Name:   Escaped NUL
219 In:     "\u0000"
220 Exit:   1
221 Err:    ERROR: Zero bytes in strings are not supported at line 1:7
222
223 Name:   Escaped surrogate
224 In:     "\udaff\udcba"
225 Out:    "<f3><8f><b2><ba>"<0a>
226
227 Name:   Escaped surrogate malformation 1
228 In:     "\udaff"
229 Exit:   1
230 Err:    ERROR: Escaped high surrogate codepoint must be followed by a low surrogate codepoint at line 1:8
231
232 Name:   Escaped surrogate malformation 2
233 In:     "\udcff"
234 Exit:   1
235 Err:    ERROR: Invalid escaped surrogate codepoint at line 1:7
236
237 Name:   Escaped low private-use character
238 In:     "\uedac"
239 Exit:   1
240 Err:    ERROR: Invalid escaped private-use character at line 1:7
241
242 Name:   Escaped high private-use character
243 In:     "\udbff\udc00"
244 Exit:   1
245 Err:    ERROR: Invalid escaped private-use character at line 1:13
246
247 # Switch back to normal mode
248 Name:   Invalid ASCII character
249 Run:    ../obj/ucw-json/json-test -rw
250 In:     @
251 Exit:   1
252 Err:    ERROR: Invalid character at line 1:1
253
254 ### Arrays ###
255
256 Name:   Empty array
257 In:     []
258 Out:    []
259
260 Name:   One-element array
261 In:     [1]
262 Out:    [ 1 ]
263
264 Name:   Two-element array
265 In:     [1,2]
266 Out:    [ 1, 2 ]
267
268 Name:   Nested arrays
269 In:     [[1,2],["a","b"]]
270 Out:    [ [ 1, 2 ], [ "a", "b" ] ]
271
272 Name:   Multi-line array
273 In:     [
274         "a",    null,false
275         ,false
276         ]
277 Out:    [ "a", null, false, false ]