1 # copied over from JSON::XS and modified to use JSON 2 3 use Test::More; 4 use strict; 5 BEGIN { plan tests => 2432 }; 6 7 BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; } 8 9 BEGIN { 10 use lib qw(t); 11 use _unicode_handling; 12 } 13 14 use JSON; 15 16 SKIP: { 17 skip "UNICODE handling is disabale.", 2432 unless $JSON::can_handle_UTF16_and_utf8; 18 19 sub test($) { 20 my $js; 21 22 $js = JSON->new->allow_nonref(0)->utf8->ascii->shrink->encode ([$_[0]]); 23 ok ($_[0] eq ((decode_json $js)->[0])); 24 $js = JSON->new->allow_nonref(0)->utf8->ascii->encode ([$_[0]]); 25 ok ($_[0] eq (JSON->new->utf8->shrink->decode($js))->[0]); 26 27 $js = JSON->new->allow_nonref(0)->utf8->shrink->encode ([$_[0]]); 28 ok ($_[0] eq ((decode_json $js)->[0])); 29 $js = JSON->new->allow_nonref(1)->utf8->encode ([$_[0]]); 30 ok ($_[0] eq (JSON->new->utf8->shrink->decode($js))->[0]); 31 32 $js = JSON->new->allow_nonref(1)->ascii->encode ([$_[0]]); 33 ok ($_[0] eq JSON->new->decode ($js)->[0]); 34 $js = JSON->new->allow_nonref(0)->ascii->encode ([$_[0]]); 35 ok ($_[0] eq JSON->new->shrink->decode ($js)->[0]); 36 37 $js = JSON->new->allow_nonref(1)->shrink->encode ([$_[0]]); 38 ok ($_[0] eq JSON->new->decode ($js)->[0]); 39 $js = JSON->new->allow_nonref(0)->encode ([$_[0]]); 40 ok ($_[0] eq JSON->new->shrink->decode ($js)->[0]); 41 } 42 43 srand 0; # doesn't help too much, but its at least more deterministic 44 45 #for (1..768) { 46 for (1..64, 125..129, 255..257, 512, 704, 736, 768) { 47 test join "", map chr ($_ & 255), 0..$_; 48 test join "", map chr rand 255, 0..$_; 49 test join "", map chr ($_ * 97 & ~0x4000), 0..$_; 50 test join "", map chr (rand (2**20) & ~0x800), 0..$_; 51 } 52 53 } 54