| 1 |
#!perl |
| 2 |
# cjk_test: the whole tests for CJK/*.pm |
| 3 |
# |
| 4 |
# input files: ../Collate/CJK/*.pm |
| 5 |
# |
| 6 |
# * All successful when the output is as below: |
| 7 |
# |
| 8 |
# OK - ja compare |
| 9 |
# OK - ja count |
| 10 |
# OK - ko compare |
| 11 |
# OK - ko count |
| 12 |
# OK - zh_big5 compare |
| 13 |
# OK - zh_big5 count |
| 14 |
# OK - zh_gb2312 compare |
| 15 |
# OK - zh_gb2312 count |
| 16 |
# OK - zh_pinyin compare |
| 17 |
# OK - zh_pinyin count |
| 18 |
# OK - zh_stroke compare |
| 19 |
# OK - zh_stroke count |
| 20 |
# OK - zh_zhuyin compare |
| 21 |
# OK - zh_zhuyin count |
| 22 |
# |
| 23 |
use strict; |
| 24 |
|
| 25 |
use File::Spec; |
| 26 |
use Unicode::Collate::Locale; |
| 27 |
|
| 28 |
my %file = qw( |
| 29 |
zh_big5 Big5 |
| 30 |
zh_gb2312 GB2312 |
| 31 |
ja JISX0208 |
| 32 |
ko Korean |
| 33 |
zh_pinyin Pinyin |
| 34 |
zh_stroke Stroke |
| 35 |
zh_zhuyin Zhuyin |
| 36 |
); |
| 37 |
|
| 38 |
sub testdata ($$) { |
| 39 |
my $locale = shift; |
| 40 |
my $file = $file{$locale}; |
| 41 |
my $count = shift; |
| 42 |
my $korean = $locale eq 'ko'; # Hangul <2 Unified Ideographs. |
| 43 |
|
| 44 |
my $d = File::Spec->updir(); |
| 45 |
my $f = File::Spec->catfile($d, 'Collate', 'CJK', "$file.pm"); |
| 46 |
open my $fh, "<$f" or die $f; |
| 47 |
|
| 48 |
my $col = Unicode::Collate::Locale->new(locale => $locale, level => 1); |
| 49 |
my $pre = undef; |
| 50 |
my $prc = ''; |
| 51 |
my @err; |
| 52 |
my $done = 0; |
| 53 |
while (<$fh>) { |
| 54 |
if (!defined $pre) { |
| 55 |
$pre = '' if /^__DATA__/; |
| 56 |
next; |
| 57 |
} |
| 58 |
last if /^__END__/; |
| 59 |
my @c = split; |
| 60 |
for my $c (@c) { |
| 61 |
++$done; |
| 62 |
$c =~ s/:.*//; # format change, Korean 1.13 |
| 63 |
my $u = pack('U*', map hex, split '-', $c); |
| 64 |
if ($korean) { |
| 65 |
$col->change(level => 1); |
| 66 |
if (@c != 1 || $c[0] !~ /^[A-D]/) { # not Hangul |
| 67 |
push @err, "$c($prc)" unless $col->eq($pre, $u); |
| 68 |
$col->change(level => 2); |
| 69 |
} |
| 70 |
} |
| 71 |
push @err, "$c($prc)" unless $col->lt($pre, $u); |
| 72 |
push @err, "$c(A)" unless $col->lt('A', $u); |
| 73 |
$pre = $u; |
| 74 |
$prc = $c; |
| 75 |
} |
| 76 |
} |
| 77 |
print @err ? "NG @err" : "OK", " - $locale compare\n"; |
| 78 |
print $count != $done ? "NG $done" : "OK", " - $locale count\n"; |
| 79 |
close $fh; |
| 80 |
} |
| 81 |
|
| 82 |
testdata('ja', 6355); |
| 83 |
testdata('ko', 7953); |
| 84 |
testdata('zh_big5', 13060); |
| 85 |
testdata('zh_gb2312', 6768); |
| 86 |
testdata('zh_pinyin', 20916); # 2.0 short |
| 87 |
testdata('zh_stroke', 23684); # 2.0 short |
| 88 |
testdata('zh_zhuyin', 22160); # 22 short |
| 89 |
|
| 90 |
__END__ |
| 91 |
|
| 92 |
past test counts: |
| 93 |
|
| 94 |
testdata('zh_pinyin', 20893); # 2.0 short without U+FDD0 |
| 95 |
testdata('zh_pinyin', 20861); # 1.9.1 short |
| 96 |
testdata('zh_pinyin', 20994); # 1.8.1 |
| 97 |
|
| 98 |
testdata('zh_stroke', 23647); # 1.9.1 short |
| 99 |
testdata('zh_stroke', 13057); # 1.8.1 |