Upgrade to Encode 1.42, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / t / JP.t
CommitLineData
0a95303c 1BEGIN {
037b88d6 2 if ($ENV{'PERL_CORE'}){
3 chdir 't';
4 unshift @INC, '../lib';
5 }
0a95303c 6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bEncode\b/) {
8 print "1..0 # Skip: Encode was not built\n";
9 exit 0;
10 }
72f0eb71 11 if (ord("A") == 193) {
12 print "1..0 # Skip: EBCDIC\n";
13 exit 0;
14 }
0a95303c 15 $| = 1;
16}
0e567a6c 17use strict;
ee981de6 18use Test::More tests => 27;
fab31126 19#use Test::More qw(no_plan);
0a95303c 20use Encode;
21use File::Basename;
22use File::Spec;
23use File::Compare;
0e567a6c 24require_ok "Encode::JP";
25
ee981de6 26my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
0a95303c 27
28ok(defined(my $enc = find_encoding('euc-jp')));
29ok($enc->isa('Encode::XS'));
30is($enc->name,'euc-jp');
31my $dir = dirname(__FILE__);
ee981de6 32
33my @subcodings = qw(jisx0212 jisx0208);
34
35for my $subcoding (@subcodings){
36 $euc = File::Spec->catfile($dir,"$subcoding.euc");
37 $utf = File::Spec->catfile($dir,"$$.utf8");
38 $ref = File::Spec->catfile($dir,"$subcoding.ref");
39 $rnd = File::Spec->catfile($dir,"$$.rnd");
40 print "# Basic decode test\n";
41 open($src,"<",$euc) || die "Cannot open $euc:$!";
42 binmode($src);
43 ok(defined($src) && fileno($src));
44 $txt = join('',<$src>);
45 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
46 binmode($dst);
47 ok(defined($dst) && fileno($dst));
48 eval{ $uni = $enc->decode($txt,1) };
49 $@ and print $@;
50 ok(defined($uni));
51 is(length($txt),0);
52 print $dst $uni;
53 close($dst);
54 close($src);
55 ok(compare($utf,$ref) == 0);
56}
0a95303c 57
58print "# Basic encode test\n";
0e567a6c 59open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
a6a3912c 60binmode($src);
0a95303c 61ok(defined($src) && fileno($src));
0e567a6c 62$uni = join('',<$src>);
63open($dst,">",$rnd) || die "Cannot open $rnd:$!";
a6a3912c 64binmode($dst);
0a95303c 65ok(defined($dst) && fileno($dst));
0e567a6c 66$txt = $enc->encode($uni,1);
0a95303c 67ok(defined($txt));
68is(length($uni),0);
69print $dst $txt;
70close($dst);
71close($src);
72ok(compare($euc,$rnd) == 0);
73
74is($enc->name,'euc-jp');
75
b2704119 76my $skip_perlio;
77eval { require PerlIO::encoding; };
78if ($@){
79 $skip_perlio = 1;
80}else{
81 $skip_perlio = 0;
82 binmode(STDIN);
161720b2 83}
0a95303c 84
b2704119 85$skip_perlio ||= (@ARGV and shift eq 'perlio');
86
87SKIP: {
88 skip "PerlIO Encoding Needed", 6 if $skip_perlio;
89 print "# src :encoding test\n";
90 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
91 binmode($src);
92 ok(defined($src) && fileno($src));
93 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
94 binmode($dst);
95 ok(defined($dst) || fileno($dst));
96 my $out = select($dst);
97 while (<$src>){ print; }
98 close($dst);
99 close($src);
100
101 TODO:
102 {
103 local $TODO = 'needs debugging on VMS' if $^O eq 'VMS';
104 ok(compare($utf,$ref) == 0);
105 }
106 select($out);
107
108 print "# dst :encoding test\n";
109 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
110 binmode($src);
111 ok(defined($src) || fileno($src));
112 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
113 binmode($dst);
114 ok(defined($dst) || fileno($dst));
115 $out = select($dst);
116 while (<$src>) { print; }
117 close($dst);
118 close($src);
119 ok(compare($euc,$rnd) == 0);
120 select($out);
0a95303c 121}
122
123is($enc->name,'euc-jp');
fab31126 124
0a95303c 125END {
f51e7ad5 126 1 while unlink($utf,$rnd);
0a95303c 127}