Upgrade to Encode 1.57, 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 }
64ffdd5e 11 if (ord("A") == 193) {
12 print "1..0 # Skip: EBCDIC\n";
13 exit 0;
14 }
011b2d2f 15 unless (PerlIO::Layer->find('perlio')){
16 print "1..0 # Skip: PerlIO required\n";
17 exit 0;
18 }
64ffdd5e 19 $| = 1;
20}
21use strict;
011b2d2f 22use Test::More tests => 11;
64ffdd5e 23#use Test::More qw(no_plan);
24use Encode;
25use File::Basename;
26use File::Spec;
011b2d2f 27use File::Compare qw(compare_text);
64ffdd5e 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
011b2d2f 37for my $charset (qw(ksc5601)){
38 $euc = File::Spec->catfile($dir,"$charset.euc");
64ffdd5e 39 $utf = File::Spec->catfile($dir,"$$.utf8");
011b2d2f 40 $ref = File::Spec->catfile($dir,"$charset.ref");
64ffdd5e 41 $rnd = File::Spec->catfile($dir,"$$.rnd");
011b2d2f 42
43 open($src,"<",$euc) or die "Cannot open $euc:$!";
64ffdd5e 44 binmode($src);
64ffdd5e 45 $txt = join('',<$src>);
011b2d2f 46 close($src);
47
48 eval{ $uni = $enc->decode($txt, 1) };
64ffdd5e 49 $@ and print $@;
011b2d2f 50 ok(defined($uni), "decode $charset");
51 is(length($txt),0, "decode $charset completely");
52
53 open($dst,">:utf8",$utf) or die "Cannot open $utf:$!";
54 binmode($dst);
64ffdd5e 55 print $dst $uni;
011b2d2f 56 close($dst);
57 is(compare_text($utf, $ref), 0, "$utf eq $ref");
58
59 open $src, "<:utf8", $ref or die "$ref : $!";
60 binmode($src);
61 $uni = join('', <$src>);
62 close $src;
64ffdd5e 63
011b2d2f 64 for my $canon (qw(euc-kr)){
65 my $test = \&is;
66 if ($charset eq 'jisx0201'){
67 $canon eq 'iso-2022-jp' and $test = \&isnt;
68 $canon eq 'iso-2022-jp-1' and $test = \&isnt;
69 }elsif($charset eq 'jisx0212'){
70 $canon eq 'shiftjis' and $test = \&isnt;
71 $canon eq 'iso-2022-jp' and $test = \&isnt;
72 }
73 my $rt = ($test eq \&is) ? 'RT' : 'non-RT';
74 $test->($uni, decode($canon, encode($canon, $uni)),
75 "$rt $charset $canon");
76
77 }
64ffdd5e 78
011b2d2f 79 eval{ $txt = $enc->encode($uni,1) };
80 $@ and print $@;
81 ok(defined($txt), "encode $charset");
82 is(length($uni), 0, "encode $charset completely");
83
84 open($dst,">", $rnd) or die "Cannot open $utf:$!";
85 binmode($dst);
86 print $dst $txt;
87 close($dst);
88 is(compare_text($euc, $rnd), 0 => "$rnd eq $euc");
89}
64ffdd5e 90
64ffdd5e 91END {
92 1 while unlink($utf,$rnd);
93}