A few tweaks to get Tk803 to work with Encode scheme.
[p5sagit/p5-mst-13.2.git] / t / lib / encode.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4 }
5 use Test;
6 use Encode qw(from_to);
7 use charnames qw(greek);
8 my @encodings = grep(/iso8859/,Encode::encodings());
9 my $n = 2;
10 plan test => 13+$n*@encodings;
11 my $str = join('',map(chr($_),0x20..0x7E));
12 my $cpy = $str;
13 ok(length($str),from_to($cpy,'iso8859-1','Unicode'),"Length Wrong");
14 ok($cpy,$str,"ASCII mangled by translating from iso8859-1 to Unicode");
15 $cpy = $str;
16 ok(from_to($cpy,'Unicode','iso8859-1'),length($str),"Length wrong");
17 ok($cpy,$str,"ASCII mangled by translating from Unicode to iso8859-1");
18
19 $str = join('',map(chr($_),0xa0..0xff));
20 $cpy = $str;
21 ok(length($str),from_to($cpy,'iso8859-1','Unicode'),"Length Wrong");
22
23 my $sym = Encode->getEncoding('symbol');
24 my $uni = $sym->toUnicode('a');
25 ok("\N{alpha}",substr($uni,0,1),"alpha does not map so symbol 'a'");
26 $str = $sym->fromUnicode("\N{Beta}");
27 ok("B",substr($str,0,1),"Symbol 'B' does not map to Beta");
28
29 foreach my $enc (qw(symbol dingbats ascii),@encodings)
30  {
31   my $tab = Encode->getEncoding($enc);
32   ok(1,defined($tab),"Could not load $enc");
33   $str = join('',map(chr($_),0x20..0x7E));
34   $uni = $tab->toUnicode($str);
35   $cpy = $tab->fromUnicode($uni);
36   ok($cpy,$str,"$enc mangled translating to Unicode and back");
37  }
38