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