[PATCH] Encode.pm to use escape-sequence encoding
[p5sagit/p5-mst-13.2.git] / ext / Encode / Encode / Tcl.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4     require Config; import Config;
5     if ($Config{'extensions'} !~ /\bEncode\b/) {
6       print "1..0 # Skip: Encode was not built\n";
7       exit 0;
8     }
9 }
10 use Test;
11 use Encode qw(encode decode);
12 use Encode::Tcl;
13
14 my @encodings = qw(euc-cn euc-jp euc-kr big5 shiftjis); # CJK
15 my $n = 2;
16
17 my %greek = (
18   'euc-cn'   => [0xA6A1..0xA6B8,0xA6C1..0xA6D8],
19   'euc-jp'   => [0xA6A1..0xA6B8,0xA6C1..0xA6D8],
20   'euc-kr'   => [0xA5C1..0xA5D8,0xA5E1..0xA5F8],
21   'big5'     => [0xA344..0xA35B,0xA35C..0xA373],
22   'shiftjis' => [0x839F..0x83B6,0x83BF..0x83D6],
23   'utf8'     => [0x0391..0x03A1,0x03A3..0x03A9,0x03B1..0x03C1,0x03C3..0x03C9],
24 );
25 my @greek = qw(
26   ALPHA BETA GAMMA DELTA EPSILON ZETA ETA
27   THETA IOTA KAPPA LAMBDA MU NU XI OMICRON
28   PI RHO SIGMA TAU UPSILON PHI CHI PSI OMEGA
29   alpha beta gamma delta epsilon zeta eta
30   theta iota kappa lambda mu nu xi omicron
31   pi rho sigma tau upsilon phi chi psi omega
32 );
33
34 my %ideodigit = ( # cjk ideograph 'one' to 'ten'
35   'euc-cn'   => [qw(d2bb b6fe c8fd cbc4 cee5 c1f9 c6df b0cb bec5 caae)],
36   'euc-jp'   => [qw(b0ec c6f3 bbb0 bbcd b8de cfbb bcb7 c8ac b6e5 bdbd)],
37   'euc-kr'   => [qw(ece9 eca3 dfb2 decc e7e9 d7bf f6d2 f8a2 cefa e4a8)],
38   'big5'     => [qw(a440 a447 a454 a57c a4ad a4bb a443 a44b a445 a451)],
39   'shiftjis' => [qw(88ea 93f1 8e4f 8e6c 8cdc 985a 8eb5 94aa 8be3 8f5c)],
40   'utf8'     => [qw(4e00 4e8c 4e09 56db 4e94 516d 4e03 516b 4e5d 5341)],
41 );
42 my @ideodigit = qw(one two three four five six seven eight nine ten);
43
44 plan test => $n*@encodings + $n*@encodings*@greek + $n*@encodings*@ideodigit;
45
46 foreach my $enc (@encodings)
47  {
48   my $tab = Encode->getEncoding($enc);
49   ok(1,defined($tab),"Could not load $enc");
50   my $str = join('',map(chr($_),0x20..0x7E));
51   my $uni = $tab->decode($str);
52   my $cpy = $tab->encode($uni);
53   ok($cpy,$str,"$enc mangled translating to Unicode and back");
54  }
55
56 foreach my $enc (@encodings)
57  {
58   my $tab = Encode->getEncoding($enc);
59   foreach my $gk (0..$#greek)
60    {
61      my $uni = unpack 'U', $tab->decode(pack 'n', $greek{$enc}[$gk]);
62      ok($uni,$greek{'utf8'}[$gk],
63        "$enc mangled translating to Unicode GREEK $greek[$gk]");
64      my $cpy = unpack 'n',$tab->encode(pack 'U',$uni);
65      ok($cpy,$greek{$enc}[$gk],
66        "$enc mangled translating from Unicode GREEK $greek[$gk]");
67    }
68  }
69
70 foreach my $enc (@encodings)
71  {
72   my $tab = Encode->getEncoding($enc);
73   foreach my $id (0..$#ideodigit)
74    {
75      my $uni = unpack 'U',$tab->decode(pack 'H*', $ideodigit{$enc}[$id]);
76      ok($uni,hex($ideodigit{'utf8'}[$id]),
77        "$enc mangled translating to Unicode CJK IDEOGRAPH $ideodigit[$id]");
78      my $cpy = lc unpack 'H*', $tab->encode(pack 'U',$uni);
79      ok($cpy,$ideodigit{$enc}[$id],
80        "$enc mangled translating from Unicode CJK IDEOGRAPH $ideodigit[$id]");
81    }
82  }
83