"Fossies" - the Fresh Open Source Software Archive

Member "perl-5.32.1/cpan/JSON-PP/t/007_pc_esc.t" (18 Dec 2020, 2002 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 #
    2 # このファイルのエンコーディングはUTF-8
    3 #
    4 
    5 # copied over from JSON::PC and modified to use JSON::PP
    6 # copied over from JSON::XS and modified to use JSON::PP
    7 
    8 use Test::More;
    9 use strict;
   10 use utf8;
   11 BEGIN { plan tests => 17 };
   12 BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
   13 
   14 use JSON::PP;
   15 
   16 #########################
   17 my ($js,$obj,$str);
   18 
   19 my $pc = new JSON::PP;
   20 
   21 $obj = {test => qq|abc"def|};
   22 $str = $pc->encode($obj);
   23 is($str,q|{"test":"abc\"def"}|);
   24 
   25 $obj = {qq|te"st| => qq|abc"def|};
   26 $str = $pc->encode($obj);
   27 is($str,q|{"te\"st":"abc\"def"}|);
   28 
   29 $obj = {test => qq|abc/def|};   # / => \/
   30 $str = $pc->encode($obj);         # but since version 0.99
   31 is($str,q|{"test":"abc/def"}|); # this handling is deleted.
   32 $obj = $pc->decode($str);
   33 is($obj->{test},q|abc/def|);
   34 
   35 $obj = {test => q|abc\def|};
   36 $str = $pc->encode($obj);
   37 is($str,q|{"test":"abc\\\\def"}|);
   38 
   39 $obj = {test => "abc\bdef"};
   40 $str = $pc->encode($obj);
   41 is($str,q|{"test":"abc\bdef"}|);
   42 
   43 $obj = {test => "abc\fdef"};
   44 $str = $pc->encode($obj);
   45 is($str,q|{"test":"abc\fdef"}|);
   46 
   47 $obj = {test => "abc\ndef"};
   48 $str = $pc->encode($obj);
   49 is($str,q|{"test":"abc\ndef"}|);
   50 
   51 $obj = {test => "abc\rdef"};
   52 $str = $pc->encode($obj);
   53 is($str,q|{"test":"abc\rdef"}|);
   54 
   55 $obj = {test => "abc-def"};
   56 $str = $pc->encode($obj);
   57 is($str,q|{"test":"abc-def"}|);
   58 
   59 $obj = {test => "abc(def"};
   60 $str = $pc->encode($obj);
   61 is($str,q|{"test":"abc(def"}|);
   62 
   63 $obj = {test => "abc\\def"};
   64 $str = $pc->encode($obj);
   65 is($str,q|{"test":"abc\\\\def"}|);
   66 
   67 $obj = {test => "あいうえお"};
   68 $str = $pc->encode($obj);
   69 is($str,q|{"test":"あいうえお"}|);
   70 
   71 $obj = {"あいうえお" => "かきくけこ"};
   72 $str = $pc->encode($obj);
   73 is($str,q|{"あいうえお":"かきくけこ"}|);
   74 
   75 $obj = $pc->decode(q|{"id":"abc\ndef"}|);
   76 is($obj->{id},"abc\ndef",q|{"id":"abc\ndef"}|);
   77 
   78 $obj = $pc->decode(q|{"id":"abc\\\ndef"}|);
   79 is($obj->{id},"abc\\ndef",q|{"id":"abc\\\ndef"}|);
   80 
   81 $obj = $pc->decode(q|{"id":"abc\\\\\ndef"}|);
   82 is($obj->{id},"abc\\\ndef",q|{"id":"abc\\\\\ndef"}|);
   83