Commit | Line | Data |
64ffdd5e |
1 | BEGIN { |
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 | } |
21 | use strict; |
011b2d2f |
22 | use Test::More tests => 11; |
64ffdd5e |
23 | #use Test::More qw(no_plan); |
24 | use Encode; |
25 | use File::Basename; |
26 | use File::Spec; |
011b2d2f |
27 | use File::Compare qw(compare_text); |
64ffdd5e |
28 | require_ok "Encode::KR"; |
29 | |
30 | my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd); |
31 | |
32 | ok(defined(my $enc = find_encoding('euc-kr'))); |
33 | ok($enc->isa('Encode::XS')); |
34 | is($enc->name,'euc-kr'); |
35 | my $dir = dirname(__FILE__); |
36 | |
011b2d2f |
37 | for 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 |
91 | END { |
92 | 1 while unlink($utf,$rnd); |
93 | } |