6 no warnings; # Need global -w flag for later tests, but don't want this
8 push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
9 unless (find PerlIO::Layer 'perlio') {
10 print "1..0 # Skip: not perlio\n";
21 my $russki = "koi8r$$";
22 my $threebyte = "3byte$$";
24 if (open(GRK, ">$grk")) {
25 binmode(GRK, ":bytes");
26 # alpha beta gamma in ISO 8859-7
27 print GRK "\xe1\xe2\xe3";
28 close GRK or die "Could not close: $!";
33 open(my $i,'<:encoding(iso-8859-7)',$grk);
35 open(my $o,'>:utf8',$utf);
37 print $o readline($i);
39 close($o) or die "Could not close: $!";
43 if (open(UTF, "<$utf")) {
44 binmode(UTF, ":bytes");
45 if (ord('A') == 193) { # EBCDIC
46 # alpha beta gamma in UTF-EBCDIC Unicode (0x3b1 0x3b2 0x3b3)
47 print "not " unless <UTF> eq "\xb4\x58\xb4\x59\xb4\x62";
49 # alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3)
50 print "not " unless <UTF> eq "\xce\xb1\xce\xb2\xce\xb3";
58 open(my $i,'<:utf8',$utf);
60 open(my $o,'>:encoding(iso-8859-7)',$grk);
62 print $o readline($i);
64 close($o) or die "Could not close: $!";
68 if (open(GRK, "<$grk")) {
69 binmode(GRK, ":bytes");
70 print "not " unless <GRK> eq "\xe1\xe2\xe3";
75 $SIG{__WARN__} = sub {$warn .= $_[0]};
77 if (open(FAIL, ">:encoding(NoneSuch)", $fail1)) {
78 print "not ok 9 # Open should fail\n";
83 print "not ok 10 # warning is undef\n";
84 } elsif ($warn =~ /^Cannot find encoding "NoneSuch" at/) {
87 print "not ok 10 # warning is '$warn'";
90 if (open(RUSSKI, ">$russki")) {
91 print RUSSKI "\x3c\x3f\x78";
92 close RUSSKI or die "Could not close: $!";
93 open(RUSSKI, "$russki");
94 binmode(RUSSKI, ":raw");
96 read(RUSSKI, $buf1, 1);
98 binmode(RUSSKI, ":encoding(koi8-r)");
100 read(RUSSKI, $buf2, 1);
101 my $offset = tell(RUSSKI);
102 if (ord($buf1) == 0x3c &&
103 ord($buf2) == (ord('A') == 193) ? 0x6f : 0x3f &&
107 printf "not ok 11 # [%s] [%s] %d\n",
108 join(" ", unpack("H*", $buf1)),
109 join(" ", unpack("H*", $buf2)), $offset;
113 print "not ok 11 # open failed: $!\n";
118 # Check there is no Use of uninitialized value in concatenation (.) warning
119 # due to the way @latin2iso_num was used to make aliases.
120 if (open(FAIL, ">:encoding(latin42)", $fail2)) {
121 print "not ok 12 # Open should fail\n";
125 if (!defined $warn) {
126 print "not ok 13 # warning is undef\n";
127 } elsif ($warn =~ /^Cannot find encoding "latin42" at.*line \d+\.$/) {
130 print "not ok 13 # warning is: \n";
135 # Create a string of chars that are 3 bytes in UTF-8
136 my $str = "\x{1f80}" x 2048;
138 # Write them to a file
139 open(F,'>:utf8',$threebyte) || die "Cannot open $threebyte:$!";
143 # Read file back as UTF-8
144 open(F,'<:encoding(utf-8)',$threebyte) || die "Cannot open $threebyte:$!";
147 print "not " unless ($dstr eq $str);
151 unlink($grk, $utf, $fail1, $fail2, $russki, $threebyte);