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