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