Re: [ PATCH ] module test fest
[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
e028e334 48{
49 no utf8;
50 open($fh,">$file") || die "File cannot be re-opened";
51 print $fh "£0.02\n";
52 close($fh);
53}
1982da40 54
55ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
56my $line = <$fh>;
57printf "# %x\n",ord($line);
58is($line,"\\xA30.02\n","Escaped non-mapped char");
59close($fh);
60
61$PerlIO::encoding::fallback = Encode::WARN_ON_ERROR;
62
63ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
64my $line = <$fh>;
65printf "# %x\n",ord($line);
66is($line,"\x{FFFD}0.02\n","Unicode replacement char");
67close($fh);
68
69END {
cd5e0f48 70 1 while unlink($file);
1982da40 71}
72
73
74