Upgrade to Encode 1.89. The enc_module.t required
[p5sagit/p5-mst-13.2.git] / ext / Encode / t / enc_eucjp.t
1 # $Id: enc_eucjp.t,v 1.3 2003/02/20 14:42:34 dankogai Exp $
2 # This is the twin of enc_utf8.t .
3
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     if ($] <= 5.008 and !$Config{perl_patchlevel}){
19         print "1..0 # Skip: Perl 5.8.1 or later required\n";
20         exit 0;
21     }
22 }
23
24 use encoding 'euc-jp';
25
26 my @c = (127, 128, 255, 256);
27
28 print "1.." . (scalar @c + 1) . "\n";
29
30 my @f;
31
32 for my $i (0..$#c) {
33   push @f, "f$i";
34   open(F, ">f$i") or die "$0: failed to open 'f$i' for writing: $!";
35   binmode(F, ":utf8");
36   print F chr($c[$i]);
37   print F pack("C" => $c[$i]);
38   close F;
39 }
40
41 my $t = 1;
42
43 for my $i (0..$#c) {
44   open(F, "<f$i") or die "$0: failed to open 'f$i' for reading: $!";
45   binmode(F, ":utf8");
46   my $c = <F>;
47   my $o = ord($c);
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";
49   $t++;
50 }
51
52 my $f = "f" . @f;
53
54 push @f, $f;
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.
58 close F;
59 open(F, $f) or die "$0: failed to open '$f' for reading: $!";
60 binmode(F, ":encoding(utf-8)");
61 {
62         local $^W = 1;
63         local $SIG{__WARN__} = sub { $a = shift };
64         eval { <F> }; # This should get caught.
65 }
66 close F;
67 print $a =~ qr{^utf8 "\\x80" does not map to Unicode} ?
68   "ok $t - illegal utf8 input\n" : "not ok $t - illegal utf8 input: a = " . unpack("H*", $a) . "\n";
69
70 END {
71   1 while unlink @f;
72 }