Encode 0.90 (the one with jisx0212-1990) from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / t / JP.t
index 31ba2da..7b4bf14 100644 (file)
@@ -1,6 +1,6 @@
 BEGIN {
-    chdir 't' if -d 't';
-    @INC = '../lib';
+    chdir 't' if -d 't' and $ENV{PWD} !~ m,/Encode[^/]*$,o;
+    unshift @INC, '../lib';
     require Config; import Config;
     if ($Config{'extensions'} !~ /\bEncode\b/) {
       print "1..0 # Skip: Encode was not built\n";
@@ -17,38 +17,44 @@ BEGIN {
     $| = 1;
 }
 use strict;
-use Test::More tests => 22;
+use Test::More tests => 27;
 use Encode;
 use File::Basename;
 use File::Spec;
 use File::Compare;
 require_ok "Encode::JP";
 
-my ($src, $uni, $dst, $txt);
+my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
 
 ok(defined(my $enc = find_encoding('euc-jp')));
 ok($enc->isa('Encode::XS'));
 is($enc->name,'euc-jp');
 my $dir = dirname(__FILE__);
-my $euc = File::Spec->catfile($dir,"table.euc");
-my $utf = File::Spec->catfile($dir,"$$.utf8");
-my $ref = File::Spec->catfile($dir,"table.ref");
-my $rnd = File::Spec->catfile($dir,"$$.rnd");
-print "# Basic decode test\n";
-open($src,"<",$euc) || die "Cannot open $euc:$!";
-binmode($src);
-ok(defined($src) && fileno($src));
-$txt = join('',<$src>);
-open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
-binmode($dst);
-ok(defined($dst) && fileno($dst));
-$uni = $enc->decode($txt,1);
-ok(defined($uni));
-is(length($txt),0);
-print $dst $uni;
-close($dst);
-close($src);
-ok(compare($utf,$ref) == 0);
+
+my @subcodings = qw(jisx0212 jisx0208);
+
+for my $subcoding (@subcodings){
+    $euc = File::Spec->catfile($dir,"$subcoding.euc");
+    $utf = File::Spec->catfile($dir,"$$.utf8");
+    $ref = File::Spec->catfile($dir,"$subcoding.ref");
+    $rnd = File::Spec->catfile($dir,"$$.rnd");
+    print "# Basic decode test\n";
+    open($src,"<",$euc) || die "Cannot open $euc:$!";
+    binmode($src);
+    ok(defined($src) && fileno($src));
+    $txt = join('',<$src>);
+    open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
+    binmode($dst);
+    ok(defined($dst) && fileno($dst));
+    eval{ $uni = $enc->decode($txt,1) };
+    $@ and print $@;
+    ok(defined($uni));
+    is(length($txt),0);
+    print $dst $uni;
+    close($dst);
+    close($src);
+    ok(compare($utf,$ref) == 0);
+}
 
 print "# Basic encode test\n";
 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";