This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Misplaced block end.
[perl5.git] / ext / Encode / t / JP.t
CommitLineData
0a95303c 1BEGIN {
f51e7ad5
JH
2 chdir 't' if -d 't';
3 @INC = '../lib';
0a95303c
NIS
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}
0e567a6c 11use strict;
0a95303c
NIS
12use Test::More tests => 22;
13use Encode;
14use File::Basename;
15use File::Spec;
16use File::Compare;
0e567a6c
JH
17require_ok "Encode::JP";
18
19my ($src, $uni, $dst, $txt);
0a95303c
NIS
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");
f51e7ad5 26my $utf = File::Spec->catfile($dir,"$$.utf8");
0a95303c 27my $ref = File::Spec->catfile($dir,"table.ref");
f51e7ad5 28my $rnd = File::Spec->catfile($dir,"$$.rnd");
0a95303c 29print "# Basic decode test\n";
0e567a6c 30open($src,"<",$euc) || die "Cannot open $euc:$!";
0a95303c 31ok(defined($src) && fileno($src));
0e567a6c
JH
32$txt = join('',<$src>);
33open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
0a95303c 34ok(defined($dst) && fileno($dst));
0e567a6c 35$uni = $enc->decode($txt,1);
0a95303c
NIS
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";
0e567a6c 44open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
0a95303c 45ok(defined($src) && fileno($src));
0e567a6c
JH
46$uni = join('',<$src>);
47open($dst,">",$rnd) || die "Cannot open $rnd:$!";
0a95303c 48ok(defined($dst) && fileno($dst));
0e567a6c 49$txt = $enc->encode($uni,1);
0a95303c
NIS
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";
0e567a6c 60open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
0a95303c 61ok(defined($src) && fileno($src));
0e567a6c 62open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
0a95303c 63ok(defined($dst) || fileno($dst));
0e567a6c 64my $out = select($dst);
0a95303c
NIS
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";
0e567a6c 78 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
0a95303c 79 ok(defined($src) || fileno($src));
0e567a6c 80 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
0a95303c
NIS
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 {
f51e7ad5 95 1 while unlink($utf,$rnd);
0a95303c 96}