summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-01-13 23:13:02 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-01-13 23:13:02 +0000
commit06fb145cab43a2ded6cd129384406808a391c59a (patch)
tree3d58c6e261b7c399c589116977d9b915c7fdbb04
parent0f7c507f688c1f7ff05ce69abb8332c23e7ec07d (diff)
downloadperl-06fb145cab43a2ded6cd129384406808a391c59a.tar.gz
Add a test for encoding 'utf8'.
p4raw-id: //depot/perl@18479
-rw-r--r--MANIFEST1
-rw-r--r--ext/Encode/MANIFEST1
-rw-r--r--ext/Encode/t/enc_utf8.t63
3 files changed, 65 insertions, 0 deletions
diff --git a/MANIFEST b/MANIFEST
index 4e798d47b7..44a53a7680 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -259,6 +259,7 @@ ext/Encode/t/big5-hkscs.utf test data
ext/Encode/t/CJKT.t test script
ext/Encode/t/Encode.t test script
ext/Encode/t/Encoder.t test script
+ext/Encode/t/enc_utf8.t test script
ext/Encode/t/encoding.t test script
ext/Encode/t/fallback.t test script
ext/Encode/t/gb2312.enc test data
diff --git a/ext/Encode/MANIFEST b/ext/Encode/MANIFEST
index 77c189e808..cb4a0d8fe7 100644
--- a/ext/Encode/MANIFEST
+++ b/ext/Encode/MANIFEST
@@ -61,6 +61,7 @@ t/big5-eten.enc test data
t/big5-eten.utf test data
t/big5-hkscs.enc test data
t/big5-hkscs.utf test data
+t/enc_utf8.t test script
t/encoding.t test script
t/fallback.t test script
t/gb2312.enc test data
diff --git a/ext/Encode/t/enc_utf8.t b/ext/Encode/t/enc_utf8.t
new file mode 100644
index 0000000000..20eb288400
--- /dev/null
+++ b/ext/Encode/t/enc_utf8.t
@@ -0,0 +1,63 @@
+BEGIN {
+ require Config; import Config;
+ if ($Config{'extensions'} !~ /\bEncode\b/) {
+ print "1..0 # Skip: Encode was not built\n";
+ exit 0;
+ }
+ unless (find PerlIO::Layer 'perlio') {
+ print "1..0 # Skip: PerlIO was not built\n";
+ exit 0;
+ }
+ if (ord("A") == 193) {
+ print "1..0 # encoding pragma does not support EBCDIC platforms\n";
+ exit(0);
+ }
+}
+
+use encoding 'utf8';
+
+my @c = (127, 128, 255, 256);
+
+print "1.." . (scalar @c + 1) . "\n";
+
+my @f;
+
+for my $i (0..$#c) {
+ push @f, "f$i";
+ open(F, ">f$i") or die "$0: failed to open 'f$i' for writing: $!";
+ binmode(F, ":utf8");
+ print F chr($c[$i]);
+ close F;
+}
+
+my $t = 1;
+
+for my $i (0..$#c) {
+ open(F, "<f$i") or die "$0: failed to open 'f$i' for reading: $!";
+ binmode(F, ":utf8");
+ my $c = <F>;
+ my $o = ord($c);
+ print $o == $c[$i] ? "ok $t\n" : "not ok $t # $o != $c[$i]\n";
+ $t++;
+}
+
+my $f = "f4";
+
+push @f, $f;
+open(F, ">$f") or die "$0: failed to open '$f' for writing: $!";
+binmode(F, ":raw"); # Output raw bytes.
+print F chr(128); # Output illegal UTF-8.
+close F;
+open(F, $f) or die "$0: failed to open '$f' for reading: $!";
+binmode(F, ":encoding(utf-8)");
+{
+ local $^W = 1;
+ local $SIG{__WARN__} = sub { $a = shift };
+ eval { <F> }; # This should get caught.
+}
+print $a =~ qr{^utf8 "\\x80" does not map to Unicode} ?
+ "ok $t\n" : "not ok $t: $a\n";
+
+END {
+ 1 while unlink @f;
+}