2 if ($ENV{'PERL_CORE'}){
4 unshift @INC, '../lib';
6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bEncode\b/) {
8 print "1..0 # Skip: Encode was not built\n";
11 if (ord("A") == 193) {
12 print "1..0 # Skip: EBCDIC\n";
15 unless (PerlIO::Layer->find('perlio')){
16 print "1..0 # Skip: PerlIO required\n";
25 use File::Compare qw(compare_text);
29 #use Test::More qw(no_plan);
30 use Test::More tests => 28;
37 @ARGV and $DEBUG = shift;
38 #require Encode::JP::JIS7;
39 #require Encode::KR::2022_KR;
40 #$Encode::JP::JIS7::DEBUG = $DEBUG;
46 my $dir = dirname(__FILE__);
50 jisx0208 => [ qw/euc-jp shiftjis 7bit-jis iso-2022-jp iso-2022-jp-1/],
51 #ksc5601 => [ qw/euc-kr iso-2022-kr/],
52 ksc5601 => [ qw/euc-kr/],
53 #gb2312 => [ qw/euc-cn hz/],
54 gb2312 => [ qw/euc-cn/],
58 for my $src(sort keys %e) {
59 my $ufile = File::Spec->catfile($dir,"$src.utf");
60 open my $fh, "<:utf8", $ufile or die "$ufile : $!";
62 my $utext = join('' => @uline);
65 for my $e (@{$e{$src}}){
66 my $sfile = File::Spec->catfile($dir,"$$.sio");
67 my $pfile = File::Spec->catfile($dir,"$$.pio");
69 # first create a file without perlio
70 dump2file($sfile, &encode($e, $utext, 0));
72 # then create a file via perlio without autoflush
75 #local $TODO = "$e: !perlio_ok" unless (perlio_ok($e) or $DEBUG);
76 todo_skip "$e: !perlio_ok", 4 unless (perlio_ok($e) or $DEBUG);
77 no warnings 'uninitialized';
78 open $fh, ">:encoding($e)", $pfile or die "$sfile : $!";
83 is(compare_text($sfile, $pfile), 0 => ">:encoding($e)");
85 copy $sfile, "$sfile.$seq";
86 copy $pfile, "$pfile.$seq";
89 # this time print line by line.
90 # works even for ISO-2022 but not ISO-2022-KR
91 open $fh, ">:encoding($e)", $pfile or die "$sfile : $!";
98 is(compare_text($sfile, $pfile), 0 => ">:encoding($e) by lines");
100 copy $sfile, "$sfile.$seq";
101 copy $pfile, "$pfile.$seq";
104 open $fh, "<:encoding($e)", $pfile or die "$pfile : $!";
106 $dtext = join('' => <$fh>);
109 ok($utext eq $dtext, "<:encoding($e)");
111 dump2file("$sfile.$seq", $utext);
112 dump2file("$pfile.$seq", $dtext);
114 if (perlio_ok($e) or $DEBUG){
116 open $fh, "<:encoding($e)", $pfile or die "$pfile : $!";
117 while(defined(my $l = <$fh>)) {
123 ok($utext eq $dtext, "<:encoding($e) by lines");
125 dump2file("$sfile.$seq", $utext);
126 dump2file("$pfile.$seq", $dtext);
129 $DEBUG or unlink ($sfile, $pfile);
136 open my $fh, ">", $_[0] or die "$_[0]: $!";