2 # use the testsuite from http://www.json.org/JSON_checker/
3 # except for fail18.json, as we do not support a depth of 20 (but 16 and 32).
5 # copied over from JSON::XS and modified to use JSON
11 BEGIN { plan tests => 39 };
12 BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; }
16 my $json = JSON->new->utf8->max_depth(32)->canonical;
23 chomp (my $test = <DATA>)
27 if (my $perl = eval { $json->decode ($test) }) {
28 ok ($name =~ /^pass/, $name);
29 #print $json->encode ($perl), "\n";
30 is ($json->encode ($json->decode ($json->encode ($perl))), $json->encode ($perl));
32 ok ($name =~ /^fail/, "$name ($@)");
38 "A JSON payload should be an object or array, not a string."
40 {"Extra value after close": true} "misplaced quoted value"
42 {"Illegal expression": 1 + 2}
44 {"Illegal invocation": alert()}
46 {"Numbers cannot have leading zeroes": 013}
48 {"Numbers cannot be hex": 0x14}
50 ["Illegal backslash escape: \x15"]
54 ["Illegal backslash escape: \017"]
56 [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
58 {"Missing colon" null}
62 {"Double colon":: null}
64 {"Comma instead of colon", null}
66 ["Colon instead of comma": false]
72 [" tab character in string "]
74 ["tab\ character\ in\ string\ "]
84 {unquoted_key: "keys must be quoted"}
90 {"Comma instead if closing brace": true,
96 ["double extra comma",,]
98 [ , "<-- missing value"]
100 ["Comma after the close"],
104 {"Extra comma": true,}
107 "JSON Test Pattern pass1",
108 {"object with 1 member":["array with 1 element"]},
116 "integer": 1234567890,
117 "real": -9876.543210,
118 "e": 0.123456789e-12,
119 "E": 1.234567890E+34,
126 "controls": "\b\f\n\r\t",
128 "alpha": "abcdefghijklmnopqrstuvwyz",
129 "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
130 "digit": "0123456789",
131 "0123456789": "digit",
132 "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
133 "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
139 "address": "50 St. James Street",
140 "url": "http://www.JSON.org/",
141 "comment": "// /* <!-- --",
143 " s p a c e d " :[1,2 , 3
147 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
148 "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
149 "quotes": "" \u0022 %22 0x22 034 "",
150 "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
151 : "A key can be any string"
165 [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
168 "JSON Test Pattern pass3": {
169 "The outermost value": "must be an object or array.",
170 "In this test": "It is an object."