ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/99_binary.t
Revision: 1.1
Committed: Sun Jul 1 22:20:00 2007 UTC (17 years ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-1_51, rel-1_53, rel-2_0, rel-1_5, rel-1_4, rel-1_43, rel-1_41
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 ((from_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 ((from_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 leats 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 }