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