ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/99_binary.t
Revision: 1.2
Committed: Wed Dec 5 10:59:31 2007 UTC (16 years, 6 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-2_01, rel-2_222, rel-2_2, rel-2_1, rel-2_231, rel-2_21, rel-2_2222, rel-2_23, rel-2_22
Changes since 1.1: +2 -2 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 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 }