2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2012, Joyent, Inc. All rights reserved.
17 * General functional tests of JSON parser for json().
20 #
pragma D option quiet
21 #
pragma D option strsize
=1k
24 printf("\ntst |%s|\n", name
)
25 #define
IN2(vala
, valb
) \
26 in = strjoin(vala
, valb
); \
27 printf("in |%s|\n", in)
30 printf("in |%s|\n", in)
33 printf("sel |%s|\nout |%s|\n", ss
, \
34 out != NULL ?
out : "<NULL>")
42 TST("one-element array: integer");
49 TST("one-element array: hex integer (not in spec, not supported)");
53 TST("one-element array: float");
57 TST("one-element array: float + exponent");
61 TST("one-element array: integer + whitespace");
65 TST("one-element array: integer + exponent + whitespace");
66 IN("[ \t \t 16E10 \t ]");
69 TST("one-element array: string");
73 TST("alternative first-element indexing");
80 TST("one-element array: object");
81 IN("[ { \"first\": true, \"second\": false }]");
86 TST("many-element array: integers");
87 IN("[0,1,1,2,3,5,8,13,21,34,55,89,144,233,377]");
88 SEL("10"); /* F(10) = 55 */
89 SEL("14"); /* F(14) = 377 */
92 TST("many-element array: multiple types");
93 IN2("[\"string\",32,true,{\"a\":9,\"b\":false},100.3e10,false,200.5,",
94 "{\"key\":\"val\"},null]");
108 SEL("7.key.notobject");
113 TST("many-element array: multiple types + whitespace");
114 IN2("\n[\t\"string\" ,\t32 , true\t,\t {\"a\": 9,\t\"b\": false},\t\t",
115 "100.3e10, false, 200.5,{\"key\" \t:\n \"val\"},\t\t null ]\t\t");
129 SEL("7.key.notobject");
134 TST("two-element array: various string escape codes");
135 IN2("[\"abcd \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u0000 \\uf00F \", ",
140 TST("three-element array: broken escape code");
141 IN("[\"fine here\", \"dodgey \\u00AZ\", \"wont get here\"]");
146 TST("nested objects");
147 IN2("{ \"top\": { \"mid\" : { \"legs\": \"feet\" }, \"number\": 9, ",
148 "\"array\":[0,1,{\"a\":true,\"bb\":[1,2,false,{\"x\":\"yz\"}]}]}}");
154 SEL("top.mid.number");
155 SEL("top.mid.array");
161 SEL("top.array[2].a");
162 SEL("top.array[2].b");
163 SEL("top.array[2].bb");
164 SEL("top.array[2].bb[0]");
165 SEL("top.array[2].bb[1]");
166 SEL("top.array[2].bb[2]");
167 SEL("top.array[2].bb[3]");
168 SEL("top.array[2].bb[3].x");
169 SEL("top.array[2].bb[3].x.nofurther");
170 SEL("top.array[2].bb[4]");