Assorted 2.15 fixes.
[p5sagit/p5-mst-13.2.git] / ext / Encode / t / CJKT.t
index 4540034..1480439 100644 (file)
@@ -20,28 +20,27 @@ BEGIN {
     $| = 1;
 }
 use strict;
-use Test::More tests => 73;
-#use Test::More qw(no_plan);
+use Test::More tests => 60;
 use Encode;
 use File::Basename;
 use File::Spec;
 use File::Compare qw(compare_text);
-our $DEBUG;
+our $DEBUG = shift || 0;
 
 my %Charset =
     (
-     'big5-eten'  => [qw(big5-eten cp950 MacChineseTrad)],
+     'big5-eten'  => [qw(big5-eten)],
      'big5-hkscs' => [qw(big5-hkscs)],
-     gb2312       => [qw(euc-cn gb2312-raw cp936 MacChineseSimp)],
-     jisx0201     => [qw(euc-jp shiftjis 7bit-jis jis0201-raw
-                        cp932 MacJapanese)],
-     jisx0212     => [qw(euc-jp 7bit-jis iso-2022-jp-1 jis0208-raw)],
-     jisx0208     => [qw(euc-jp shiftjis 7bit-jis cp932 MacJapanese
-                    iso-2022-jp iso-2022-jp-1 jis0212-raw)],
-     ksc5601      => [qw(euc-kr iso-2022-kr ksc5601-raw cp949 MacKorean)],
+     gb2312       => [qw(euc-cn hz)],
+     jisx0201     => [qw(euc-jp shiftjis 7bit-jis)],
+     jisx0208     => [qw(euc-jp shiftjis 7bit-jis iso-2022-jp iso-2022-jp-1)],
+     jisx0212     => [qw(euc-jp 7bit-jis iso-2022-jp-1)],
+     ksc5601      => [qw(euc-kr iso-2022-kr johab)],
     );
 
+
 my $dir = dirname(__FILE__);
+my $seq = 1;
 
 for my $charset (sort keys %Charset){
     my ($src, $uni, $dst, $txt);
@@ -53,16 +52,19 @@ for my $charset (sort keys %Charset){
     my $dst_enc = File::Spec->catfile($dir,"$$.enc");
     my $dst_utf = File::Spec->catfile($dir,"$$.utf");
 
-
     open $src, "<$src_enc" or die "$src_enc : $!";
-    binmode($src);
+    
+    if (PerlIO::Layer->find('perlio')){
+       binmode($src, ":bytes"); # needed when :utf8 in default open layer
+    }
+
     $txt = join('',<$src>);
     close($src);
     
     eval{ $uni = $transcoder->decode($txt, 1) }; 
     $@ and print $@;
-    ok(defined($uni),  "decode $charset");
-    is(length($txt),0, "decode $charset completely");
+    ok(defined($uni),  "decode $charset"); $seq++;
+    is(length($txt),0, "decode $charset completely"); $seq++;
     
     open $dst, ">$dst_utf" or die "$dst_utf : $!";
     if (PerlIO::Layer->find('perlio')){
@@ -75,7 +77,9 @@ for my $charset (sort keys %Charset){
     }
 
     close($dst); 
-    is(compare_text($dst_utf, $src_utf), 0, "$dst_utf eq $src_utf");
+    is(compare_text($dst_utf, $src_utf), 0, "$dst_utf eq $src_utf")
+       or ($DEBUG and rename $dst_utf, "$dst_utf.$seq");
+    $seq++;
     
     open $src, "<$src_utf" or die "$src_utf : $!";
     if (PerlIO::Layer->find('perlio')){
@@ -88,20 +92,25 @@ for my $charset (sort keys %Charset){
     }
     close $src;
 
+    my $unisave = $uni;
     eval{ $txt = $transcoder->encode($uni,1) };    
     $@ and print $@;
-    ok(defined($txt),   "encode $charset");
-    is(length($uni), 0, "encode $charset completely");
+    ok(defined($txt),   "encode $charset"); $seq++;
+    is(length($uni), 0, "encode $charset completely");  $seq++;
+    $uni = $unisave;
 
     open $dst,">$dst_enc" or die "$dst_utf : $!";
     binmode($dst);
     print $dst $txt;
     close($dst); 
-    is(compare_text($src_enc, $dst_enc), 0 => "$dst_enc eq $src_enc");
+    is(compare_text($src_enc, $dst_enc), 0 => "$dst_enc eq $src_enc")
+       or ($DEBUG and rename $dst_enc, "$dst_enc.$seq");
+    $seq++;
+    
+    unlink($dst_utf, $dst_enc);
 
-    for my $canon (@{$Charset{$charset}}){
-       is($uni, decode($canon, encode($canon, $uni)), 
-          "RT/$charset/$canon");
-     }
-    $DEBUG or unlink($dst_utf, $dst_enc);
+    for my $encoding (@{$Charset{$charset}}){
+       my $rt = decode($encoding, encode($encoding, $uni));
+       is ($rt, $uni, "RT $encoding");
+    }
 }