Test the encoding transform only iff we have PerlIO,
[p5sagit/p5-mst-13.2.git] / ext / PerlIO / t / encoding.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     unless (find PerlIO::Layer 'perlio') {
7         print "1..0 # Skip: not perlio\n";
8         exit 0;
9     }
10 }
11
12 print "1..8\n";
13
14 my $grk = "grk$$";
15 my $utf = "utf$$";
16
17 if (open(GRK, ">$grk")) {
18     # alpha beta gamma in ISO 8859-7
19     print GRK "\xe1\xe2\xe3";
20     close GRK;
21 }
22
23 {
24     use Encode;
25     open(my $i,'<:encoding(iso-8859-7)',$grk);
26     print "ok 1\n";
27     open(my $o,'>:utf8',$utf);
28     print "ok 2\n";
29     print $o readline($i);
30     print "ok 3\n";
31     close($o);
32     close($i);
33 }
34
35 if (open(UTF, "<$utf")) {
36     # alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3)
37     print "not " unless <UTF> eq "\xce\xb1\xce\xb2\xce\xb3";
38     print "ok 4\n";
39     close $grk;
40 }
41
42 {
43     use Encode;
44     open(my $i,'<:utf8',$utf);
45     print "ok 5\n";
46     open(my $o,'>:encoding(iso-8859-7)',$grk);
47     print "ok 6\n";
48     print $o readline($i);
49     print "ok 7\n";
50     close($o);
51     close($i);
52 }
53
54 if (open(GRK, "<$grk")) {
55     print "not " unless <GRK> eq "\xe1\xe2\xe3";
56     print "ok 8\n";
57     close $grk;
58 }
59
60 END {
61     unlink($grk, $utf);
62 }