6 require "../t/test.pl";
7 skip_all("No perlio") unless (find PerlIO::Layer 'perlio');
10 use Encode qw(:fallback_all);
12 # $PerlIO::encoding = 0; # WARN_ON_ERR|PERLQQ;
14 my $file = "fallback$$.txt";
18 local $SIG{__WARN__} = sub { $message = $_[0] };
19 $PerlIO::encoding::fallback = Encode::PERLQQ;
20 ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file");
22 print $fh $str,"0.02\n";
24 like($message, qr/does not map to iso-8859-1/o, "FB_WARN message");
27 open($fh,$file) || die "File cannot be re-opened";
29 is($line,"\\x{20ac}0.02\n","perlqq escapes");
32 $PerlIO::encoding::fallback = Encode::HTMLCREF;
34 ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file");
36 print $fh $str,"0.02\n";
39 open($fh,$file) || die "File cannot be re-opened";
41 is($line,"€0.02\n","HTML escapes");
44 open($fh,">$file") || die "File cannot be re-opened";
48 ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
50 printf "# %x\n",ord($line);
51 is($line,"\\xA30.02\n","Escaped non-mapped char");
54 $PerlIO::encoding::fallback = Encode::WARN_ON_ERROR;
56 ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
58 printf "# %x\n",ord($line);
59 is($line,"\x{FFFD}0.02\n","Unicode replacement char");
63 1 while unlink($file);