[Patch] ext/PerlIO/t/fallback.t gets haircut
[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');
709a84d3 8 plan (9);
1982da40 9}
10use Encode qw(:fallback_all);
11
12# $PerlIO::encoding = 0; # WARN_ON_ERR|PERLQQ;
13
14my $file = "fallback$$.txt";
15
709a84d3 16{
17 my $message = '';
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");
21 my $str = "\x{20AC}";
22 print $fh $str,"0.02\n";
23 close($fh);
24 like($message, qr/does not map to iso-8859-1/o, "FB_WARN message");
25}
1982da40 26
27open($fh,$file) || die "File cannot be re-opened";
28my $line = <$fh>;
29is($line,"\\x{20ac}0.02\n","perlqq escapes");
30close($fh);
31
32$PerlIO::encoding::fallback = Encode::HTMLCREF;
33
34ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file");
35my $str = "\x{20AC}";
36print $fh $str,"0.02\n";
37close($fh);
38
39open($fh,$file) || die "File cannot be re-opened";
40my $line = <$fh>;
41is($line,"&#8364;0.02\n","HTML escapes");
42close($fh);
43
44open($fh,">$file") || die "File cannot be re-opened";
45print $fh "£0.02\n";
46close($fh);
47
48ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
49my $line = <$fh>;
50printf "# %x\n",ord($line);
51is($line,"\\xA30.02\n","Escaped non-mapped char");
52close($fh);
53
54$PerlIO::encoding::fallback = Encode::WARN_ON_ERROR;
55
56ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
57my $line = <$fh>;
58printf "# %x\n",ord($line);
59is($line,"\x{FFFD}0.02\n","Unicode replacement char");
60close($fh);
61
62END {
cd5e0f48 63 1 while unlink($file);
1982da40 64}
65
66
67