Commit | Line | Data |
cc7dbc11 |
1 | # $Id: enc_utf8.t,v 1.3 2003/02/20 14:42:34 dankogai Exp dankogai $ |
2 | # This is the twin of enc_eucjp.t . |
88632417 |
3 | |
06fb145c |
4 | BEGIN { |
5 | require Config; import Config; |
6 | if ($Config{'extensions'} !~ /\bEncode\b/) { |
7 | print "1..0 # Skip: Encode was not built\n"; |
8 | exit 0; |
9 | } |
10 | unless (find PerlIO::Layer 'perlio') { |
11 | print "1..0 # Skip: PerlIO was not built\n"; |
12 | exit 0; |
13 | } |
14 | if (ord("A") == 193) { |
15 | print "1..0 # encoding pragma does not support EBCDIC platforms\n"; |
16 | exit(0); |
17 | } |
18 | } |
19 | |
20 | use encoding 'utf8'; |
21 | |
22 | my @c = (127, 128, 255, 256); |
23 | |
24 | print "1.." . (scalar @c + 1) . "\n"; |
25 | |
26 | my @f; |
27 | |
28 | for my $i (0..$#c) { |
29 | push @f, "f$i"; |
30 | open(F, ">f$i") or die "$0: failed to open 'f$i' for writing: $!"; |
31 | binmode(F, ":utf8"); |
32 | print F chr($c[$i]); |
33 | close F; |
34 | } |
35 | |
36 | my $t = 1; |
37 | |
38 | for my $i (0..$#c) { |
39 | open(F, "<f$i") or die "$0: failed to open 'f$i' for reading: $!"; |
40 | binmode(F, ":utf8"); |
41 | my $c = <F>; |
42 | my $o = ord($c); |
fa6f41cf |
43 | print $o == $c[$i] ? "ok $t - utf8 I/O $c[$i]\n" : "not ok $t - utf8 I/O $c[$i]: $o != $c[$i]\n"; |
06fb145c |
44 | $t++; |
45 | } |
46 | |
88632417 |
47 | my $f = "f" . @f; |
06fb145c |
48 | |
49 | push @f, $f; |
50 | open(F, ">$f") or die "$0: failed to open '$f' for writing: $!"; |
51 | binmode(F, ":raw"); # Output raw bytes. |
52 | print F chr(128); # Output illegal UTF-8. |
53 | close F; |
54 | open(F, $f) or die "$0: failed to open '$f' for reading: $!"; |
55 | binmode(F, ":encoding(utf-8)"); |
56 | { |
57 | local $^W = 1; |
58 | local $SIG{__WARN__} = sub { $a = shift }; |
59 | eval { <F> }; # This should get caught. |
60 | } |
cc7dbc11 |
61 | close F; |
06fb145c |
62 | print $a =~ qr{^utf8 "\\x80" does not map to Unicode} ? |
88632417 |
63 | "ok $t - illegal utf8 input\n" : "not ok $t - illegal utf8 input: a = " . unpack("H*", $a) . "\n"; |
06fb145c |
64 | |
65 | END { |
66 | 1 while unlink @f; |
67 | } |