Upgrade to Encode 1.42, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / t / TW.t
CommitLineData
00a464f7 1BEGIN {
037b88d6 2 if ($ENV{'PERL_CORE'}){
3 chdir 't';
4 unshift @INC, '../lib';
5 }
00a464f7 6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bEncode\b/) {
8 print "1..0 # Skip: Encode was not built\n";
9 exit 0;
10 }
00a464f7 11 if (ord("A") == 193) {
12 print "1..0 # Skip: EBCDIC\n";
13 exit 0;
14 }
15 $| = 1;
16}
17
18use strict;
19use Test::More tests => 17;
20use Encode;
21
22use_ok('Encode::TW');
23
24# Since JP.t already test basic file IO, we will just focus on
25# internal encode / decode test here. Unfortunately, to test
26# against all the UniHan characters will take a huge disk space,
27# not to mention the time it will take, and the fact that Perl
28# did not bundle UniHan.txt anyway.
29
30# So, here we just test a typical snippet spanning multiple Unicode
31# blocks, and hope it can point out obvious errors.
32
33run_tests('Basic Big5 range', {
34 'utf' => (
3524093.39640.38525.20043.33495.35028.20846.65292.
3626389.30343.32771.26352.20271.24248.65108.
3725885.25552.35998.20110.23391.38508.20846.65292.
3824799.24218.23493.21566.20197.38477.65108
39 ),
40
41 'big5' => (join('',
42'«Ò°ª¶§¤§­]¸Ç¤¼¡A®Ó¬Ó¦Ò¤ê§B±e¡Q',
43'Äá´£­s¤_©s³µ¤¼¡A±©©°±G§^¥H­°¡Q',
44 )),
45
46 'big5-hkscs'=> (join('',
47'«Ò°ª¶§¤§­]¸Ç¤¼¡A®Ó¬Ó¦Ò¤ê§B±e¡Q',
48'Äá´£­s¤_©s³µ¤¼¡A±©©°±G§^¥H­°¡Q',
49 )),
50
51 'cp950' => (join('',
52'«Ò°ª¶§¤§­]¸Ç¤¼¡A®Ó¬Ó¦Ò¤ê§B±e¡Q',
53'Äá´£­s¤_©s³µ¤¼¡A±©©°±G§^¥H­°¡Q',
54 )),
55});
56
57run_tests('Hong Kong Extensions', {
58 'utf' => (
5924863.35613.25152.26377.20351.29992.32.80.101.114.108.32.
6022021.26379.21451.65292.32102.25105.21707.22021.
6125903.25345.12289.24847.35211.21644.40723.21237.
6222914.26524.32232.30908.26377.20219.20309.37679.28431.
6365292.35531.21578.35380.25105.21707.12290
64 ),
65
66 'big5-hkscs' => join('',
67'·PÁ©Ҧ³¨Ï¥Î Perl ïªB¤Í¡Aµ¹§Ú’]ï¤ä«ù¡B·N¨£©M¹ªÀy',
68'¦pªG½s½X¦³¥ô¦ó¿ùº|¡A½Ð§i¶D§Ú’]¡C'
69 ),
70});
71
72sub run_tests {
73 my ($title, $tests) = @_;
74 my $utf = delete $tests->{'utf'};
75
76 # $enc = encoding, $str = content
77 foreach my $enc (sort keys %{$tests}) {
78 my $str = $tests->{$enc};
79
80 is(Encode::decode($enc, $str), $utf, "[$enc] decode - $title");
81 is(Encode::encode($enc, $utf), $str, "[$enc] encode - $title");
82
83 my $str2 = $str;
84 my $utf8 = Encode::encode('utf-8', $utf);
85
86 Encode::from_to($str2, $enc, 'utf-8');
87 is($str2, $utf8, "[$enc] from_to => utf8 - $title");
88
89 Encode::from_to($utf8, 'utf-8', $enc); # convert $utf8 as $enc
90 is($utf8, $str, "[$enc] utf8 => from_to - $title");
91 }
92}