This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Encode: truncated_utf8.t TODO passes
[perl5.git] / cpan / Encode / t / truncated_utf8.t
CommitLineData
3f60a930
AC
1BEGIN {
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
18use strict;
19use warnings;
20
21use Encode;
22use PerlIO::encoding;
23$PerlIO::encoding::fallback &= ~(Encode::WARN_ON_ERR|Encode::PERLQQ);
24
25use Test::More tests => 9;
26
27binmode Test::More->builder->failure_output, ":utf8";
28binmode Test::More->builder->todo_output, ":utf8";
29
30is(decode("UTF-8", "\xfd\xfe"), "\x{fffd}" x 2);
31is(decode("UTF-8", "\xfd\xfe\xff"), "\x{fffd}" x 3);
32is(decode("UTF-8", "\xfd\xfe\xff\xe0"), "\x{fffd}" x 4);
33is(decode("UTF-8", "\xfd\xfe\xff\xe0\xe1"), "\x{fffd}" x 5);
34is(decode("UTF-8", "\xc1\x9f"), "\x{fffd}");
35is(decode("UTF-8", "\xFF\x80\x90\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80"), "\x{fffd}");
36is(decode("UTF-8", "\xF0\x80\x80\x80"), "\x{fffd}");
37
38SKIP: {
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}