File: 099_binary.t

package info (click to toggle)
perl 5.32.1-4%2Bdeb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 113,408 kB
  • sloc: ansic: 641,443; perl: 491,650; sh: 70,967; pascal: 8,354; cpp: 4,103; xml: 2,428; makefile: 2,237; yacc: 1,173; lisp: 1
file content (44 lines) | stat: -rw-r--r-- 1,541 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# copied over from JSON::XS and modified to use JSON::PP

use strict;
use Test::More;
BEGIN { plan tests => 24576 };

BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }

use JSON::PP;


sub test($) {
   my $js;

   $js = JSON::PP->new->allow_nonref(0)->utf8->ascii->shrink->encode ([$_[0]]);
   ok ($_[0] eq ((decode_json $js)->[0]), " - 0");
   $js = JSON::PP->new->allow_nonref(0)->utf8->ascii->encode ([$_[0]]);
   ok ($_[0] eq (JSON::PP->new->utf8->shrink->decode($js))->[0], " - 1");

   $js = JSON::PP->new->allow_nonref(0)->utf8->shrink->encode ([$_[0]]);
   ok ($_[0] eq ((decode_json $js)->[0]), " - 2");
   $js = JSON::PP->new->allow_nonref(1)->utf8->encode ([$_[0]]);
   ok ($_[0] eq (JSON::PP->new->utf8->shrink->decode($js))->[0], " - 3");

   $js = JSON::PP->new->allow_nonref(1)->ascii->encode ([$_[0]]);
   ok ($_[0] eq JSON::PP->new->decode ($js)->[0], " - 4");
   $js = JSON::PP->new->allow_nonref(0)->ascii->encode ([$_[0]]);
   ok ($_[0] eq JSON::PP->new->shrink->decode ($js)->[0], " - 5");

   $js = JSON::PP->new->allow_nonref(1)->shrink->encode ([$_[0]]);
   ok ($_[0] eq JSON::PP->new->decode ($js)->[0], " - 6");
   $js = JSON::PP->new->allow_nonref(0)->encode ([$_[0]]);
   ok ($_[0] eq JSON::PP->new->shrink->decode ($js)->[0], " - 7");
}

srand 0; # doesn't help too much, but its at least more deterministic

for (1..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..$_;
}