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'); |
982a4085 |
8 | if (ord("A") == 193) { |
9 | print "1..0 # Skip: EBCDIC\n"; |
10 | exit 0; |
11 | } |
709a84d3 |
12 | plan (9); |
1982da40 |
13 | } |
14 | use Encode qw(:fallback_all); |
15 | |
16 | # $PerlIO::encoding = 0; # WARN_ON_ERR|PERLQQ; |
17 | |
18 | my $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 | |
31 | open($fh,$file) || die "File cannot be re-opened"; |
32 | my $line = <$fh>; |
33 | is($line,"\\x{20ac}0.02\n","perlqq escapes"); |
34 | close($fh); |
35 | |
36 | $PerlIO::encoding::fallback = Encode::HTMLCREF; |
37 | |
38 | ok(open(my $fh,">encoding(iso-8859-1)",$file),"opened iso-8859-1 file"); |
39 | my $str = "\x{20AC}"; |
40 | print $fh $str,"0.02\n"; |
41 | close($fh); |
42 | |
43 | open($fh,$file) || die "File cannot be re-opened"; |
44 | my $line = <$fh>; |
45 | is($line,"€0.02\n","HTML escapes"); |
46 | close($fh); |
47 | |
48 | open($fh,">$file") || die "File cannot be re-opened"; |
49 | print $fh "£0.02\n"; |
50 | close($fh); |
51 | |
52 | ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII"); |
53 | my $line = <$fh>; |
54 | printf "# %x\n",ord($line); |
55 | is($line,"\\xA30.02\n","Escaped non-mapped char"); |
56 | close($fh); |
57 | |
58 | $PerlIO::encoding::fallback = Encode::WARN_ON_ERROR; |
59 | |
60 | ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII"); |
61 | my $line = <$fh>; |
62 | printf "# %x\n",ord($line); |
63 | is($line,"\x{FFFD}0.02\n","Unicode replacement char"); |
64 | close($fh); |
65 | |
66 | END { |
cd5e0f48 |
67 | 1 while unlink($file); |
1982da40 |
68 | } |
69 | |
70 | |
71 | |