3 test_description
='test json-writer JSON generation'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'unit test of json-writer routines' '
9 test-tool json-writer -u
12 test_expect_success
'trivial object' '
13 cat >expect <<-\EOF &&
20 test-tool json-writer <input >actual &&
21 test_cmp expect actual
24 test_expect_success
'trivial array' '
25 cat >expect <<-\EOF &&
32 test-tool json-writer <input >actual &&
33 test_cmp expect actual
36 test_expect_success
'simple object' '
37 cat >expect <<-\EOF &&
38 {"a":"abc","b":42,"c":3.14,"d":true,"e":false,"f":null}
44 object-double c 2 3.140
50 test-tool json-writer <input >actual &&
51 test_cmp expect actual
54 test_expect_success
'simple array' '
55 cat >expect <<-\EOF &&
56 ["abc",42,3.14,true,false,null]
68 test-tool json-writer <input >actual &&
69 test_cmp expect actual
72 test_expect_success
'escape quoting string' '
73 cat >expect <<-\EOF &&
78 object-string a abc\def
81 test-tool json-writer <input >actual &&
82 test_cmp expect actual
85 test_expect_success
'escape quoting string 2' '
86 cat >expect <<-\EOF &&
91 object-string a abc"def
94 test-tool json-writer <input >actual &&
95 test_cmp expect actual
98 test_expect_success
'nested inline object' '
99 cat >expect <<-\EOF &&
100 {"a":"abc","b":42,"sub1":{"c":3.14,"d":true,"sub2":{"e":false,"f":null}}}
102 cat >input <<-\EOF &&
107 object-double c 2 3.140
116 test-tool json-writer <input >actual &&
117 test_cmp expect actual
120 test_expect_success
'nested inline array' '
121 cat >expect <<-\EOF &&
122 ["abc",42,[3.14,true,[false,null]]]
124 cat >input <<-\EOF &&
138 test-tool json-writer <input >actual &&
139 test_cmp expect actual
142 test_expect_success
'nested inline object and array' '
143 cat >expect <<-\EOF &&
144 {"a":"abc","b":42,"sub1":{"c":3.14,"d":true,"sub2":[false,null]}}
146 cat >input <<-\EOF &&
151 object-double c 2 3.140
160 test-tool json-writer <input >actual &&
161 test_cmp expect actual
164 test_expect_success
'nested inline object and array 2' '
165 cat >expect <<-\EOF &&
166 {"a":"abc","b":42,"sub1":{"c":3.14,"d":true,"sub2":[false,{"g":0,"h":1},null]}}
168 cat >input <<-\EOF &&
173 object-double c 2 3.140
186 test-tool json-writer <input >actual &&
187 test_cmp expect actual
190 test_expect_success
'pretty nested inline object and array 2' '
191 sed -e "s/^|//" >expect <<-\EOF &&
209 cat >input <<-\EOF &&
214 object-double c 2 3.140
227 test-tool json-writer -p <input >actual &&
228 test_cmp expect actual
231 test_expect_success
'inline object with no members' '
232 cat >expect <<-\EOF &&
233 {"a":"abc","empty":{},"b":42}
235 cat >input <<-\EOF &&
243 test-tool json-writer <input >actual &&
244 test_cmp expect actual
247 test_expect_success
'inline array with no members' '
248 cat >expect <<-\EOF &&
249 {"a":"abc","empty":[],"b":42}
251 cat >input <<-\EOF &&
259 test-tool json-writer <input >actual &&
260 test_cmp expect actual
263 test_expect_success
'larger empty example' '
264 cat >expect <<-\EOF &&
265 {"a":"abc","empty":[{},{},{},[],{}],"b":42}
267 cat >input <<-\EOF &&
285 test-tool json-writer <input >actual &&
286 test_cmp expect actual
289 test_lazy_prereq PERLJSON
'
290 perl -MJSON -e "exit 0"
293 # As a sanity check, ask Perl to parse our generated JSON and recursively
294 # dump the resulting data in sorted order. Confirm that that matches our
296 test_expect_success PERLJSON
'parse JSON using Perl' '
297 cat >expect <<-\EOF &&
303 row[0].sub1.sub2 array
304 row[0].sub1.sub2[0] 0
305 row[0].sub1.sub2[1] hash
306 row[0].sub1.sub2[1].g 0
307 row[0].sub1.sub2[1].h 1
308 row[0].sub1.sub2[2] null
310 cat >input <<-\EOF &&
315 object-double c 2 3.140
328 test-tool json-writer <input >output.json &&
329 perl "$TEST_DIRECTORY"/t0019/parse_json.perl <output.json >actual &&
330 test_cmp expect actual