Debian Codegraph @

t/99_binary.t

raw
1 # copied over from JSON::XS and modified to use JSON
2
3 use strict;
4 use warnings;
5 use Test::More;
6 BEGIN { plan tests => 24576 };
7
8 BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; }
9
10 use JSON;
11
12
13 sub test($) {
14 my $js;
15
16 $js = JSON->new->allow_nonref(0)->utf8->ascii->shrink->encode ([$_[0]]);
17 ok ($_[0] eq ((decode_json $js)->[0]), " - 0");
18 $js = JSON->new->allow_nonref(0)->utf8->ascii->encode ([$_[0]]);
19 ok ($_[0] eq (JSON->new->utf8->shrink->decode($js))->[0], " - 1");
20
21 $js = JSON->new->allow_nonref(0)->utf8->shrink->encode ([$_[0]]);
22 ok ($_[0] eq ((decode_json $js)->[0]), " - 2");
23 $js = JSON->new->allow_nonref(1)->utf8->encode ([$_[0]]);
24 ok ($_[0] eq (JSON->new->utf8->shrink->decode($js))->[0], " - 3");
25
26 $js = JSON->new->allow_nonref(1)->ascii->encode ([$_[0]]);
27 ok ($_[0] eq JSON->new->decode ($js)->[0], " - 4");
28 $js = JSON->new->allow_nonref(0)->ascii->encode ([$_[0]]);
29 ok ($_[0] eq JSON->new->shrink->decode ($js)->[0], " - 5");
30
31 $js = JSON->new->allow_nonref(1)->shrink->encode ([$_[0]]);
32 ok ($_[0] eq JSON->new->decode ($js)->[0], " - 6");
33 $js = JSON->new->allow_nonref(0)->encode ([$_[0]]);
34 ok ($_[0] eq JSON->new->shrink->decode ($js)->[0], " - 7");
35 }
36
37 srand 0; # doesn't help too much, but its at least more deterministic
38
39 for (1..768) {
40 test join "", map chr ($_ & 255), 0..$_;
41 test join "", map chr rand 255, 0..$_;
42 test join "", map chr ($_ * 97 & ~0x4000), 0..$_;
43 test join "", map chr (rand (2**20) & ~0x800), 0..$_;
44 }
45