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/],
57 $/ = "\x0a"; # may fix VMS problem for test #28 and #29
59 for my $src(sort keys %e) {
60 my $ufile = File::Spec->catfile($dir,"$src.utf");
61 open my $fh, "<:utf8", $ufile or die "$ufile : $!";
63 my $utext = join('' => @uline);
66 for my $e (@{$e{$src}}){
67 my $sfile = File::Spec->catfile($dir,"$$.sio");
68 my $pfile = File::Spec->catfile($dir,"$$.pio");
70 # first create a file without perlio
71 dump2file($sfile, &encode($e, $utext, 0));
73 # then create a file via perlio without autoflush
76 #local $TODO = "$e: !perlio_ok" unless (perlio_ok($e) or $DEBUG);
77 todo_skip "$e: !perlio_ok", 4 unless (perlio_ok($e) or $DEBUG);
78 no warnings 'uninitialized';
79 open $fh, ">:encoding($e)", $pfile or die "$sfile : $!";
84 is(compare_text($sfile, $pfile), 0 => ">:encoding($e)");
86 copy $sfile, "$sfile.$seq";
87 copy $pfile, "$pfile.$seq";
90 # this time print line by line.
91 # works even for ISO-2022 but not ISO-2022-KR
92 open $fh, ">:encoding($e)", $pfile or die "$sfile : $!";
99 is(compare_text($sfile, $pfile), 0 => ">:encoding($e) by lines");
101 copy $sfile, "$sfile.$seq";
102 copy $pfile, "$pfile.$seq";
105 open $fh, "<:encoding($e)", $pfile or die "$pfile : $!";
107 $dtext = join('' => <$fh>);
110 ok($utext eq $dtext, "<:encoding($e)");
112 dump2file("$sfile.$seq", $utext);
113 dump2file("$pfile.$seq", $dtext);
115 if (perlio_ok($e) or $DEBUG){
117 open $fh, "<:encoding($e)", $pfile or die "$pfile : $!";
118 while(defined(my $l = <$fh>)) {
124 ok($utext eq $dtext, "<:encoding($e) by lines");
126 dump2file("$sfile.$seq", $utext);
127 dump2file("$pfile.$seq", $dtext);
130 $DEBUG or unlink ($sfile, $pfile);
137 open my $fh, ">", $_[0] or die "$_[0]: $!";