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 | } | |
15 | $| = 1; | |
16 | } | |
17 | ||
18 | use strict; | |
19 | use warnings; | |
20 | ||
21 | use Encode; | |
22 | use PerlIO::encoding; | |
23 | $PerlIO::encoding::fallback &= ~(Encode::WARN_ON_ERR|Encode::PERLQQ); | |
24 | ||
25 | use Test::More tests => 9; | |
26 | ||
27 | binmode Test::More->builder->failure_output, ":utf8"; | |
28 | binmode Test::More->builder->todo_output, ":utf8"; | |
29 | ||
30 | is(decode("UTF-8", "\xfd\xfe"), "\x{fffd}" x 2); | |
31 | is(decode("UTF-8", "\xfd\xfe\xff"), "\x{fffd}" x 3); | |
32 | is(decode("UTF-8", "\xfd\xfe\xff\xe0"), "\x{fffd}" x 4); | |
33 | is(decode("UTF-8", "\xfd\xfe\xff\xe0\xe1"), "\x{fffd}" x 5); | |
34 | is(decode("UTF-8", "\xc1\x9f"), "\x{fffd}"); | |
35 | is(decode("UTF-8", "\xFF\x80\x90\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80"), "\x{fffd}"); | |
36 | is(decode("UTF-8", "\xF0\x80\x80\x80"), "\x{fffd}"); | |
37 | ||
38 | SKIP: { | |
39 | # infinite loop due to bug: https://rt.perl.org/Public/Bug/Display.html?id=41442 | |
40 | skip "Perl Version ($]) is older than v5.8.9", 2 if $] < 5.008009; | |
41 | my $str = ("x" x 1023) . "\xfd\xfe\xffx"; | |
42 | open my $fh, '<:encoding(UTF-8)', \$str; | |
43 | my $str2 = <$fh>; | |
44 | close $fh; | |
45 | is($str2, ("x" x 1023) . ("\x{fffd}" x 3) . "x"); | |
46 | ||
47 | TODO: { | |
836bb1e3 | 48 | local $TODO = "bug in perlio" if $] < 5.027009; |
3f60a930 AC |
49 | my $str = ("x" x 1023) . "\xfd\xfe\xff"; |
50 | open my $fh, '<:encoding(UTF-8)', \$str; | |
51 | my $str2 = <$fh>; | |
52 | close $fh; | |
53 | is($str2, ("x" x 1023) . ("\x{fffd}" x 3)); | |
54 | } | |
55 | } |