2 if (! -d 'blib' and -d 't'){ chdir 't' };
3 unshift @INC, '../lib';
4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bEncode\b/) {
6 print "1..0 # Skip: Encode was not built\n";
9 unless (find PerlIO::Layer 'perlio') {
10 print "1..0 # Skip: PerlIO was not built\n";
13 if (ord("A") == 193) {
14 print "1..0 # Skip: EBCDIC\n";
21 use Test::More tests => 17;
26 # Since JP.t already test basic file IO, we will just focus on
27 # internal encode / decode test here. Unfortunately, to test
28 # against all the UniHan characters will take a huge disk space,
29 # not to mention the time it will take, and the fact that Perl
30 # did not bundle UniHan.txt anyway.
32 # So, here we just test a typical snippet spanning multiple Unicode
33 # blocks, and hope it can point out obvious errors.
35 run_tests('Basic Big5 range', {
37 24093.39640.38525.20043.33495.35028.20846.65292.
38 26389.30343.32771.26352.20271.24248.65108.
39 25885.25552.35998.20110.23391.38508.20846.65292.
40 24799.24218.23493.21566.20197.38477.65108
44 '«Ò°ª¶§¤§]¸Ç¤¼¡A®Ó¬Ó¦Ò¤ê§B±e¡Q',
45 'Äá´£s¤_©s³µ¤¼¡A±©©°±G§^¥H°¡Q',
48 'big5-hkscs'=> (join('',
49 '«Ò°ª¶§¤§]¸Ç¤¼¡A®Ó¬Ó¦Ò¤ê§B±e¡Q',
50 'Äá´£s¤_©s³µ¤¼¡A±©©°±G§^¥H°¡Q',
54 '«Ò°ª¶§¤§]¸Ç¤¼¡A®Ó¬Ó¦Ò¤ê§B±e¡Q',
55 'Äá´£s¤_©s³µ¤¼¡A±©©°±G§^¥H°¡Q',
59 run_tests('Hong Kong Extensions', {
61 24863.35613.25152.26377.20351.29992.32.80.101.114.108.32.
62 22021.26379.21451.65292.32102.25105.21707.22021.
63 25903.25345.12289.24847.35211.21644.40723.21237.
64 22914.26524.32232.30908.26377.20219.20309.37679.28431.
65 65292.35531.21578.35380.25105.21707.12290
68 'big5-hkscs' => join('',
69 '·PÁ©Ҧ³¨Ï¥Î Perl ïªB¤Í¡Aµ¹§Ú]ï¤ä«ù¡B·N¨£©M¹ªÀy',
70 '¦pªG½s½X¦³¥ô¦ó¿ùº|¡A½Ð§i¶D§Ú]¡C'
75 my ($title, $tests) = @_;
76 my $utf = delete $tests->{'utf'};
78 # $enc = encoding, $str = content
79 foreach my $enc (sort keys %{$tests}) {
80 my $str = $tests->{$enc};
82 is(Encode::decode($enc, $str), $utf, "[$enc] decode - $title");
83 is(Encode::encode($enc, $utf), $str, "[$enc] encode - $title");
86 my $utf8 = Encode::encode('utf-8', $utf);
88 Encode::from_to($str2, $enc, 'utf-8');
89 is($str2, $utf8, "[$enc] from_to => utf8 - $title");
91 Encode::from_to($utf8, 'utf-8', $enc); # convert $utf8 as $enc
92 is($utf8, $str, "[$enc] utf8 => from_to - $title");