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