From: Jarkko Hietaniemi Date: Tue, 10 Jul 2001 03:50:18 +0000 (+0000) Subject: Add a test for for PerlIO ":encoding(...)" layer. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8e86646e958d6dc7566f90f497756b5c18800b82;p=p5sagit%2Fp5-mst-13.2.git Add a test for for PerlIO ":encoding(...)" layer. p4raw-id: //depot/perl@11249 --- diff --git a/MANIFEST b/MANIFEST index efe3026..ba99ec8 100644 --- 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 diff --git a/ext/Encode/Encode.pm b/ext/Encode/Encode.pm index 4e55f46..b84623a 100644 --- a/ext/Encode/Encode.pm +++ b/ext/Encode/Encode.pm @@ -739,9 +739,15 @@ If Perl is configured to use the new 'perlio' IO system then C provides a "layer" (See L) 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 index 0000000..bfae3ed --- /dev/null +++ b/ext/PerlIO/t/encoding.t @@ -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 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 eq "\xe1\xe2\xe3"; + print "ok 8\n"; + close $grk; +} + +END { + unlink($grk, $utf); +}