Don't test $! with like() since one may have
[p5sagit/p5-mst-13.2.git] / ext / PerlIO / t / fallback.t
CommitLineData
1982da40 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require "../t/test.pl";
7 skip_all("No perlio") unless (find PerlIO::Layer 'perlio');
982a4085 8 if (ord("A") == 193) {
9 print "1..0 # Skip: EBCDIC\n";
10 exit 0;
11 }
709a84d3 12 plan (9);
1982da40 13}
14use Encode qw(:fallback_all);
15
16# $PerlIO::encoding = 0; # WARN_ON_ERR|PERLQQ;
17
18my $file = "fallback$$.txt";
19
709a84d3 20{
21 my $message = '';
22 local $SIG{__WARN__} = sub { $message = $_[0] };
23 $PerlIO::encoding::fallback = Encode::PERLQQ;
24 ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file");
25 my $str = "\x{20AC}";
26 print $fh $str,"0.02\n";
27 close($fh);
28 like($message, qr/does not map to iso-8859-1/o, "FB_WARN message");
29}
1982da40 30
31open($fh,$file) || die "File cannot be re-opened";
32my $line = <$fh>;
33is($line,"\\x{20ac}0.02\n","perlqq escapes");
34close($fh);
35
36$PerlIO::encoding::fallback = Encode::HTMLCREF;
37
38ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file");
39my $str = "\x{20AC}";
40print $fh $str,"0.02\n";
41close($fh);
42
43open($fh,$file) || die "File cannot be re-opened";
44my $line = <$fh>;
45is($line,"&#8364;0.02\n","HTML escapes");
46close($fh);
47
48open($fh,">$file") || die "File cannot be re-opened";
49print $fh "£0.02\n";
50close($fh);
51
52ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
53my $line = <$fh>;
54printf "# %x\n",ord($line);
55is($line,"\\xA30.02\n","Escaped non-mapped char");
56close($fh);
57
58$PerlIO::encoding::fallback = Encode::WARN_ON_ERROR;
59
60ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
61my $line = <$fh>;
62printf "# %x\n",ord($line);
63is($line,"\x{FFFD}0.02\n","Unicode replacement char");
64close($fh);
65
66END {
cd5e0f48 67 1 while unlink($file);
1982da40 68}
69
70
71