Commit | Line | Data |
---|---|---|
3f60a930 AC |
1 | BEGIN { |
2 | if ($ENV{'PERL_CORE'}) { | |
3 | chdir 't'; | |
4 | unshift @INC, '../lib'; | |
5 | } | |
6 | require Config; import Config; | |
7 | if ($Config{'extensions'} !~ /\bEncode\b/) { | |
8 | print "1..0 # Skip: Encode was not built\n"; | |
9 | exit 0; | |
10 | } | |
11 | if (ord("A") == 193) { | |
12 | print "1..0 # Skip: EBCDIC\n"; | |
13 | exit 0; | |
14 | } | |
d26b5e1d DK |
15 | if ( $] < 5.009 ) { |
16 | print "1..0 # Skip: Perl <= 5.9 or later required\n"; | |
17 | exit 0; | |
18 | } | |
3f60a930 AC |
19 | $| = 1; |
20 | } | |
21 | ||
22 | use strict; | |
23 | use warnings; | |
24 | ||
25 | use Encode; | |
26 | use PerlIO::encoding; | |
27 | $PerlIO::encoding::fallback &= ~(Encode::WARN_ON_ERR|Encode::PERLQQ); | |
28 | ||
29 | use Test::More tests => 9; | |
30 | ||
31 | binmode Test::More->builder->failure_output, ":utf8"; | |
32 | binmode Test::More->builder->todo_output, ":utf8"; | |
33 | ||
34 | is(decode("UTF-8", "\xfd\xfe"), "\x{fffd}" x 2); | |
35 | is(decode("UTF-8", "\xfd\xfe\xff"), "\x{fffd}" x 3); | |
36 | is(decode("UTF-8", "\xfd\xfe\xff\xe0"), "\x{fffd}" x 4); | |
37 | is(decode("UTF-8", "\xfd\xfe\xff\xe0\xe1"), "\x{fffd}" x 5); | |
38 | is(decode("UTF-8", "\xc1\x9f"), "\x{fffd}"); | |
39 | is(decode("UTF-8", "\xFF\x80\x90\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80"), "\x{fffd}"); | |
40 | is(decode("UTF-8", "\xF0\x80\x80\x80"), "\x{fffd}"); | |
41 | ||
42 | SKIP: { | |
43 | # infinite loop due to bug: https://rt.perl.org/Public/Bug/Display.html?id=41442 | |
44 | skip "Perl Version ($]) is older than v5.8.9", 2 if $] < 5.008009; | |
45 | my $str = ("x" x 1023) . "\xfd\xfe\xffx"; | |
46 | open my $fh, '<:encoding(UTF-8)', \$str; | |
47 | my $str2 = <$fh>; | |
48 | close $fh; | |
49 | is($str2, ("x" x 1023) . ("\x{fffd}" x 3) . "x"); | |
50 | ||
51 | TODO: { | |
836bb1e3 | 52 | local $TODO = "bug in perlio" if $] < 5.027009; |
3f60a930 AC |
53 | my $str = ("x" x 1023) . "\xfd\xfe\xff"; |
54 | open my $fh, '<:encoding(UTF-8)', \$str; | |
55 | my $str2 = <$fh>; | |
56 | close $fh; | |
57 | is($str2, ("x" x 1023) . ("\x{fffd}" x 3)); | |
58 | } | |
59 | } |