1 # $Id: enc_utf8.t,v 2.0 2004/05/16 20:55:18 dankogai Exp $
2 # This is the twin of enc_eucjp.t .
5 require Config; import Config;
6 if ($Config{'extensions'} !~ /\bEncode\b/) {
7 print "1..0 # Skip: Encode was not built\n";
10 unless (find PerlIO::Layer 'perlio') {
11 print "1..0 # Skip: PerlIO was not built\n";
14 if (ord("A") == 193) {
15 print "1..0 # encoding pragma does not support EBCDIC platforms\n";
22 my @c = (127, 128, 255, 256);
24 print "1.." . (scalar @c + 1) . "\n";
29 my $file = filename("f$i");
31 open(F, ">$file") or die "$0: failed to open '$file' for writing: $!";
40 my $file = filename("f$i");
41 open(F, "<$file") or die "$0: failed to open '$file' for reading: $!";
45 print $o == $c[$i] ? "ok $t - utf8 I/O $c[$i]\n" : "not ok $t - utf8 I/O $c[$i]: $o != $c[$i]\n";
49 my $f = filename("f" . @f);
52 open(F, ">$f") or die "$0: failed to open '$f' for writing: $!";
53 binmode(F, ":raw"); # Output raw bytes.
54 print F chr(128); # Output illegal UTF-8.
56 open(F, $f) or die "$0: failed to open '$f' for reading: $!";
57 binmode(F, ":encoding(utf-8)");
60 local $SIG{__WARN__} = sub { $a = shift };
61 eval { <F> }; # This should get caught.
64 print $a =~ qr{^utf8 "\\x80" does not map to Unicode} ?
65 "ok $t - illegal utf8 input\n" : "not ok $t - illegal utf8 input: a = " . unpack("H*", $a) . "\n";
67 # On VMS temporary file names like "f0." may be more readable than "f0" since
68 # "f0" could be a logical name pointing elsewhere.
71 $name .= '.' if $^O eq 'VMS';