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 12my $isASCII = ord "A" == 65; 13 14use JSON::PP; 15 16no utf8; 17 18my $json = JSON::PP->new->allow_nonref; 19 20 21is($json->decode(q|"ü"|), "ü"); # utf8 22is($json->decode(q|"\u00fc"|), "\xfc"); # latin1 23is($json->decode(q|"\u00c3\u00bc"|), "\xc3\xbc"); # utf8 24 25my $str = 'あ'; # Japanese 'a' in utf8 26 27is($json->decode(($isASCII) ? q|"\u00e3\u0081\u0082"| 28 : q|"\u00ce\u0043\u0043"|), 29 $str); 30 31utf8::decode($str); # usually UTF-8 flagged on, but no-op for 5.005. 32 33is($json->decode(q|"\u3042"|), $str); 34 35 36# chr 0x12400, which was chosen because it has the same representation in 37# both EBCDIC 1047 and 037 38my $utf8 = $json->decode(q|"\ud809\udc00"|); 39 40utf8::encode($utf8); # UTF-8 flagged off 41 42is($utf8, ($isASCII) ? "\xf0\x92\x90\x80" : "\xDE\x4A\x41\x41"); 43 44eval { $json->decode(q|{"action":"foo" "method":"bar","tid":1}|) }; 45my $error = $@; 46like $error => qr!""method":"bar","tid"..."!; 47