diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2013-03-25 20:09:46 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2013-03-25 20:09:46 +0000 |
commit | 6eda9412f8dc717200dec22c57afdd2a46edfa8e (patch) | |
tree | c835d11c3e3f90de6a8561320ec54f077bfd358f /gnu/usr.bin/perl/cpan/JSON-PP/t/099_binary.t | |
parent | 19adbb7d6dbd1516758cad91978165088a19e917 (diff) |
import perl 5.16.3 from CPAN - worked on by Andrew Fresh and myself
Diffstat (limited to 'gnu/usr.bin/perl/cpan/JSON-PP/t/099_binary.t')
-rw-r--r-- | gnu/usr.bin/perl/cpan/JSON-PP/t/099_binary.t | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gnu/usr.bin/perl/cpan/JSON-PP/t/099_binary.t b/gnu/usr.bin/perl/cpan/JSON-PP/t/099_binary.t new file mode 100644 index 00000000000..56f23297fa0 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/JSON-PP/t/099_binary.t @@ -0,0 +1,53 @@ +# copied over from JSON::PP::XS and modified to use JSON::PP + +use Test::More; +use strict; +BEGIN { plan tests => 2432 }; + +BEGIN { $ENV{PERL_JSON_BACKEND} = 0; } + +BEGIN { + use lib qw(t); + use _unicode_handling; +} + +use JSON::PP; + +SKIP: { + skip "UNICODE handling is disabale.", 2432 unless $JSON::PP::can_handle_UTF16_and_utf8; + +sub test($) { + my $js; + + $js = JSON::PP->new->allow_nonref(0)->utf8->ascii->shrink->encode ([$_[0]]); + ok ($_[0] eq ((decode_json $js)->[0])); + $js = JSON::PP->new->allow_nonref(0)->utf8->ascii->encode ([$_[0]]); + ok ($_[0] eq (JSON::PP->new->utf8->shrink->decode($js))->[0]); + + $js = JSON::PP->new->allow_nonref(0)->utf8->shrink->encode ([$_[0]]); + ok ($_[0] eq ((decode_json $js)->[0])); + $js = JSON::PP->new->allow_nonref(1)->utf8->encode ([$_[0]]); + ok ($_[0] eq (JSON::PP->new->utf8->shrink->decode($js))->[0]); + + $js = JSON::PP->new->allow_nonref(1)->ascii->encode ([$_[0]]); + ok ($_[0] eq JSON::PP->new->decode ($js)->[0]); + $js = JSON::PP->new->allow_nonref(0)->ascii->encode ([$_[0]]); + ok ($_[0] eq JSON::PP->new->shrink->decode ($js)->[0]); + + $js = JSON::PP->new->allow_nonref(1)->shrink->encode ([$_[0]]); + ok ($_[0] eq JSON::PP->new->decode ($js)->[0]); + $js = JSON::PP->new->allow_nonref(0)->encode ([$_[0]]); + ok ($_[0] eq JSON::PP->new->shrink->decode ($js)->[0]); +} + +srand 0; # doesn't help too much, but its at leats more deterministic + +#for (1..768) { +for (1..64, 125..129, 255..257, 512, 704, 736, 768) { + test join "", map chr ($_ & 255), 0..$_; + test join "", map chr rand 255, 0..$_; + test join "", map chr ($_ * 97 & ~0x4000), 0..$_; + test join "", map chr (rand (2**20) & ~0x800), 0..$_; +} + +} |