1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
1N/A require "../t/test.pl";
1N/A skip_all("No perlio") unless (find PerlIO::Layer 'perlio');
1N/A if (ord("A") == 193) {
1N/A print "1..0 # Skip: EBCDIC\n";
1N/A exit 0;
1N/A }
1N/A unless( eval { require Encode } ) {
1N/A print "1..0 # Skip: No Encode\n";
1N/A exit 0;
1N/A }
1N/A plan (9);
1N/A import Encode qw(:fallback_all);
1N/A}
1N/A
1N/A# $PerlIO::encoding = 0; # WARN_ON_ERR|PERLQQ;
1N/A
1N/Amy $file = "fallback$$.txt";
1N/A
1N/A{
1N/A my $message = '';
1N/A local $SIG{__WARN__} = sub { $message = $_[0] };
1N/A $PerlIO::encoding::fallback = Encode::PERLQQ;
1N/A ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file");
1N/A my $str = "\x{20AC}";
1N/A print $fh $str,"0.02\n";
1N/A close($fh);
1N/A like($message, qr/does not map to iso-8859-1/o, "FB_WARN message");
1N/A}
1N/A
1N/Aopen($fh,$file) || die "File cannot be re-opened";
1N/Amy $line = <$fh>;
1N/Ais($line,"\\x{20ac}0.02\n","perlqq escapes");
1N/Aclose($fh);
1N/A
1N/A$PerlIO::encoding::fallback = Encode::HTMLCREF;
1N/A
1N/Aok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file");
1N/Amy $str = "\x{20AC}";
1N/Aprint $fh $str,"0.02\n";
1N/Aclose($fh);
1N/A
1N/Aopen($fh,$file) || die "File cannot be re-opened";
1N/Amy $line = <$fh>;
1N/Ais($line,"&#8364;0.02\n","HTML escapes");
1N/Aclose($fh);
1N/A
1N/A{
1N/A no utf8;
1N/A open($fh,">$file") || die "File cannot be re-opened";
1N/A binmode($fh);
1N/A print $fh "\xA30.02\n";
1N/A close($fh);
1N/A}
1N/A
1N/Aok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
1N/Amy $line = <$fh>;
1N/Aprintf "# %x\n",ord($line);
1N/Ais($line,"\\xA30.02\n","Escaped non-mapped char");
1N/Aclose($fh);
1N/A
1N/A$PerlIO::encoding::fallback = Encode::WARN_ON_ERROR;
1N/A
1N/Aok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
1N/Amy $line = <$fh>;
1N/Aprintf "# %x\n",ord($line);
1N/Ais($line,"\x{FFFD}0.02\n","Unicode replacement char");
1N/Aclose($fh);
1N/A
1N/AEND {
1N/A 1 while unlink($file);
1N/A}