1# copied over from JSON::XS and modified to use JSON::PP 2 3use strict; 4use warnings; 5use Test::More; 6BEGIN { plan tests => 9 }; 7 8BEGIN { $ENV{PERL_JSON_BACKEND} = 0; } 9 10use utf8; 11use JSON::PP; 12 13 14ok (JSON::PP->new->allow_nonref (1)->utf8 (1)->encode ("ü") eq "\"\xc3\xbc\""); 15ok (JSON::PP->new->allow_nonref (1)->encode ("ü") eq "\"ü\""); 16ok (JSON::PP->new->allow_nonref (1)->ascii (1)->utf8 (1)->encode (chr 0x8000) eq '"\u8000"'); 17ok (JSON::PP->new->allow_nonref (1)->ascii (1)->utf8 (1)->pretty (1)->encode (chr 0x10402) eq "\"\\ud801\\udc02\"\n"); 18 19eval { JSON::PP->new->allow_nonref (1)->utf8 (1)->decode ('"ü"') }; 20ok $@ =~ /malformed UTF-8/; 21 22ok (JSON::PP->new->allow_nonref (1)->decode ('"ü"') eq "ü"); 23ok (JSON::PP->new->allow_nonref (1)->decode ('"\u00fc"') eq "ü"); 24ok (JSON::PP->new->allow_nonref (1)->decode ('"\ud801\udc02' . "\x{10204}\"") eq "\x{10402}\x{10204}"); 25ok (JSON::PP->new->allow_nonref (1)->decode ('"\"\n\\\\\r\t\f\b"') eq "\"\012\\\015\011\014\010"); 26 27