1 |
BEGIN { $| = 1; print "1..19\n"; } |
2 |
|
3 |
use utf8; |
4 |
use JSON::XS; |
5 |
|
6 |
our $test; |
7 |
sub ok($) { |
8 |
print $_[0] ? "" : "not ", "ok ", ++$test, "\n"; |
9 |
} |
10 |
|
11 |
ok (!defined JSON::XS->new->allow_nonref (1)->decode ('null')); |
12 |
ok (JSON::XS->new->allow_nonref (1)->decode ('true') == 1); |
13 |
ok (JSON::XS->new->allow_nonref (1)->decode ('false') == 0); |
14 |
|
15 |
ok (JSON::XS->new->allow_nonref (1)->decode ('5') == 5); |
16 |
ok (JSON::XS->new->allow_nonref (1)->decode ('-5') == -5); |
17 |
ok (JSON::XS->new->allow_nonref (1)->decode ('5e1') == 50); |
18 |
ok (JSON::XS->new->allow_nonref (1)->decode ('-333e+0') == -333); |
19 |
ok (JSON::XS->new->allow_nonref (1)->decode ('2.5') == 2.5); |
20 |
|
21 |
ok (JSON::XS->new->allow_nonref (1)->decode ('""') eq ""); |
22 |
ok ('[1,2,3,4]' eq to_json from_json ('[1,2, 3,4]')); |
23 |
ok ('[{},[],[],{}]' eq to_json from_json ('[{},[], [ ] ,{ }]')); |
24 |
ok ('[{"1":[5]}]' eq to_json [{1 => [5]}]); |
25 |
ok ('{"1":2,"3":4}' eq JSON::XS->new->canonical (1)->encode (from_json '{ "1" : 2, "3" : 4 }')); |
26 |
ok ('{"1":2,"3":1.2}' eq JSON::XS->new->canonical (1)->encode (from_json '{ "1" : 2, "3" : 1.2 }')); |
27 |
|
28 |
ok ('[true]' eq to_json [JSON::XS::true]); |
29 |
ok ('[false]' eq to_json [JSON::XS::false]); |
30 |
ok ('[true]' eq to_json [\1]); |
31 |
ok ('[false]' eq to_json [\0]); |
32 |
ok ('[null]' eq to_json [undef]); |