Commit | Line | Data |
5d030b67 |
1 | #!../perl |
2 | |
3 | use strict; |
5129552c |
4 | use Encode; |
5 | use Encode::Alias; |
5d030b67 |
6 | |
7 | my %a2c; |
8 | |
9 | BEGIN { |
10 | %a2c = ( |
11 | 'ascii' => 'US-ascii', |
12 | 'cyrillic' => 'iso-8859-5', |
13 | 'arabic' => 'iso-8859-6', |
14 | 'greek' => 'iso-8859-7', |
15 | 'hebrew' => 'iso-8859-8', |
16 | 'thai' => 'iso-8859-11', |
17 | 'tis620' => 'iso-8859-11', |
18 | 'ja_JP.euc' => 'euc-jp', |
19 | 'x-euc-jp' => 'euc-jp', |
20 | 'zh_CN.euc' => 'euc-cn', |
21 | 'x-euc-cn' => 'euc-cn', |
22 | 'ko_KR.euc' => 'euc-kr', |
23 | 'x-euc-kr' => 'euc-kr', |
24 | 'ujis' => 'euc-jp', |
25 | 'Shift_JIS' => 'shiftjis', |
26 | 'x-sjis' => 'shiftjis', |
27 | 'jis' => '7bit-jis', |
28 | 'big-5' => 'big5', |
29 | 'zh_TW.Big5' => 'big5', |
30 | 'big5-hk' => 'big5-hkscs', |
31 | 'WinLatin1' => 'cp1252', |
32 | 'WinLatin2' => 'cp1250', |
33 | 'WinCyrillic' => 'cp1251', |
34 | 'WinGreek' => 'cp1253', |
35 | 'WinTurkish' => 'cp1254', |
36 | 'WinHebrew' => 'cp1255', |
37 | 'WinArabic' => 'cp1256', |
38 | 'WinBaltic' => 'cp1257', |
39 | 'WinVietnamese' => 'cp1258', |
40 | ); |
41 | |
42 | for my $i (1..11,13..16){ |
43 | $a2c{"ISO 8859 $i"} = "iso-8859-$i"; |
44 | } |
45 | for my $i (1..10){ |
46 | $a2c{"ISO Latin $i"} = "iso-8859-$Encode::Alias::Latin2iso[$i]"; |
47 | } |
48 | for my $k (keys %Encode::Alias::Winlatin2cp){ |
49 | my $v = $Encode::Alias::Winlatin2cp{$k}; |
50 | $a2c{"Win" . ucfirst($k)} = "cp" . $v; |
51 | $a2c{"IBM-$v"} = "cp" . $v; |
52 | $a2c{"MS-$v"} = "cp" . $v; |
53 | } |
54 | } |
55 | |
5129552c |
56 | use Test::More tests => (scalar keys %a2c) * 3; |
5d030b67 |
57 | |
58 | print "# alias test\n"; |
59 | |
60 | foreach my $a (keys %a2c){ |
61 | my $e = Encode::find_encoding($a); |
62 | is((defined($e) and $e->name), $a2c{$a}); |
63 | } |
64 | |
65 | # now we override some of the aliases and see if it works fine |
66 | |
5129552c |
67 | define_alias( qr/shift.*jis$/i => '"macjapan"' ); |
68 | define_alias( qr/sjis$/i => '"cp932"' ); |
5d030b67 |
69 | |
70 | @a2c{qw(Shift_JIS x-sjis)} = qw(macjapan cp932); |
71 | |
72 | print "# alias test with alias overrides\n"; |
73 | |
74 | foreach my $a (keys %a2c){ |
75 | my $e = Encode::find_encoding($a); |
76 | is((defined($e) and $e->name), $a2c{$a}); |
77 | } |
78 | |
5129552c |
79 | print "# alias undef test\n"; |
80 | |
81 | Encode::Alias->undef_aliases; |
82 | foreach my $a (keys %a2c){ |
83 | my $e = Encode::find_encoding($a); |
84 | ok(!defined($e)); |
85 | } |
86 | |
5d030b67 |
87 | __END__ |
88 | for (my $i = 0; $i < @Encode::Alias::Alias; $i+=2){ |
89 | my ($k, $v) = @Encode::Alias::Alias[$i, $i+1]; |
90 | print "$k => $v\n"; |
91 | } |
92 | |
93 | |