ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/03_types.t
Revision: 1.4
Committed: Wed Jun 6 14:52:49 2007 UTC (17 years ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-1_24, rel-1_23
Changes since 1.3: +14 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 BEGIN { $| = 1; print "1..67\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]);
33
34 for $v (1, 2, 3, 5, -1, -2, -3, -4, 100, 1000, 10000, -999, -88, -7, 7, 88, 999, -1e5, 1e6, 1e7, 1e8) {
35 ok ($v == ((from_json "[$v]")->[0]));
36 ok ($v == ((from_json to_json [$v])->[0]));
37 }
38
39 ok (30123 == ((from_json to_json [30123])->[0]));
40 ok (32123 == ((from_json to_json [32123])->[0]));
41 ok (32456 == ((from_json to_json [32456])->[0]));
42 ok (32789 == ((from_json to_json [32789])->[0]));
43 ok (32767 == ((from_json to_json [32767])->[0]));
44 ok (32768 == ((from_json to_json [32768])->[0]));
45