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";
21 use File::Compare qw(compare_text);
25 #use Test::More qw(no_plan);
26 use Test::More tests => 28;
31 eval { require PerlIO::encoding };
35 @ARGV and $DEBUG = shift;
36 #require Encode::JP::JIS7;
37 #require Encode::KR::2022_KR;
38 #$Encode::JP::JIS7::DEBUG = $DEBUG;
44 my $dir = dirname(__FILE__);
48 jisx0208 => [ qw/euc-jp shiftjis 7bit-jis iso-2022-jp iso-2022-jp-1/],
49 #ksc5601 => [ qw/euc-kr iso-2022-kr/],
50 ksc5601 => [ qw/euc-kr/],
51 #gb2312 => [ qw/euc-cn hz/],
52 gb2312 => [ qw/euc-cn/],
56 for my $src(sort keys %e) {
57 my $ufile = File::Spec->catfile($dir,"$src.ref");
58 open my $fh, "<:utf8", $ufile or die "$ufile : $!";
60 my $utext = join('' => @uline);
63 for my $e (@{$e{$src}}){
64 my $sfile = File::Spec->catfile($dir,"$$.sio");
65 my $pfile = File::Spec->catfile($dir,"$$.pio");
67 # first create a file without perlio
68 dump2file($sfile, &encode($e, $utext, 0));
70 # then create a file via perlio without autoflush
73 #local $TODO = "$e: !perlio_ok" unless (perlio_ok($e) or $DEBUG);
74 todo_skip "$e: !perlio_ok", 4 unless (perlio_ok($e) or $DEBUG);
75 no warnings 'uninitialized';
76 open $fh, ">:encoding($e)", $pfile or die "$sfile : $!";
81 is(compare_text($sfile, $pfile), 0 => ">:encoding($e)");
83 copy $sfile, "$sfile.$seq";
84 copy $pfile, "$pfile.$seq";
87 # this time print line by line.
88 # works even for ISO-2022 but not ISO-2022-KR
89 open $fh, ">:encoding($e)", $pfile or die "$sfile : $!";
96 is(compare_text($sfile, $pfile), 0 => ">:encoding($e) by lines");
98 copy $sfile, "$sfile.$seq";
99 copy $pfile, "$pfile.$seq";
102 open $fh, "<:encoding($e)", $pfile or die "$pfile : $!";
104 $dtext = join('' => <$fh>);
107 ok($utext eq $dtext, "<:encoding($e)");
109 dump2file("$sfile.$seq", $utext);
110 dump2file("$pfile.$seq", $dtext);
112 if (perlio_ok($e) or $DEBUG){
114 open $fh, "<:encoding($e)", $pfile or die "$pfile : $!";
115 while(defined(my $l = <$fh>)) {
121 ok($utext eq $dtext, "<:encoding($e) by lines");
123 dump2file("$sfile.$seq", $utext);
124 dump2file("$pfile.$seq", $dtext);
127 $DEBUG or unlink ($sfile, $pfile);
134 open my $fh, ">", $_[0] or die "$_[0]: $!";