Debian Codegraph @

t/109_encode.t

raw
1 #
2 # decode on Perl 5.005, 5.6, 5.8 or later
3 #
4 use strict;
5 use warnings;
6 use Test::More;
7
8 BEGIN { plan tests => 7 };
9
10 BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; }
11
12 my $isASCII = ord "A" == 65;
13
14 use JSON;
15
16 no utf8;
17
18 my $json = JSON->new->allow_nonref;
19
20 # U+00B6 chosen because it works on both ASCII and EBCDIC
21 is($json->encode("¶"), q|"¶"|); # as is
22
23 $json->ascii;
24
25 if ($] < 5.008) {
26 is($json->encode("\xb6"), q|"\u00b6"|); # latin1
27 is($json->encode("\xc2\xb6"), q|"\u00c2\u00b6"|); # utf8
28 is($json->encode("¶"), q|"\u00c2\u00b6"|); # utf8
29 is($json->encode('あ'), q|"\u00e3\u0081\u0082"|);
30 }
31 else {
32 is($json->encode("\xb6"), q|"\u00b6"|); # latin1
33
34 if (ord "A" == 65) {
35 is($json->encode("\xc2\xb6"), q|"\u00c2\u00b6"|); # utf8
36 is($json->encode("¶"), q|"\u00c2\u00b6"|); # utf8
37 is($json->encode('あ'), q|"\u00e3\u0081\u0082"|);
38 }
39 else {
40 if (ord '^' == 95) { # EBCDIC 1047
41 is($json->encode("\x80\x65"), q|"\u0080\u0065"|); # utf8
42 is($json->encode("¶"), q|"\u0080\u0065"|); # utf8
43 }
44 else { # Assume EBCDIC 037
45 is($json->encode("\x78\x64"), q|"\u0078\u0064"|); # utf8
46 is($json->encode("¶"), q|"\u0078\u0064"|); # utf8
47 }
48
49 is($json->encode('あ'), (q|"\u00ce\u0043\u0043"|));
50 }
51 }
52
53 if ($] >= 5.006) {
54 is($json->encode(chr hex 3042 ), q|"\u3042"|);
55 is($json->encode(chr hex 12345 ), q|"\ud808\udf45"|);
56 }
57 else {
58 is($json->encode(chr hex 3042 ), $json->encode(chr 66));
59 is($json->encode(chr hex 12345 ), $json->encode(chr 69));
60 }
61