Commit | Line | Data |
1982da40 |
1 | #!./perl |
2 | |
3 | BEGIN { |
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 | } |
10 | use Encode qw(:fallback_all); |
11 | |
12 | # $PerlIO::encoding = 0; # WARN_ON_ERR|PERLQQ; |
13 | |
14 | my $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 | |
27 | open($fh,$file) || die "File cannot be re-opened"; |
28 | my $line = <$fh>; |
29 | is($line,"\\x{20ac}0.02\n","perlqq escapes"); |
30 | close($fh); |
31 | |
32 | $PerlIO::encoding::fallback = Encode::HTMLCREF; |
33 | |
34 | ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file"); |
35 | my $str = "\x{20AC}"; |
36 | print $fh $str,"0.02\n"; |
37 | close($fh); |
38 | |
39 | open($fh,$file) || die "File cannot be re-opened"; |
40 | my $line = <$fh>; |
41 | is($line,"€0.02\n","HTML escapes"); |
42 | close($fh); |
43 | |
44 | open($fh,">$file") || die "File cannot be re-opened"; |
45 | print $fh "£0.02\n"; |
46 | close($fh); |
47 | |
48 | ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII"); |
49 | my $line = <$fh>; |
50 | printf "# %x\n",ord($line); |
51 | is($line,"\\xA30.02\n","Escaped non-mapped char"); |
52 | close($fh); |
53 | |
54 | $PerlIO::encoding::fallback = Encode::WARN_ON_ERROR; |
55 | |
56 | ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII"); |
57 | my $line = <$fh>; |
58 | printf "# %x\n",ord($line); |
59 | is($line,"\x{FFFD}0.02\n","Unicode replacement char"); |
60 | close($fh); |
61 | |
62 | END { |
cd5e0f48 |
63 | 1 while unlink($file); |
1982da40 |
64 | } |
65 | |
66 | |
67 | |