ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/18_json_checker.t
Revision: 1.2
Committed: Thu Nov 15 20:49:12 2018 UTC (5 years, 6 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_0, rel-4_01, rel-4_03, rel-4_02, rel-4_0_00, HEAD
Changes since 1.1: +1 -3 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     # use the testsuite from http://www.json.org/JSON_checker/
4     # except for fail18.json, as we do not support a depth of 20 (but 16 and 32).
5    
6     use strict;
7     no warnings;
8     use Test::More;
9 root 1.2 BEGIN { plan tests => 38 };
10 root 1.1
11     use JSON::XS;
12    
13     # emulate JSON_checker default config
14     my $json = JSON::XS->new->utf8->max_depth(32)->canonical;
15    
16     binmode DATA;
17    
18     for (;;) {
19     $/ = "\n# ";
20     chomp (my $test = <DATA>)
21     or last;
22     $/ = "\n";
23     my $name = <DATA>;
24    
25     if (my $perl = eval { $json->decode ($test) }) {
26     ok ($name =~ /^pass/, $name);
27     is ($json->encode ($json->decode ($json->encode ($perl))), $json->encode ($perl));
28     } else {
29     ok ($name =~ /^fail/, "$name ($@)");
30     }
31     }
32    
33     __DATA__
34     {"Extra value after close": true} "misplaced quoted value"
35     # fail10.json
36     {"Illegal expression": 1 + 2}
37     # fail11.json
38     {"Illegal invocation": alert()}
39     # fail12.json
40     {"Numbers cannot have leading zeroes": 013}
41     # fail13.json
42     {"Numbers cannot be hex": 0x14}
43     # fail14.json
44     ["Illegal backslash escape: \x15"]
45     # fail15.json
46     [\naked]
47     # fail16.json
48     ["Illegal backslash escape: \017"]
49     # fail17.json
50     [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
51     # fail18.json
52     {"Missing colon" null}
53     # fail19.json
54     ["Unclosed array"
55     # fail2.json
56     {"Double colon":: null}
57     # fail20.json
58     {"Comma instead of colon", null}
59     # fail21.json
60     ["Colon instead of comma": false]
61     # fail22.json
62     ["Bad value", truth]
63     # fail23.json
64     ['single quote']
65     # fail24.json
66     [" tab character in string "]
67     # fail25.json
68     ["tab\ character\ in\ string\ "]
69     # fail26.json
70     ["line
71     break"]
72     # fail27.json
73     ["line\
74     break"]
75     # fail28.json
76     [0e]
77     # fail29.json
78     {unquoted_key: "keys must be quoted"}
79     # fail3.json
80     [0e+]
81     # fail30.json
82     [0e+-1]
83     # fail31.json
84     {"Comma instead if closing brace": true,
85     # fail32.json
86     ["mismatch"}
87     # fail33.json
88     ["extra comma",]
89     # fail4.json
90     ["double extra comma",,]
91     # fail5.json
92     [ , "<-- missing value"]
93     # fail6.json
94     ["Comma after the close"],
95     # fail7.json
96     ["Extra close"]]
97     # fail8.json
98     {"Extra comma": true,}
99     # fail9.json
100     [
101     "JSON Test Pattern pass1",
102     {"object with 1 member":["array with 1 element"]},
103     {},
104     [],
105     -42,
106     true,
107     false,
108     null,
109     {
110     "integer": 1234567890,
111     "real": -9876.543210,
112     "e": 0.123456789e-12,
113     "E": 1.234567890E+34,
114     "": 23456789012E66,
115     "zero": 0,
116     "one": 1,
117     "space": " ",
118     "quote": "\"",
119     "backslash": "\\",
120     "controls": "\b\f\n\r\t",
121     "slash": "/ & \/",
122     "alpha": "abcdefghijklmnopqrstuvwyz",
123     "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
124     "digit": "0123456789",
125     "0123456789": "digit",
126     "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
127     "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
128     "true": true,
129     "false": false,
130     "null": null,
131     "array":[ ],
132     "object":{ },
133     "address": "50 St. James Street",
134     "url": "http://www.JSON.org/",
135     "comment": "// /* <!-- --",
136     "# -- --> */": " ",
137     " s p a c e d " :[1,2 , 3
138    
139     ,
140    
141     4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
142     "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
143     "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
144     "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
145     : "A key can be any string"
146     },
147     0.5 ,98.6
148     ,
149     99.44
150     ,
151    
152     1066,
153     1e1,
154     0.1e1,
155     1e-1,
156     1e00,2e+00,2e-00
157     ,"rosebud"]
158     # pass1.json
159     [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
160     # pass2.json
161     {
162     "JSON Test Pattern pass3": {
163     "The outermost value": "must be an object or array.",
164     "In this test": "It is an object."
165     }
166     }
167    
168     # pass3.json