1 # $Id: enc_utf8.t,v 1.2 2003/01/22 03:29:07 dankogai Exp $
2 # This is the twin of enc_eucjp.t, the only difference is that
3 # this has "use encoding 'utf8'".
7 # print "1..0 # Skip: Perl 5.8.1 or later required\n";
10 require Config; import Config;
11 if ($Config{'extensions'} !~ /\bEncode\b/) {
12 print "1..0 # Skip: Encode was not built\n";
15 unless (find PerlIO::Layer 'perlio') {
16 print "1..0 # Skip: PerlIO was not built\n";
19 if (ord("A") == 193) {
20 print "1..0 # encoding pragma does not support EBCDIC platforms\n";
27 my @c = (127, 128, 255, 256);
29 print "1.." . (scalar @c + 1) . "\n";
35 open(F, ">f$i") or die "$0: failed to open 'f$i' for writing: $!";
44 open(F, "<f$i") or die "$0: failed to open 'f$i' for reading: $!";
48 print $o == $c[$i] ? "ok $t - utf8 I/O $c[$i]\n" : "not ok $t - utf8 I/O $c[$i]: $o != $c[$i]\n";
55 open(F, ">$f") or die "$0: failed to open '$f' for writing: $!";
56 binmode(F, ":raw"); # Output raw bytes.
57 print F chr(128); # Output illegal UTF-8.
59 open(F, $f) or die "$0: failed to open '$f' for reading: $!";
60 binmode(F, ":encoding(utf-8)");
63 local $SIG{__WARN__} = sub { $a = shift };
64 eval { <F> }; # This should get caught.
66 print $a =~ qr{^utf8 "\\x80" does not map to Unicode} ?
67 "ok $t - illegal utf8 input\n" : "not ok $t - illegal utf8 input: a = " . unpack("H*", $a) . "\n";