1BEGIN { 2 if ($ENV{'PERL_CORE'}) { 3 chdir 't'; 4 unshift @INC, '../lib'; 5 } 6 require Config; Config->import(); 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 if ( $] < 5.009 ) { 16 print "1..0 # Skip: Perl <= 5.9 or later required\n"; 17 exit 0; 18 } 19 $| = 1; 20} 21 22use strict; 23use warnings; 24 25use Encode; 26use PerlIO::encoding; 27$PerlIO::encoding::fallback &= ~(Encode::WARN_ON_ERR|Encode::PERLQQ); 28 29use Test::More tests => 9; 30 31binmode Test::More->builder->failure_output, ":utf8"; 32binmode Test::More->builder->todo_output, ":utf8"; 33 34is(decode("UTF-8", "\xfd\xfe"), "\x{fffd}" x 2); 35is(decode("UTF-8", "\xfd\xfe\xff"), "\x{fffd}" x 3); 36is(decode("UTF-8", "\xfd\xfe\xff\xe0"), "\x{fffd}" x 4); 37is(decode("UTF-8", "\xfd\xfe\xff\xe0\xe1"), "\x{fffd}" x 5); 38is(decode("UTF-8", "\xc1\x9f"), "\x{fffd}"); 39is(decode("UTF-8", "\xFF\x80\x90\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80"), "\x{fffd}"); 40is(decode("UTF-8", "\xF0\x80\x80\x80"), "\x{fffd}"); 41 42SKIP: { 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: { 52 local $TODO = "bug in perlio" if $] < 5.027009; 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} 60