6 require Config; import Config;
7 unless ($Config{'useperlio'}) {
8 print "1..0 # Skip: not perlio\n";
16 open(F,"+>:utf8",'a');
17 print F chr(0x100).'£';
18 print '#'.tell(F)."\n";
19 print "not " unless tell(F) == 4;
22 print '#'.tell(F)."\n";
23 print "not " unless tell(F) >= 5;
26 print "not " unless getc(F) eq chr(0x100);
28 print "not " unless getc(F) eq "£";
30 print "not " unless getc(F) eq "\n";
34 print "not " unless getc(F) eq chr(0xc4);
36 print "not " unless getc(F) eq chr(0x80);
38 print "not " unless getc(F) eq chr(0xc2);
40 print "not " unless getc(F) eq chr(0xa3);
42 print "not " unless getc(F) eq "\n";
46 print "not " unless scalar(<F>) eq "\x{100}£\n";
50 $count = read(F,$buf,2,1);
51 print "not " unless $count == 2;
53 print "not " unless $buf eq "\x{200}\x{100}£";
58 $a = chr(300); # This *is* UTF-encoded
59 $b = chr(130); # This is not.
61 open F, ">:utf8", 'a' or die $!;
65 open F, "<:utf8", 'a' or die $!;
68 print "not " unless $x eq chr(300);
71 open F, "a" or die $!; # Not UTF
74 print "not " unless $x eq chr(196).chr(172);
78 open F, ">:utf8", 'a' or die $!;
79 binmode(F); # we write a "\n" and then tell() - avoid CRLF issues.
83 { use bytes; $y = length($a);}
84 print "not " unless $x == $y;
88 { # Check byte length of $b
89 use bytes; my $y = length($b);
90 print "not " unless $y == 1;
94 print F $b,"\n"; # This upgrades $b!
96 { # Check byte length of $b
97 use bytes; my $y = length($b);
98 print "not " unless $y == 2;
103 { use bytes; $y += 3;}
104 print "not " unless $x == $y;
110 open F, "a" or die $!; # Not UTF
113 print "not " unless $x eq v196.172.194.130;
116 open F, "<:utf8", "a" or die $!;
120 print "not " unless $x eq chr(300).chr(130);
123 # Now let's make it suffer.
124 open F, ">", "a" or die $!;
125 eval { print F $a; };
126 print "not " unless $@ and $@ =~ /Wide character in print/i;
130 # Hm. Time to get more evil.
131 open F, ">:utf8", "a" or die $!;
133 binmode(F, ":bytes");
134 print F chr(130)."\n";
137 open F, "<", "a" or die $!;
139 print "not " unless $x eq v196.172.130;
143 open F, ">:utf8", "a" or die $!;
146 open F, ">>", "a" or die $!;
147 print F chr(130)."\n";
150 open F, "<", "a" or die $!;
152 print "not " unless $x eq v196.172.130;
155 # Now we have a deformed file.
156 open F, "<:utf8", "a" or die $!;
158 { local $SIG{__WARN__} = sub { print "ok 25\n"; };
159 eval { sprintf "%vd\n", $x; }