1*0Sstevel@tonic-gateBEGIN { 2*0Sstevel@tonic-gate if (! -d 'blib' and -d 't'){ chdir 't' }; 3*0Sstevel@tonic-gate unshift @INC, '../lib'; 4*0Sstevel@tonic-gate require Config; import Config; 5*0Sstevel@tonic-gate if ($Config{'extensions'} !~ /\bEncode\b/) { 6*0Sstevel@tonic-gate print "1..0 # Skip: Encode was not built\n"; 7*0Sstevel@tonic-gate exit 0; 8*0Sstevel@tonic-gate } 9*0Sstevel@tonic-gate unless (find PerlIO::Layer 'perlio') { 10*0Sstevel@tonic-gate print "1..0 # Skip: PerlIO was not built\n"; 11*0Sstevel@tonic-gate exit 0; 12*0Sstevel@tonic-gate } 13*0Sstevel@tonic-gate if (ord("A") == 193) { 14*0Sstevel@tonic-gate print "1..0 # Skip: EBCDIC\n"; 15*0Sstevel@tonic-gate exit 0; 16*0Sstevel@tonic-gate } 17*0Sstevel@tonic-gate $| = 1; 18*0Sstevel@tonic-gate} 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gateuse strict; 21*0Sstevel@tonic-gateuse Test::More tests => 17; 22*0Sstevel@tonic-gateuse Encode; 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gateno utf8; # we have raw Chinese encodings here 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gateuse_ok('Encode::TW'); 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate# Since JP.t already tests basic file IO, we will just focus on 29*0Sstevel@tonic-gate# internal encode / decode test here. Unfortunately, to test 30*0Sstevel@tonic-gate# against all the UniHan characters will take a huge disk space, 31*0Sstevel@tonic-gate# not to mention the time it will take, and the fact that Perl 32*0Sstevel@tonic-gate# did not bundle UniHan.txt anyway. 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate# So, here we just test a typical snippet spanning multiple Unicode 35*0Sstevel@tonic-gate# blocks, and hope it can point out obvious errors. 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gaterun_tests('Basic Big5 range', { 38*0Sstevel@tonic-gate 'utf' => ( 39*0Sstevel@tonic-gate24093.39640.38525.20043.33495.35028.20846.65292. 40*0Sstevel@tonic-gate26389.30343.32771.26352.20271.24248.65108. 41*0Sstevel@tonic-gate25885.25552.35998.20110.23391.38508.20846.65292. 42*0Sstevel@tonic-gate24799.24218.23493.21566.20197.38477.65108 43*0Sstevel@tonic-gate ), 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate 'big5' => (join('', 46*0Sstevel@tonic-gate'�Ұ������]�Ǥ��A�ӬӦҤ�B�e�Q', 47*0Sstevel@tonic-gate'�ᴣ�s�_�s�����A�����G�^�H���Q', 48*0Sstevel@tonic-gate )), 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate 'big5-hkscs'=> (join('', 51*0Sstevel@tonic-gate'�Ұ������]�Ǥ��A�ӬӦҤ�B�e�Q', 52*0Sstevel@tonic-gate'�ᴣ�s�_�s�����A�����G�^�H���Q', 53*0Sstevel@tonic-gate )), 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate 'cp950' => (join('', 56*0Sstevel@tonic-gate'�Ұ������]�Ǥ��A�ӬӦҤ�B�e�Q', 57*0Sstevel@tonic-gate'�ᴣ�s�_�s�����A�����G�^�H���Q', 58*0Sstevel@tonic-gate )), 59*0Sstevel@tonic-gate}); 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gaterun_tests('Hong Kong Extensions', { 62*0Sstevel@tonic-gate 'utf' => ( 63*0Sstevel@tonic-gate24863.35613.25152.26377.20351.29992.32.80.101.114.108.32. 64*0Sstevel@tonic-gate22021.26379.21451.65292.32102.25105.21707.22021. 65*0Sstevel@tonic-gate25903.25345.12289.24847.35211.21644.40723.21237. 66*0Sstevel@tonic-gate22914.26524.32232.30908.26377.20219.20309.37679.28431. 67*0Sstevel@tonic-gate65292.35531.21578.35380.25105.21707.12290 68*0Sstevel@tonic-gate ), 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate 'big5-hkscs' => join('', 71*0Sstevel@tonic-gate'�P�©Ҧ��ϥ� Perl ��B�͡A���ڒ]�����B�N���M���y', 72*0Sstevel@tonic-gate'�p�G�s�X��������|�A�Чi�D�ڒ]�C' 73*0Sstevel@tonic-gate ), 74*0Sstevel@tonic-gate}); 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gatesub run_tests { 77*0Sstevel@tonic-gate my ($title, $tests) = @_; 78*0Sstevel@tonic-gate my $utf = delete $tests->{'utf'}; 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate # $enc = encoding, $str = content 81*0Sstevel@tonic-gate foreach my $enc (sort keys %{$tests}) { 82*0Sstevel@tonic-gate my $str = $tests->{$enc}; 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate is(Encode::decode($enc, $str), $utf, "[$enc] decode - $title"); 85*0Sstevel@tonic-gate is(Encode::encode($enc, $utf), $str, "[$enc] encode - $title"); 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate my $str2 = $str; 88*0Sstevel@tonic-gate my $utf8 = Encode::encode('utf-8', $utf); 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate Encode::from_to($str2, $enc, 'utf-8'); 91*0Sstevel@tonic-gate is($str2, $utf8, "[$enc] from_to => utf8 - $title"); 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate Encode::from_to($utf8, 'utf-8', $enc); # convert $utf8 as $enc 94*0Sstevel@tonic-gate is($utf8, $str, "[$enc] utf8 => from_to - $title"); 95*0Sstevel@tonic-gate } 96*0Sstevel@tonic-gate} 97