1*f2a19305Safresh1# copied over from JSON::XS and modified to use JSON::PP
2*f2a19305Safresh1
3*f2a19305Safresh1use strict;
4*f2a19305Safresh1use warnings;
5*f2a19305Safresh1use Test::More;
6*f2a19305Safresh1BEGIN {
7*f2a19305Safresh1    if (defined(my $n= $ENV{JSONPP_CHUNK})) {
8*f2a19305Safresh1        $ENV{JSONPP_FROM}= 1 + $n * 48;
9*f2a19305Safresh1        $ENV{JSONPP_TO}= (1 + $n) * 48;
10*f2a19305Safresh1    }
11*f2a19305Safresh1    $ENV{JSONPP_FROM} = 1 unless defined $ENV{JSONPP_FROM};
12*f2a19305Safresh1    $ENV{JSONPP_TO}   = 768 unless defined $ENV{JSONPP_TO};
13*f2a19305Safresh1}
14*f2a19305Safresh1BEGIN { plan tests => 32 * ($ENV{JSONPP_TO} - $ENV{JSONPP_FROM} + 1) };
15*f2a19305Safresh1
16*f2a19305Safresh1BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
17*f2a19305Safresh1
18*f2a19305Safresh1use JSON::PP;
19*f2a19305Safresh1
20*f2a19305Safresh1
21*f2a19305Safresh1sub test($) {
22*f2a19305Safresh1   my $js;
23*f2a19305Safresh1
24*f2a19305Safresh1   $js = JSON::PP->new->allow_nonref(0)->utf8->ascii->shrink->encode ([$_[0]]);
25*f2a19305Safresh1   ok ($_[0] eq ((decode_json $js)->[0]), " - 0");
26*f2a19305Safresh1   $js = JSON::PP->new->allow_nonref(0)->utf8->ascii->encode ([$_[0]]);
27*f2a19305Safresh1   ok ($_[0] eq (JSON::PP->new->utf8->shrink->decode($js))->[0], " - 1");
28*f2a19305Safresh1
29*f2a19305Safresh1   $js = JSON::PP->new->allow_nonref(0)->utf8->shrink->encode ([$_[0]]);
30*f2a19305Safresh1   ok ($_[0] eq ((decode_json $js)->[0]), " - 2");
31*f2a19305Safresh1   $js = JSON::PP->new->allow_nonref(1)->utf8->encode ([$_[0]]);
32*f2a19305Safresh1   ok ($_[0] eq (JSON::PP->new->utf8->shrink->decode($js))->[0], " - 3");
33*f2a19305Safresh1
34*f2a19305Safresh1   $js = JSON::PP->new->allow_nonref(1)->ascii->encode ([$_[0]]);
35*f2a19305Safresh1   ok ($_[0] eq JSON::PP->new->decode ($js)->[0], " - 4");
36*f2a19305Safresh1   $js = JSON::PP->new->allow_nonref(0)->ascii->encode ([$_[0]]);
37*f2a19305Safresh1   ok ($_[0] eq JSON::PP->new->shrink->decode ($js)->[0], " - 5");
38*f2a19305Safresh1
39*f2a19305Safresh1   $js = JSON::PP->new->allow_nonref(1)->shrink->encode ([$_[0]]);
40*f2a19305Safresh1   ok ($_[0] eq JSON::PP->new->decode ($js)->[0], " - 6");
41*f2a19305Safresh1   $js = JSON::PP->new->allow_nonref(0)->encode ([$_[0]]);
42*f2a19305Safresh1   ok ($_[0] eq JSON::PP->new->shrink->decode ($js)->[0], " - 7");
43*f2a19305Safresh1}
44*f2a19305Safresh1
45*f2a19305Safresh1srand $ENV{JSONPP_FROM}; # doesn't help too much, but its at least more deterministic
46*f2a19305Safresh1
47*f2a19305Safresh1for ($ENV{JSONPP_FROM} .. $ENV{JSONPP_TO}) {
48*f2a19305Safresh1   test join "", map chr ($_ & 255), 0..$_;
49*f2a19305Safresh1   test join "", map chr rand 255, 0..$_;
50*f2a19305Safresh1   test join "", map chr ($_ * 97 & ~0x4000), 0..$_;
51*f2a19305Safresh1   test join "", map chr (rand (2**20) & ~0x800), 0..$_;
52*f2a19305Safresh1}
53