This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add a test for for PerlIO ":encoding(...)" layer.
[perl5.git] / ext / PerlIO / t / encoding.t
CommitLineData
8e86646e
JH
1my $grk = "grk$$";
2my $utf = "utf$$";
3
4if (open(GRK, ">$grk")) {
5 # alpha beta gamma in ISO 8859-7
6 print GRK "\xe1\xe2\xe3";
7 close GRK;
8}
9
10{
11 use Encode;
12 open(my $i,'<:encoding(iso-8859-7)',$grk);
13 print "ok 1\n";
14 open(my $o,'>:utf8',$utf);
15 print "ok 2\n";
16 print $o readline($i);
17 print "ok 3\n";
18 close($o);
19 close($i);
20}
21
22if (open(UTF, "<$utf")) {
23 # alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3)
24 print "not " unless <UTF> eq "\xce\xb1\xce\xb2\xce\xb3";
25 print "ok 4\n";
26 close $grk;
27}
28
29{
30 use Encode;
31 open(my $i,'<:utf8',$utf);
32 print "ok 5\n";
33 open(my $o,'>:encoding(iso-8859-7)',$grk);
34 print "ok 6\n";
35 print $o readline($i);
36 print "ok 7\n";
37 close($o);
38 close($i);
39}
40
41if (open(GRK, "<$grk")) {
42 print "not " unless <GRK> eq "\xe1\xe2\xe3";
43 print "ok 8\n";
44 close $grk;
45}
46
47END {
48 unlink($grk, $utf);
49}