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