summaryrefslogtreecommitdiff
path: root/ext/Encode/t/Japanese.t
blob: 20f5b2523a75157d4231cfd399971ca179c77c37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
BEGIN {
#   chdir 't' if -d 't';
#   @INC = (-d '../../lib' ? '../lib';
    require Config; import Config;
    if ($Config{'extensions'} !~ /\bEncode\b/) {
      print "1..0 # Skip: Encode was not built\n";
      exit 0;
    }
    $| = 1;
}
use Test::More tests => 22;
use Encode;
use File::Basename;
use File::Spec;
use File::Compare;
require_ok "Encode::Japanese";

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,"table.utf8");
my $ref = File::Spec->catfile($dir,"table.ref");
my $rnd = File::Spec->catfile($dir,"table.rnd");
print "# Basic decode test\n";
open(my $src,"<",$euc) || die "Cannot open $euc:$!";
ok(defined($src) && fileno($src));
my $txt = join('',<$src>);
open(my $dst,">:utf8",$utf) || die "Cannot open $utf:$!";
ok(defined($dst) && fileno($dst));
my $uni = $enc->decode($txt,1);
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(my $src,"<:utf8",$ref) || die "Cannot open $ref:$!";
ok(defined($src) && fileno($src));
my $uni = join('',<$src>);
open(my $dst,">",$rnd) || die "Cannot open $rnd:$!";
ok(defined($dst) && fileno($dst));
my $txt = $enc->encode($uni,1);
ok(defined($txt));
is(length($uni),0);
print $dst $txt;
close($dst);
close($src);
ok(compare($euc,$rnd) == 0);

is($enc->name,'euc-jp');

print "# src :encoding test\n";
open(my $src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
ok(defined($src) && fileno($src));
open(my $dst,">:utf8",$utf) || die "Cannot open $utf:$!";
ok(defined($dst) || fileno($dst));
$out = select($dst);
while (<$src>)
 {
  print;
 }
close($dst);
close($src);
ok(compare($utf,$ref) == 0);
select($out);

SKIP:
{
 #skip "Multi-byte write is broken",3;
 print "# dst :encoding test\n";
 open(my $src,"<:utf8",$ref) || die "Cannot open $ref:$!";
 ok(defined($src) || fileno($src));
 open(my $dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
 ok(defined($dst) || fileno($dst));
 my $out = select($dst);
 while (<$src>)
  {
   print;
  }
 close($dst);
 close($src);
 ok(compare($euc,$rnd) == 0);
 select($out);
}

is($enc->name,'euc-jp');
END {
# unlink($utf,$rnd);

}