diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2002-04-28 10:08:05 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2002-04-28 10:08:05 +0000 |
commit | 1982da4048668033f4bb857b02c690606711056a (patch) | |
tree | b78140d455020650f6d958f2e8d8f549edfe95c9 /ext/PerlIO/t | |
parent | 6b5da1a3dd326d0fe0f59ec1ea7b9b5d72b2a49e (diff) | |
download | perl-1982da4048668033f4bb857b02c690606711056a.tar.gz |
Have :encoding() default to perlqq style fallbacks.
Add test for that.
p4raw-id: //depot/perlio@16246
Diffstat (limited to 'ext/PerlIO/t')
-rw-r--r-- | ext/PerlIO/t/fallback.t | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/ext/PerlIO/t/fallback.t b/ext/PerlIO/t/fallback.t new file mode 100644 index 0000000000..fd1b30c956 --- /dev/null +++ b/ext/PerlIO/t/fallback.t @@ -0,0 +1,63 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require "../t/test.pl"; + skip_all("No perlio") unless (find PerlIO::Layer 'perlio'); + plan (8); +} +use Encode qw(:fallback_all); + +# $PerlIO::encoding = 0; # WARN_ON_ERR|PERLQQ; + +my $file = "fallback$$.txt"; + +$PerlIO::encoding::fallback = Encode::PERLQQ; + +ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file"); +my $str = "\x{20AC}"; +print $fh $str,"0.02\n"; +close($fh); + +open($fh,$file) || die "File cannot be re-opened"; +my $line = <$fh>; +is($line,"\\x{20ac}0.02\n","perlqq escapes"); +close($fh); + +$PerlIO::encoding::fallback = Encode::HTMLCREF; + +ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file"); +my $str = "\x{20AC}"; +print $fh $str,"0.02\n"; +close($fh); + +open($fh,$file) || die "File cannot be re-opened"; +my $line = <$fh>; +is($line,"€0.02\n","HTML escapes"); +close($fh); + +open($fh,">$file") || die "File cannot be re-opened"; +print $fh "£0.02\n"; +close($fh); + +ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII"); +my $line = <$fh>; +printf "# %x\n",ord($line); +is($line,"\\xA30.02\n","Escaped non-mapped char"); +close($fh); + +$PerlIO::encoding::fallback = Encode::WARN_ON_ERROR; + +ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII"); +my $line = <$fh>; +printf "# %x\n",ord($line); +is($line,"\x{FFFD}0.02\n","Unicode replacement char"); +close($fh); + +END { +# unlink($file); +} + + + |