1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
BEGIN {
unless ('A' eq pack('U', 0x41)) {
print "1..0 # Unicode::Collate cannot pack a Unicode code point\n";
exit 0;
}
unless (0x41 == unpack('U', 'A')) {
print "1..0 # Unicode::Collate cannot get a Unicode code point\n";
exit 0;
}
if ($ENV{PERL_CORE}) {
chdir('t') if -d 't';
@INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
}
}
use strict;
use warnings;
BEGIN { $| = 1; print "1..48\n"; }
my $count = 0;
sub ok ($;$) {
my $p = my $r = shift;
if (@_) {
my $x = shift;
$p = !defined $x ? !defined $r : !defined $r ? 0 : $r eq $x;
}
print $p ? "ok" : "not ok", ' ', ++$count, "\n";
}
use Unicode::Collate;
ok(1);
#########################
my $Collator = Unicode::Collate->new(
table => 'keys.txt',
normalization => undef,
);
# [001F] UNIT SEPARATOR
{
ok($Collator->eq("\0", "\x1F"));
ok($Collator->eq("\x1F", "\x{200B}"));
ok($Collator->eq("\0", "\x{200B}"));
ok($Collator->eq("\x{313}", "\x{343}"));
ok($Collator->eq("\x{2000}", "\x{2001}"));
ok($Collator->eq("\x{200B}", "\x{200C}"));
ok($Collator->eq("\x{304C}", "\x{304B}\x{3099}"));
$Collator->change(identical => 1);
ok($Collator->lt("\0", "\x1F"));
ok($Collator->lt("\x1F", "\x{200B}"));
ok($Collator->lt("\0", "\x{200B}"));
ok($Collator->lt("\x{313}", "\x{343}"));
ok($Collator->lt("\x{2000}", "\x{2001}"));
ok($Collator->lt("\x{200B}", "\x{200C}"));
ok($Collator->gt("\x{304C}", "\x{304B}\x{3099}"));
$Collator->change(identical => 0);
ok($Collator->eq("\0", "\x1F"));
ok($Collator->eq("\x1F", "\x{200B}"));
ok($Collator->eq("\0", "\x{200B}"));
ok($Collator->eq("\x{313}", "\x{343}"));
ok($Collator->eq("\x{2000}", "\x{2001}"));
ok($Collator->eq("\x{200B}", "\x{200C}"));
ok($Collator->eq("\x{304C}", "\x{304B}\x{3099}"));
}
#### 22
eval { require Unicode::Normalize };
if (!$@) {
$Collator->change(normalization => "NFD");
$Collator->change(identical => 1);
ok($Collator->lt("\0", "\x{200B}"));
ok($Collator->eq("\x{313}", "\x{343}"));
ok($Collator->lt("\x{2000}", "\x{2001}"));
ok($Collator->lt("\x{200B}", "\x{200C}"));
ok($Collator->eq("\x{304C}", "\x{304B}\x{3099}"));
$Collator->change(identical => 0);
ok($Collator->eq("\0", "\x{200B}"));
ok($Collator->eq("\x{313}", "\x{343}"));
ok($Collator->eq("\x{2000}", "\x{2001}"));
ok($Collator->eq("\x{200B}", "\x{200C}"));
ok($Collator->eq("\x{304C}", "\x{304B}\x{3099}"));
} else {
ok(1) for 1..10;
}
$Collator->change(normalization => undef, identical => 1);
##### 32
ok($Collator->viewSortKey("\0"), '[| | | | 0000 0000]');
ok($Collator->viewSortKey("\x{200B}"), '[| | | | 0000 200B]');
ok($Collator->viewSortKey('a'),
'[0A15 | 0020 | 0002 | FFFF | 0000 0061]');
ok($Collator->viewSortKey("\x{304C}"),
'[1926 | 0020 013D | 000E 0002 | FFFF FFFF | 0000 304C]');
ok($Collator->viewSortKey("\x{4E00}"),
'[FB40 CE00 | 0020 | 0002 | FFFF FFFF | 0000 4E00]');
ok($Collator->viewSortKey("\x{100000}"),
'[FBE0 8000 | 0020 | 0002 | FFFF FFFF | 0010 0000]');
##### 38
eval { require Unicode::Normalize };
if (!$@) {
$Collator->change(normalization => "NFD");
ok($Collator->viewSortKey("\x{304C}"),
'[1926 | 0020 013D | 000E 0002 | FFFF FFFF | 0000 304B 0000 3099]');
} else {
ok(1);
}
$Collator->change(normalization => undef);
##### 39
$Collator->change(level => 3);
ok($Collator->viewSortKey("\x{304C}"),
'[1926 | 0020 013D | 000E 0002 | | 0000 304C]');
$Collator->change(level => 2);
ok($Collator->viewSortKey("\x{304C}"),
'[1926 | 0020 013D | | | 0000 304C]');
$Collator->change(level => 1);
ok($Collator->viewSortKey("\x{304C}"),
'[1926 | | | | 0000 304C]');
##### 42
$Collator->change(UCA_Version => 8);
ok($Collator->viewSortKey("\x{304C}"),
'[1926||||0000 304C]');
$Collator->change(level => 2);
ok($Collator->viewSortKey("\x{304C}"),
'[1926|0020 013D|||0000 304C]');
$Collator->change(level => 3);
ok($Collator->viewSortKey("\x{304C}"),
'[1926|0020 013D|000E 0002||0000 304C]');
$Collator->change(level => 4);
ok($Collator->viewSortKey("\x{304C}"),
'[1926|0020 013D|000E 0002|FFFF FFFF|0000 304C]');
ok($Collator->viewSortKey("\x{4E00}"),
'[4E00|0020|0002|FFFF|0000 4E00]');
ok($Collator->viewSortKey("\x{100000}"),
'[FFA0 8000|0002|0001|FFFF FFFF|0010 0000]');
##### 48
|