Add a test for for PerlIO ":encoding(...)" layer.
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 10 Jul 2001 03:50:18 +0000 (03:50 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Tue, 10 Jul 2001 03:50:18 +0000 (03:50 +0000)
p4raw-id: //depot/perl@11249

MANIFEST
ext/Encode/Encode.pm
ext/PerlIO/t/encoding.t [new file with mode: 0644]

index efe3026..ba99ec8 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -426,6 +426,7 @@ ext/PerlIO/PerlIO.t         See if PerlIO works
 ext/PerlIO/Scalar/Makefile.PL  PerlIO layer for scalars
 ext/PerlIO/Scalar/Scalar.pm    PerlIO layer for scalars
 ext/PerlIO/Scalar/Scalar.xs    PerlIO layer for scalars
+ext/PerlIO/t/encoding.t                See if PerlIo encoding conversion works
 ext/PerlIO/t/scalar.t          Test of PerlIO::Scalar
 ext/PerlIO/Via/Makefile.PL     PerlIO layer for layers in perl
 ext/PerlIO/Via/Via.pm          PerlIO layer for layers in perl
index 4e55f46..b84623a 100644 (file)
@@ -739,9 +739,15 @@ If Perl is configured to use the new 'perlio' IO system then
 C<Encode> provides a "layer" (See L<perliol>) which can transform
 data as it is read or written.
 
+Here is how the blind poet would modernise the encoding:
+
     use Encode;
-    open(my $ilyad,'>:encoding(iso-8859-7)','ilyad.greek');
-    print $ilyad @epic;
+    open(my $iliad,'<:encoding(iso-8859-7)','iliad.greek');
+    open(my $utf8,'>:utf8','iliad.utf8');
+    my @epic = <$iliad>;
+    print $utf8 @epic;
+    close($utf8);
+    close($illiad);
 
 In addition the new IO system can also be configured to read/write
 UTF-8 encoded characters (as noted above this is efficient):
diff --git a/ext/PerlIO/t/encoding.t b/ext/PerlIO/t/encoding.t
new file mode 100644 (file)
index 0000000..bfae3ed
--- /dev/null
@@ -0,0 +1,49 @@
+my $grk = "grk$$";
+my $utf = "utf$$";
+
+if (open(GRK, ">$grk")) {
+    # alpha beta gamma in ISO 8859-7
+    print GRK "\xe1\xe2\xe3";
+    close GRK;
+}
+
+{
+    use Encode;
+    open(my $i,'<:encoding(iso-8859-7)',$grk);
+    print "ok 1\n";
+    open(my $o,'>:utf8',$utf);
+    print "ok 2\n";
+    print $o readline($i);
+    print "ok 3\n";
+    close($o);
+    close($i);
+}
+
+if (open(UTF, "<$utf")) {
+    # alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3)
+    print "not " unless <UTF> eq "\xce\xb1\xce\xb2\xce\xb3";
+    print "ok 4\n";
+    close $grk;
+}
+
+{
+    use Encode;
+    open(my $i,'<:utf8',$utf);
+    print "ok 5\n";
+    open(my $o,'>:encoding(iso-8859-7)',$grk);
+    print "ok 6\n";
+    print $o readline($i);
+    print "ok 7\n";
+    close($o);
+    close($i);
+}
+
+if (open(GRK, "<$grk")) {
+    print "not " unless <GRK> eq "\xe1\xe2\xe3";
+    print "ok 8\n";
+    close $grk;
+}
+
+END {
+    unlink($grk, $utf);
+}