Integrate mainline
[p5sagit/p5-mst-13.2.git] / ext / Encode / t / JP.t
CommitLineData
0a95303c 1BEGIN {
2# chdir 't' if -d 't';
3# @INC = (-d '../../lib' ? '../lib';
4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bEncode\b/) {
6 print "1..0 # Skip: Encode was not built\n";
7 exit 0;
8 }
9 $| = 1;
10}
8e0fc1cd 11use strict;
0a95303c 12use Test::More tests => 22;
13use Encode;
14use File::Basename;
15use File::Spec;
16use File::Compare;
8e0fc1cd 17require_ok "Encode::JP";
18
19my ($src, $uni, $dst, $txt);
0a95303c 20
21ok(defined(my $enc = find_encoding('euc-jp')));
22ok($enc->isa('Encode::XS'));
23is($enc->name,'euc-jp');
24my $dir = dirname(__FILE__);
25my $euc = File::Spec->catfile($dir,"table.euc");
26my $utf = File::Spec->catfile($dir,"table.utf8");
27my $ref = File::Spec->catfile($dir,"table.ref");
28my $rnd = File::Spec->catfile($dir,"table.rnd");
29print "# Basic decode test\n";
8e0fc1cd 30open($src,"<",$euc) || die "Cannot open $euc:$!";
0a95303c 31ok(defined($src) && fileno($src));
8e0fc1cd 32$txt = join('',<$src>);
33open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
0a95303c 34ok(defined($dst) && fileno($dst));
8e0fc1cd 35$uni = $enc->decode($txt,1);
0a95303c 36ok(defined($uni));
37is(length($txt),0);
38print $dst $uni;
39close($dst);
40close($src);
41ok(compare($utf,$ref) == 0);
42
43print "# Basic encode test\n";
8e0fc1cd 44open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
0a95303c 45ok(defined($src) && fileno($src));
8e0fc1cd 46$uni = join('',<$src>);
47open($dst,">",$rnd) || die "Cannot open $rnd:$!";
0a95303c 48ok(defined($dst) && fileno($dst));
8e0fc1cd 49$txt = $enc->encode($uni,1);
0a95303c 50ok(defined($txt));
51is(length($uni),0);
52print $dst $txt;
53close($dst);
54close($src);
55ok(compare($euc,$rnd) == 0);
56
57is($enc->name,'euc-jp');
58
59print "# src :encoding test\n";
8e0fc1cd 60open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
0a95303c 61ok(defined($src) && fileno($src));
8e0fc1cd 62open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
0a95303c 63ok(defined($dst) || fileno($dst));
8e0fc1cd 64my $out = select($dst);
0a95303c 65while (<$src>)
66 {
67 print;
68 }
69close($dst);
70close($src);
71ok(compare($utf,$ref) == 0);
72select($out);
73
74SKIP:
75{
25f7d9d3 76 #skip "Multi-byte write is broken",3;
0a95303c 77 print "# dst :encoding test\n";
8e0fc1cd 78 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
0a95303c 79 ok(defined($src) || fileno($src));
8e0fc1cd 80 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
0a95303c 81 ok(defined($dst) || fileno($dst));
82 my $out = select($dst);
83 while (<$src>)
84 {
85 print;
86 }
87 close($dst);
88 close($src);
89 ok(compare($euc,$rnd) == 0);
90 select($out);
91}
92
93is($enc->name,'euc-jp');
94END {
95# unlink($utf,$rnd);
96
97}