3 test_description='test json-writer JSON generation'
6 test_expect_success 'unit test of json-writer routines' '
7 test-tool json-writer -u
10 test_expect_success 'trivial object' '
11 cat >expect <<-\EOF &&
18 test-tool json-writer <input >actual &&
19 test_cmp expect actual
22 test_expect_success 'trivial array' '
23 cat >expect <<-\EOF &&
30 test-tool json-writer <input >actual &&
31 test_cmp expect actual
34 test_expect_success 'simple object' '
35 cat >expect <<-\EOF &&
36 {"a":"abc","b":42,"c":3.14,"d":true,"e":false,"f":null}
42 object-double c 2 3.140
48 test-tool json-writer <input >actual &&
49 test_cmp expect actual
52 test_expect_success 'simple array' '
53 cat >expect <<-\EOF &&
54 ["abc",42,3.14,true,false,null]
66 test-tool json-writer <input >actual &&
67 test_cmp expect actual
70 test_expect_success 'escape quoting string' '
71 cat >expect <<-\EOF &&
76 object-string a abc\def
79 test-tool json-writer <input >actual &&
80 test_cmp expect actual
83 test_expect_success 'escape quoting string 2' '
84 cat >expect <<-\EOF &&
89 object-string a abc"def
92 test-tool json-writer <input >actual &&
93 test_cmp expect actual
96 test_expect_success 'nested inline object' '
97 cat >expect <<-\EOF &&
98 {"a":"abc","b":42,"sub1":{"c":3.14,"d":true,"sub2":{"e":false,"f":null}}}
100 cat >input <<-\EOF &&
105 object-double c 2 3.140
114 test-tool json-writer <input >actual &&
115 test_cmp expect actual
118 test_expect_success 'nested inline array' '
119 cat >expect <<-\EOF &&
120 ["abc",42,[3.14,true,[false,null]]]
122 cat >input <<-\EOF &&
136 test-tool json-writer <input >actual &&
137 test_cmp expect actual
140 test_expect_success 'nested inline object and array' '
141 cat >expect <<-\EOF &&
142 {"a":"abc","b":42,"sub1":{"c":3.14,"d":true,"sub2":[false,null]}}
144 cat >input <<-\EOF &&
149 object-double c 2 3.140
158 test-tool json-writer <input >actual &&
159 test_cmp expect actual
162 test_expect_success 'nested inline object and array 2' '
163 cat >expect <<-\EOF &&
164 {"a":"abc","b":42,"sub1":{"c":3.14,"d":true,"sub2":[false,{"g":0,"h":1},null]}}
166 cat >input <<-\EOF &&
171 object-double c 2 3.140
184 test-tool json-writer <input >actual &&
185 test_cmp expect actual
188 test_expect_success 'pretty nested inline object and array 2' '
189 sed -e "s/^|//" >expect <<-\EOF &&
207 cat >input <<-\EOF &&
212 object-double c 2 3.140
225 test-tool json-writer -p <input >actual &&
226 test_cmp expect actual
229 test_expect_success 'inline object with no members' '
230 cat >expect <<-\EOF &&
231 {"a":"abc","empty":{},"b":42}
233 cat >input <<-\EOF &&
241 test-tool json-writer <input >actual &&
242 test_cmp expect actual
245 test_expect_success 'inline array with no members' '
246 cat >expect <<-\EOF &&
247 {"a":"abc","empty":[],"b":42}
249 cat >input <<-\EOF &&
257 test-tool json-writer <input >actual &&
258 test_cmp expect actual
261 test_expect_success 'larger empty example' '
262 cat >expect <<-\EOF &&
263 {"a":"abc","empty":[{},{},{},[],{}],"b":42}
265 cat >input <<-\EOF &&
283 test-tool json-writer <input >actual &&
284 test_cmp expect actual
287 test_lazy_prereq PERLJSON '
288 perl -MJSON -e "exit 0"
291 # As a sanity check, ask Perl to parse our generated JSON and recursively
292 # dump the resulting data in sorted order. Confirm that that matches our
294 test_expect_success PERLJSON 'parse JSON using Perl' '
295 cat >expect <<-\EOF &&
301 row[0].sub1.sub2 array
302 row[0].sub1.sub2[0] 0
303 row[0].sub1.sub2[1] hash
304 row[0].sub1.sub2[1].g 0
305 row[0].sub1.sub2[1].h 1
306 row[0].sub1.sub2[2] null
308 cat >input <<-\EOF &&
313 object-double c 2 3.140
326 test-tool json-writer <input >output.json &&
327 perl "$TEST_DIRECTORY"/t0019/parse_json.perl <output.json >actual &&
328 test_cmp expect actual