This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [perl #24926] chop/~ mangles UTF8 [PATCH]
[perl5.git] / ext / Encode / t / grow.t
1 #!../perl
2 our $POWER;
3 BEGIN {
4      if ($ENV{'PERL_CORE'}){
5          chdir 't';
6          unshift @INC, '../lib';
7      }
8      require Config; import Config;
9      if ($Config{'extensions'} !~ /\bEncode\b/) {
10          print "1..0 # Skip: Encode was not built\n";
11              exit 0;
12      }
13      $POWER = 12; # up to 1 MB.  You may adjust the figure here
14 }
15
16 use strict;
17 use Encode;
18
19 my $seed = "";
20 for my $i (0x00..0xff){
21      my $c = chr($i);
22      $seed .= ($c =~ /^\p{IsPrint}/o) ? $c : " ";
23 }
24
25 use Test::More tests => $POWER*2;
26 my $octs = $seed;
27 use bytes ();
28 for my $i (1..$POWER){
29      $octs .= $octs;
30      my $len = bytes::length($octs);
31      my $utf8 = Encode::decode('latin1', $octs);
32      ok(1, "decode $len bytes");
33      is($octs,
34         Encode::encode('latin1', $utf8),
35         "encode $len bytes");
36 }
37 __END__
38
39