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