ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/99_binary.t
Revision: 1.3
Committed: Sat Jan 10 20:05:40 2009 UTC (15 years, 5 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_0, rel-3_0, rel-4_01, rel-4_03, rel-4_02, rel-2_3, rel-4_0_00, rel-2_34, rel-2_32, rel-2_33, rel-2_31, rel-2_2311, rel-3_01, rel-3_02, rel-3_03, rel-3_04, rel-2_232, rel-2_29, rel-2_28, rel-2_25, rel-2_24, rel-2_27, rel-2_26, HEAD
Changes since 1.2: +2 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 BEGIN { $| = 1; print "1..24576\n"; }
2
3 use JSON::XS;
4
5 our $test;
6 sub ok($;$) {
7 print $_[0] ? "" : "not ", "ok ", ++$test, " - $_[1]\n";
8 }
9
10 sub test($) {
11 my $js;
12
13 $js = JSON::XS->new->allow_nonref(0)->utf8->ascii->shrink->encode ([$_[0]]);
14 ok ($_[0] eq ((decode_json $js)->[0]), 0);
15 $js = JSON::XS->new->allow_nonref(0)->utf8->ascii->encode ([$_[0]]);
16 ok ($_[0] eq (JSON::XS->new->utf8->shrink->decode($js))->[0], 1);
17
18 $js = JSON::XS->new->allow_nonref(0)->utf8->shrink->encode ([$_[0]]);
19 ok ($_[0] eq ((decode_json $js)->[0]), 2);
20 $js = JSON::XS->new->allow_nonref(1)->utf8->encode ([$_[0]]);
21 ok ($_[0] eq (JSON::XS->new->utf8->shrink->decode($js))->[0], 3);
22
23 $js = JSON::XS->new->allow_nonref(1)->ascii->encode ([$_[0]]);
24 ok ($_[0] eq JSON::XS->new->decode ($js)->[0], 4);
25 $js = JSON::XS->new->allow_nonref(0)->ascii->encode ([$_[0]]);
26 ok ($_[0] eq JSON::XS->new->shrink->decode ($js)->[0], 5);
27
28 $js = JSON::XS->new->allow_nonref(1)->shrink->encode ([$_[0]]);
29 ok ($_[0] eq JSON::XS->new->decode ($js)->[0], 6);
30 $js = JSON::XS->new->allow_nonref(0)->encode ([$_[0]]);
31 ok ($_[0] eq JSON::XS->new->shrink->decode ($js)->[0], 7);
32 }
33
34 srand 0; # doesn't help too much, but its at least more deterministic
35
36 for (1..768) {
37 test join "", map chr ($_ & 255), 0..$_;
38 test join "", map chr rand 255, 0..$_;
39 test join "", map chr ($_ * 97 & ~0x4000), 0..$_;
40 test join "", map chr (rand (2**20) & ~0x800), 0..$_;
41 }
42