"Fossies" - the Fresh Open Source Software Archive

Member "perl-5.32.1/cpan/JSON-PP/t/001_utf8.t" (18 Dec 2020, 972 Bytes) of package /linux/misc/perl-5.32.1.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

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