OLD | NEW |
(Empty) | |
| 1 # copied over from JSON::XS and modified to use JSON |
| 2 |
| 3 use strict; |
| 4 use Test::More; |
| 5 BEGIN { plan tests => 9 }; |
| 6 |
| 7 BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; } |
| 8 |
| 9 BEGIN { |
| 10 use lib qw(t); |
| 11 use _unicode_handling; |
| 12 } |
| 13 |
| 14 |
| 15 use utf8; |
| 16 use JSON; |
| 17 |
| 18 |
| 19 ok (JSON->new->allow_nonref (1)->utf8 (1)->encode ("ü") eq "\"\xc3\xbc\""); |
| 20 ok (JSON->new->allow_nonref (1)->encode ("ü") eq "\"ü\""); |
| 21 |
| 22 SKIP: { |
| 23 skip "UNICODE handling is disabale.", 7 unless $JSON::can_handle_UTF16_and_u
tf8; |
| 24 |
| 25 ok (JSON->new->allow_nonref (1)->ascii (1)->utf8 (1)->encode (chr 0x8000) eq '"\
u8000"'); |
| 26 ok (JSON->new->allow_nonref (1)->ascii (1)->utf8 (1)->pretty (1)->encode (chr 0x
10402) eq "\"\\ud801\\udc02\"\n"); |
| 27 |
| 28 eval { JSON->new->allow_nonref (1)->utf8 (1)->decode ('"ü"') }; |
| 29 ok $@ =~ /malformed UTF-8/; |
| 30 |
| 31 ok (JSON->new->allow_nonref (1)->decode ('"ü"') eq "ü"); |
| 32 ok (JSON->new->allow_nonref (1)->decode ('"\u00fc"') eq "ü"); |
| 33 ok (JSON->new->allow_nonref (1)->decode ('"\ud801\udc02' . "\x{10204}\"") eq "\x
{10402}\x{10204}"); |
| 34 ok (JSON->new->allow_nonref (1)->decode ('"\"\n\\\\\r\t\f\b"') eq "\"\012\\\015\
011\014\010"); |
| 35 |
| 36 } |
OLD | NEW |