#!../perl
BEGIN {
- if (! -d 'blib' and -d 't'){ chdir 't' };
- unshift @INC, '../lib';
+ if ($ENV{'PERL_CORE'}){
+ chdir 't';
+ unshift @INC, '../lib';
+ }
require Config; import Config;
if ($Config{'extensions'} !~ /\bEncode\b/) {
print "1..0 # Skip: Encode was not built\n";
my %a2c;
my $ON_EBCDIC;
-BEGIN{
- $ON_EBCDIC = ord("A") == 193;
- @ARGV and $ON_EBCDIC = $ARGV[0] eq 'EBCDIC';
- $Encode::ON_EBCDIC = $ON_EBCDIC;
-
+sub init_a2c{
%a2c = (
- 'ascii' => 'US-ascii',
+ 'US-ascii' => 'ascii',
+ 'UTF-8' => 'utf8',
+ 'UCS-2' => 'UCS-2BE',
+ 'UCS2' => 'UCS-2BE',
+ 'iso-10646-1' => 'UCS-2BE',
+ 'ucs2-le' => 'UCS-2LE',
+ 'ucs2-be' => 'UCS-2BE',
+ 'utf16' => 'UTF-16',
+ 'utf32' => 'UTF-32',
+ 'utf16-be' => 'UTF-16BE',
+ 'utf32-be' => 'UTF-32BE',
+ 'utf16-le' => 'UTF-16LE',
+ 'utf32-le' => 'UTF-32LE',
'cyrillic' => 'iso-8859-5',
'arabic' => 'iso-8859-6',
'greek' => 'iso-8859-7',
'zh_TW.Big5' => $ON_EBCDIC ? '' : 'big5',
'big5-hk' => $ON_EBCDIC ? '' : 'big5-hkscs',
'GB_2312-80' => $ON_EBCDIC ? '' : 'euc-cn',
- 'gb2312-raw' => $ON_EBCDIC ? '' : 'gb2312-raw',
- 'gb12345-raw' => $ON_EBCDIC ? '' : 'gb12345-raw',
'KS_C_5601-1987' => $ON_EBCDIC ? '' : 'cp949',
- 'ksc5601-raw' => $ON_EBCDIC ? '' : 'ksc5601-raw',
- );
+ #
+ 'gb12345-raw' => $ON_EBCDIC ? '' : 'gb12345-raw',
+ 'gb2312-raw' => $ON_EBCDIC ? '' : 'gb2312-raw',
+ 'jis0201-raw' => $ON_EBCDIC ? '' : 'jis0201-raw',
+ 'jis0208-raw' => $ON_EBCDIC ? '' : 'jis0208-raw',
+ 'jis0212-raw' => $ON_EBCDIC ? '' : 'jis0212-raw',
+ 'ksc5601-raw' => $ON_EBCDIC ? '' : 'ksc5601-raw',
+ );
for my $i (1..11,13..16){
$a2c{"ISO 8859 $i"} = "iso-8859-$i";
$a2c{"Win" . ucfirst($k)} = "cp" . $v;
$a2c{"IBM-$v"} = $a2c{"MS-$v"} = "cp" . $v;
}
+ my @a2c = keys %a2c;
+ for my $k (@a2c){
+ $a2c{uc($k)} = $a2c{$k};
+ $a2c{lc($k)} = $a2c{$k};
+ $a2c{lcfirst($k)} = $a2c{$k};
+ $a2c{ucfirst($k)} = $a2c{$k};
+ }
+}
+
+BEGIN{
+ $ON_EBCDIC = ord("A") == 193;
+ @ARGV and $ON_EBCDIC = $ARGV[0] eq 'EBCDIC';
+ $Encode::ON_EBCDIC = $ON_EBCDIC;
+ init_a2c();
}
if ($ON_EBCDIC){
delete @Encode::ExtModule{
- qw(euc-cn gb2312 gb12345 gbk cp936 iso-ir-165
+ qw(euc-cn gb2312 gb12345 gbk cp936 iso-ir-165 MacChineseSimp
euc-jp iso-2022-jp 7bit-jis shiftjis MacJapanese cp932
- euc-kr ksc5601 cp949
- big5 big5-hkscs cp950
+ euc-kr ksc5601 cp949 MacKorean
+ big5 big5-hkscs cp950 MacChineseTrad
gb18030 big5plus euc-tw)
};
}
-use Test::More tests => (scalar keys %a2c) * 3;
+use Test::More tests => (scalar keys %a2c) * 4;
print "# alias test; \$ON_EBCDIC == $ON_EBCDIC\n";
-foreach my $a (keys %a2c){
+foreach my $a (keys %a2c){
my $e = Encode::find_encoding($a);
- is((defined($e) and $e->name), $a2c{$a});
+ is((defined($e) and $e->name), $a2c{$a},$a)
+ or warn "alias was $a";;
}
# now we override some of the aliases and see if it works fine
-define_alias(ascii => 'WinLatin1',
- cyrillic => 'WinCyrillic',
- arabic => 'WinArabic',
- greek => 'WinGreek',
- hebrew => 'WinHebrew');
-
-@a2c{qw(ascii cyrillic arabic greek hebrew)} =
- qw(cp1252 cp1251 cp1256 cp1253 cp1255);
-
-unless ($ON_EBCDIC){
- define_alias( qr/shift.*jis$/i => '"MacJapanese"',
- qr/sjis$/i => '"cp932"' );
- @a2c{qw(Shift_JIS x-sjis)} = qw(MacJapanese cp932);
-}
+define_alias(
+ qr/ascii/i => 'WinLatin1',
+ qr/cyrillic/i => 'WinCyrillic',
+ qr/arabic/i => 'WinArabic',
+ qr/greek/i => 'WinGreek',
+ qr/hebrew/i => 'WinHebrew'
+ );
print "# alias test with alias overrides\n";
-foreach my $a (keys %a2c){
+foreach my $a (keys %a2c){
my $e = Encode::find_encoding($a);
- is((defined($e) and $e->name), $a2c{$a})
+ is((defined($e) and $e->name), $a2c{$a}, "Override $a")
or warn "alias was $a";
}
print "# alias undef test\n";
Encode::Alias->undef_aliases;
-foreach my $a (keys %a2c){
+foreach my $a (keys %a2c){
my $e = Encode::find_encoding($a);
- ok(!defined($e) || $e->name =~ /-raw$/o);
+ ok(!defined($e) || $e->name =~ /-raw$/o,"Undef $a")
+ or warn "alias was $a";
}
+print "# alias reinit test\n";
+
+Encode::Alias->init_aliases;
+init_a2c();
+foreach my $a (keys %a2c){
+ my $e = Encode::find_encoding($a);
+ is((defined($e) and $e->name), $a2c{$a}, "Reinit $a")
+ or warn "alias was $a";
+}
__END__
-for (my $i = 0; $i < @Encode::Alias::Alias; $i+=2){
- my ($k, $v) = @Encode::Alias::Alias[$i, $i+1];
- print "$k => $v\n";
+for my $k (keys %a2c){
+ $k =~ /[A-Z]/ and next;
+ print "$k => $a2c{$k}\n";
}
+