1898184e3Ssthen# 2898184e3Ssthen# このファイルのエンコーディングはUTF-8 3898184e3Ssthen# 4898184e3Ssthen 55759b3d2Safresh1# copied over from JSON::PC and modified to use JSON::PP 65759b3d2Safresh1# copied over from JSON::XS and modified to use JSON::PP 7898184e3Ssthen 8898184e3Ssthenuse Test::More; 9898184e3Ssthenuse strict; 10*256a93a4Safresh1use warnings; 11f3efcd01Safresh1use utf8; 12f3efcd01Safresh1BEGIN { plan tests => 17 }; 13898184e3SsthenBEGIN { $ENV{PERL_JSON_BACKEND} = 0; } 14898184e3Ssthen 15898184e3Ssthenuse JSON::PP; 16898184e3Ssthen 17898184e3Ssthen######################### 18898184e3Ssthenmy ($js,$obj,$str); 19898184e3Ssthen 20*256a93a4Safresh1my $pc = JSON::PP->new; 21898184e3Ssthen 22898184e3Ssthen$obj = {test => qq|abc"def|}; 23898184e3Ssthen$str = $pc->encode($obj); 24898184e3Ssthenis($str,q|{"test":"abc\"def"}|); 25898184e3Ssthen 26898184e3Ssthen$obj = {qq|te"st| => qq|abc"def|}; 27898184e3Ssthen$str = $pc->encode($obj); 28898184e3Ssthenis($str,q|{"te\"st":"abc\"def"}|); 29898184e3Ssthen 30898184e3Ssthen$obj = {test => qq|abc/def|}; # / => \/ 31898184e3Ssthen$str = $pc->encode($obj); # but since version 0.99 32898184e3Ssthenis($str,q|{"test":"abc/def"}|); # this handling is deleted. 33898184e3Ssthen$obj = $pc->decode($str); 34898184e3Ssthenis($obj->{test},q|abc/def|); 35898184e3Ssthen 36898184e3Ssthen$obj = {test => q|abc\def|}; 37898184e3Ssthen$str = $pc->encode($obj); 38898184e3Ssthenis($str,q|{"test":"abc\\\\def"}|); 39898184e3Ssthen 40898184e3Ssthen$obj = {test => "abc\bdef"}; 41898184e3Ssthen$str = $pc->encode($obj); 42898184e3Ssthenis($str,q|{"test":"abc\bdef"}|); 43898184e3Ssthen 44898184e3Ssthen$obj = {test => "abc\fdef"}; 45898184e3Ssthen$str = $pc->encode($obj); 46898184e3Ssthenis($str,q|{"test":"abc\fdef"}|); 47898184e3Ssthen 48898184e3Ssthen$obj = {test => "abc\ndef"}; 49898184e3Ssthen$str = $pc->encode($obj); 50898184e3Ssthenis($str,q|{"test":"abc\ndef"}|); 51898184e3Ssthen 52898184e3Ssthen$obj = {test => "abc\rdef"}; 53898184e3Ssthen$str = $pc->encode($obj); 54898184e3Ssthenis($str,q|{"test":"abc\rdef"}|); 55898184e3Ssthen 56898184e3Ssthen$obj = {test => "abc-def"}; 57898184e3Ssthen$str = $pc->encode($obj); 58898184e3Ssthenis($str,q|{"test":"abc-def"}|); 59898184e3Ssthen 60898184e3Ssthen$obj = {test => "abc(def"}; 61898184e3Ssthen$str = $pc->encode($obj); 62898184e3Ssthenis($str,q|{"test":"abc(def"}|); 63898184e3Ssthen 64898184e3Ssthen$obj = {test => "abc\\def"}; 65898184e3Ssthen$str = $pc->encode($obj); 66898184e3Ssthenis($str,q|{"test":"abc\\\\def"}|); 67898184e3Ssthen 68898184e3Ssthen$obj = {test => "あいうえお"}; 69898184e3Ssthen$str = $pc->encode($obj); 70898184e3Ssthenis($str,q|{"test":"あいうえお"}|); 71898184e3Ssthen 72898184e3Ssthen$obj = {"あいうえお" => "かきくけこ"}; 73898184e3Ssthen$str = $pc->encode($obj); 74898184e3Ssthenis($str,q|{"あいうえお":"かきくけこ"}|); 75898184e3Ssthen 76898184e3Ssthen$obj = $pc->decode(q|{"id":"abc\ndef"}|); 77898184e3Ssthenis($obj->{id},"abc\ndef",q|{"id":"abc\ndef"}|); 78898184e3Ssthen 79898184e3Ssthen$obj = $pc->decode(q|{"id":"abc\\\ndef"}|); 80898184e3Ssthenis($obj->{id},"abc\\ndef",q|{"id":"abc\\\ndef"}|); 81898184e3Ssthen 82898184e3Ssthen$obj = $pc->decode(q|{"id":"abc\\\\\ndef"}|); 83898184e3Ssthenis($obj->{id},"abc\\\ndef",q|{"id":"abc\\\\\ndef"}|); 84898184e3Ssthen 85