1# 2# decode on Perl 5.005, 5.6, 5.8 or later 3# 4use strict; 5use warnings; 6use Test::More; 7 8BEGIN { plan tests => 7 }; 9 10BEGIN { $ENV{PERL_JSON_BACKEND} = 0; } 11 12use JSON::PP; 13 14no utf8; 15 16my $json = JSON::PP->new->allow_nonref; 17 18# U+00B6 chosen because it works on both ASCII and EBCDIC 19is($json->encode("¶"), q|"¶"|); # as is 20 21$json->ascii; 22 23is($json->encode("\xb6"), q|"\u00b6"|); # latin1 24 25if (ord "A" == 65) { 26 is($json->encode("\xc2\xb6"), q|"\u00c2\u00b6"|); # utf8 27 is($json->encode("¶"), q|"\u00c2\u00b6"|); # utf8 28 is($json->encode('あ'), q|"\u00e3\u0081\u0082"|); 29} 30else { 31 if (ord '^' == 95) { # EBCDIC 1047 32 is($json->encode("\x80\x65"), q|"\u0080\u0065"|); # utf8 33 is($json->encode("¶"), q|"\u0080\u0065"|); # utf8 34 } 35 else { # Assume EBCDIC 037 36 is($json->encode("\x78\x64"), q|"\u0078\u0064"|); # utf8 37 is($json->encode("¶"), q|"\u0078\u0064"|); # utf8 38 } 39 40 is($json->encode('あ'), (q|"\u00ce\u0043\u0043"|)); 41} 42 43is($json->encode(chr hex 3042 ), q|"\u3042"|); 44is($json->encode(chr hex 12345 ), q|"\ud808\udf45"|); 45