This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Updated Unicode-Collate to CPAN version 0.76
[perl5.git] / cpan / Unicode-Collate / t / cjk_ja.t
1
2 BEGIN {
3     unless ("A" eq pack('U', 0x41)) {
4         print "1..0 # Unicode::Collate " .
5             "cannot stringify a Unicode code point\n";
6         exit 0;
7     }
8     if ($ENV{PERL_CORE}) {
9         chdir('t') if -d 't';
10         @INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
11     }
12 }
13
14 use Test;
15 BEGIN { plan tests => 33 };
16
17 use strict;
18 use warnings;
19 use Unicode::Collate;
20
21 ok(1);
22
23 #########################
24
25 use Unicode::Collate::CJK::JISX0208;
26
27 my $collator = Unicode::Collate->new(
28     table => undef,
29     normalization => undef,
30     overrideCJK => \&Unicode::Collate::CJK::JISX0208::weightJISX0208
31 );
32
33 sub hex_sort {
34     my @source = map pack('U', hex $_), split ' ', shift;
35     my @sorted = $collator->sort(@source);
36     return join " ", map sprintf("%04X", unpack 'U', $_), @sorted;
37 }
38
39 # 1
40
41 $collator->change(level => 1);
42
43 # first ten kanji
44 ok($collator->lt("\x{4E9C}", "\x{5516}"));
45 ok($collator->lt("\x{5516}", "\x{5A03}"));
46 ok($collator->lt("\x{5A03}", "\x{963F}"));
47 ok($collator->lt("\x{963F}", "\x{54C0}"));
48 ok($collator->lt("\x{54C0}", "\x{611B}"));
49 ok($collator->lt("\x{611B}", "\x{6328}"));
50 ok($collator->lt("\x{6328}", "\x{59F6}"));
51 ok($collator->lt("\x{59F6}", "\x{9022}"));
52 ok($collator->lt("\x{9022}", "\x{8475}"));
53
54 # last five kanji and undef
55 ok($collator->lt("\x{69C7}", "\x{9059}"));
56 ok($collator->lt("\x{9059}", "\x{7464}"));
57 ok($collator->lt("\x{7464}", "\x{51DC}"));
58 ok($collator->lt("\x{51DC}", "\x{7199}"));
59 ok($collator->lt("\x{7199}", "\x{4E02}")); # 4E02: UIdeo undef in JIS X 0208
60 ok($collator->lt("\x{4E02}", "\x{3400}")); # 3400: Ext.A undef in JIS X 0208
61
62 # Ext.B
63 ok($collator->lt("\x{20000}", "\x{20001}"));
64 ok($collator->lt("\x{20001}", "\x{20002}"));
65 ok($collator->lt("\x{20002}", "\x{20003}"));
66 ok($collator->lt("\x{20003}", "\x{20004}"));
67 ok($collator->lt("\x{20004}", "\x{20005}"));
68
69 # 21
70
71 ok(hex_sort('4E00 4E8C 4E09 56DB 4E94 516D 4E03 516B 4E5D 5341'),
72             '4E00 4E5D 4E94 4E09 56DB 4E03 5341 4E8C 516B 516D');
73
74 # 22
75
76 $collator->change(overrideCJK => undef);
77
78 ok($collator->lt("\x{4E00}", "\x{4E01}"));
79 ok($collator->lt("\x{4E01}", "\x{4E02}"));
80 ok($collator->lt("\x{4E02}", "\x{4E03}"));
81 ok($collator->lt("\x{4E03}", "\x{4E04}"));
82 ok($collator->lt("\x{4E04}", "\x{4E05}"));
83
84 ok($collator->lt("\x{9F9B}", "\x{9F9C}"));
85 ok($collator->lt("\x{9F9C}", "\x{9F9D}"));
86 ok($collator->lt("\x{9F9D}", "\x{9F9E}"));
87 ok($collator->lt("\x{9F9E}", "\x{9F9F}"));
88 ok($collator->lt("\x{9F9F}", "\x{9FA0}"));
89
90 # 32
91
92 ok(hex_sort('4E00 4E8C 4E09 56DB 4E94 516D 4E03 516B 4E5D 5341'),
93             '4E00 4E03 4E09 4E5D 4E8C 4E94 516B 516D 5341 56DB');
94
95 # 33