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 8use Test::More; 9use strict; 10use warnings; 11use utf8; 12BEGIN { plan tests => 17 }; 13BEGIN { $ENV{PERL_JSON_BACKEND} = 0; } 14 15use JSON::PP; 16 17######################### 18my ($js,$obj,$str); 19 20my $pc = JSON::PP->new; 21 22$obj = {test => qq|abc"def|}; 23$str = $pc->encode($obj); 24is($str,q|{"test":"abc\"def"}|); 25 26$obj = {qq|te"st| => qq|abc"def|}; 27$str = $pc->encode($obj); 28is($str,q|{"te\"st":"abc\"def"}|); 29 30$obj = {test => qq|abc/def|}; # / => \/ 31$str = $pc->encode($obj); # but since version 0.99 32is($str,q|{"test":"abc/def"}|); # this handling is deleted. 33$obj = $pc->decode($str); 34is($obj->{test},q|abc/def|); 35 36$obj = {test => q|abc\def|}; 37$str = $pc->encode($obj); 38is($str,q|{"test":"abc\\\\def"}|); 39 40$obj = {test => "abc\bdef"}; 41$str = $pc->encode($obj); 42is($str,q|{"test":"abc\bdef"}|); 43 44$obj = {test => "abc\fdef"}; 45$str = $pc->encode($obj); 46is($str,q|{"test":"abc\fdef"}|); 47 48$obj = {test => "abc\ndef"}; 49$str = $pc->encode($obj); 50is($str,q|{"test":"abc\ndef"}|); 51 52$obj = {test => "abc\rdef"}; 53$str = $pc->encode($obj); 54is($str,q|{"test":"abc\rdef"}|); 55 56$obj = {test => "abc-def"}; 57$str = $pc->encode($obj); 58is($str,q|{"test":"abc-def"}|); 59 60$obj = {test => "abc(def"}; 61$str = $pc->encode($obj); 62is($str,q|{"test":"abc(def"}|); 63 64$obj = {test => "abc\\def"}; 65$str = $pc->encode($obj); 66is($str,q|{"test":"abc\\\\def"}|); 67 68$obj = {test => "あいうえお"}; 69$str = $pc->encode($obj); 70is($str,q|{"test":"あいうえお"}|); 71 72$obj = {"あいうえお" => "かきくけこ"}; 73$str = $pc->encode($obj); 74is($str,q|{"あいうえお":"かきくけこ"}|); 75 76$obj = $pc->decode(q|{"id":"abc\ndef"}|); 77is($obj->{id},"abc\ndef",q|{"id":"abc\ndef"}|); 78 79$obj = $pc->decode(q|{"id":"abc\\\ndef"}|); 80is($obj->{id},"abc\\ndef",q|{"id":"abc\\\ndef"}|); 81 82$obj = $pc->decode(q|{"id":"abc\\\\\ndef"}|); 83is($obj->{id},"abc\\\ndef",q|{"id":"abc\\\\\ndef"}|); 84 85