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";
18 use Test::More tests => 37;
19 #use Test::More qw(no_plan);
24 require_ok "Encode::JP";
26 my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
28 ok(defined(my $enc = find_encoding('euc-jp')), 'find_encoding');
29 ok($enc->isa('Encode::XS'), 'ISA');
30 is($enc->name,'euc-jp', '$enc->name');
31 my $dir = dirname(__FILE__);
33 for my $charset (qw(jisx0201 jisx0212 jisx0208)){
34 $euc = File::Spec->catfile($dir,"$charset.euc");
35 $utf = File::Spec->catfile($dir,"$$.utf8");
36 $ref = File::Spec->catfile($dir,"$charset.ref");
37 $rnd = File::Spec->catfile($dir,"$$.rnd");
39 open($src,"<",$euc) or die "Cannot open $euc:$!";
41 $txt = join('',<$src>);
44 eval{ $uni = $enc->decode($txt, 1) };
46 ok(defined($uni), "decode $charset");
47 is(length($txt),0, "decode $charset completely");
49 open($dst,">:utf8",$utf) or die "Cannot open $utf:$!";
53 is(compare($utf, $ref), 0, "$utf eq $ref");
55 open $src, "<:utf8", $ref or die "$ref : $!";
56 $uni = join('', <$src>);
59 for my $canon (qw(euc-jp shiftjis
60 7bit-jis iso-2022-jp iso-2022-jp-1)){
62 if ($charset eq 'jisx0201'){
63 $canon eq 'iso-2022-jp' and $test = \&isnt;
64 $canon eq 'iso-2022-jp-1' and $test = \&isnt;
65 }elsif($charset eq 'jisx0212'){
66 $canon eq 'shiftjis' and $test = \&isnt;
67 $canon eq 'iso-2022-jp' and $test = \&isnt;
69 my $rt = ($test eq \&is) ? 'RT' : 'non-RT';
70 $test->($uni, decode($canon, encode($canon, $uni)),
71 "$rt $charset $canon");
75 eval{ $txt = $enc->encode($uni,1) };
77 ok(defined($txt), "encode $charset");
78 is(length($uni), 0, "encode $charset completely");
80 open($dst,">", $rnd) or die "Cannot open $utf:$!";
84 is(compare($euc, $rnd), 0 => "$rnd eq $euc");
88 1 while unlink($utf,$rnd);