1898184e3Ssthen
2b39c5158SmillertBEGIN {
3b39c5158Smillert    if ($ENV{PERL_CORE}) {
4b39c5158Smillert	chdir('t') if -d 't';
5b39c5158Smillert	@INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
6b39c5158Smillert    }
7b39c5158Smillert}
8b39c5158Smillert
9b39c5158Smillertuse strict;
10b39c5158Smillertuse warnings;
11898184e3SsthenBEGIN { $| = 1; print "1..41\n"; }
12898184e3Ssthenmy $count = 0;
13898184e3Ssthensub ok ($;$) {
14898184e3Ssthen    my $p = my $r = shift;
15898184e3Ssthen    if (@_) {
16898184e3Ssthen	my $x = shift;
17898184e3Ssthen	$p = !defined $x ? !defined $r : !defined $r ? 0 : $r eq $x;
18898184e3Ssthen    }
19898184e3Ssthen    print $p ? "ok" : "not ok", ' ', ++$count, "\n";
20898184e3Ssthen}
21898184e3Ssthen
22b39c5158Smillertuse Unicode::Collate;
23b39c5158Smillert
24b39c5158Smillertok(1);
25b39c5158Smillert
26*256a93a4Safresh1sub _pack_U   { Unicode::Collate::pack_U(@_) }
27*256a93a4Safresh1sub _unpack_U { Unicode::Collate::unpack_U(@_) }
28*256a93a4Safresh1
29898184e3Ssthen#########################
30898184e3Ssthen
31b39c5158Smillertmy $trad = Unicode::Collate->new(
32b39c5158Smillert  table => 'keys.txt',
33b39c5158Smillert  normalization => undef,
34b39c5158Smillert  ignoreName => qr/HANGUL|HIRAGANA|KATAKANA|BOPOMOFO/,
35b39c5158Smillert  level => 3,
36b39c5158Smillert  entry => << 'ENTRIES',
37b39c5158Smillert 0063 0068 ; [.0A3F.0020.0002.0063] % "ch" in traditional Spanish
38b39c5158Smillert 0043 0068 ; [.0A3F.0020.0007.0043] # "Ch" in traditional Spanish
39b39c5158Smillert 0043 0048 ; [.0A3F.0020.0008.0043] # "CH" in traditional Spanish
40b39c5158SmillertENTRIES
41b39c5158Smillert);
42b39c5158Smillert# 0063  ; [.0A3D.0020.0002.0063] # LATIN SMALL LETTER C
43b39c5158Smillert# 0064  ; [.0A49.0020.0002.0064] # LATIN SMALL LETTER D
44b39c5158Smillert
45b39c5158Smillert##### 2..3
46b39c5158Smillert
47b39c5158Smillertok(
48b39c5158Smillert  join(':', $trad->sort( qw/ acha aca ada acia acka / ) ),
49b39c5158Smillert  join(':',              qw/ aca acia acka acha ada / ),
50b39c5158Smillert);
51b39c5158Smillert
52b39c5158Smillertok(
53b39c5158Smillert  join(':', $trad->sort( qw/ ACHA ACA ADA ACIA ACKA / ) ),
54b39c5158Smillert  join(':',              qw/ ACA ACIA ACKA ACHA ADA / ),
55b39c5158Smillert);
56b39c5158Smillert
57b39c5158Smillert##### 4..7
58b39c5158Smillert
59b39c5158Smillertok($trad->gt("ocho", "oc\cAho")); # UCA v14
60b39c5158Smillertok($trad->gt("ocho", "oc\0\cA\0\cBho"));  # UCA v14
61b39c5158Smillertok($trad->eq("-", ""));
62b39c5158Smillertok($trad->gt("ocho", "oc-ho"));
63b39c5158Smillert
64b39c5158Smillert##### 8..11
65b39c5158Smillert
66b39c5158Smillert$trad->change(UCA_Version => 9);
67b39c5158Smillert
68b39c5158Smillertok($trad->eq("ocho", "oc\cAho")); # UCA v9
69b39c5158Smillertok($trad->eq("ocho", "oc\0\cA\0\cBho")); # UCA v9
70b39c5158Smillertok($trad->eq("-", ""));
71b39c5158Smillertok($trad->gt("ocho", "oc-ho"));
72b39c5158Smillert
73b39c5158Smillert##### 12..15
74b39c5158Smillert
75b39c5158Smillert$trad->change(UCA_Version => 8);
76b39c5158Smillert
77b39c5158Smillertok($trad->gt("ocho", "oc\cAho"));
78b39c5158Smillertok($trad->gt("ocho", "oc\0\cA\0\cBho"));
79b39c5158Smillertok($trad->eq("-", ""));
80b39c5158Smillertok($trad->gt("ocho", "oc-ho"));
81b39c5158Smillert
82b39c5158Smillert
83b39c5158Smillert##### 16..19
84b39c5158Smillert
85b39c5158Smillert$trad->change(UCA_Version => 9);
86b39c5158Smillert
87b39c5158Smillertmy $hiragana = "\x{3042}\x{3044}";
88b39c5158Smillertmy $katakana = "\x{30A2}\x{30A4}";
89b39c5158Smillert
90b39c5158Smillert# HIRAGANA and KATAKANA are ignorable via ignoreName
91b39c5158Smillertok($trad->eq($hiragana, ""));
92b39c5158Smillertok($trad->eq("", $katakana));
93b39c5158Smillertok($trad->eq($hiragana, $katakana));
94b39c5158Smillertok($trad->eq($katakana, $hiragana));
95b39c5158Smillert
96b39c5158Smillert
97b39c5158Smillert##### 20..31
98b39c5158Smillert
99b39c5158Smillert# According to Conformance Test (UCA_Version == 9 or 11),
100b39c5158Smillert# a L3-ignorable is treated as a completely ignorable.
101b39c5158Smillert
102b39c5158Smillertmy $L3ignorable = Unicode::Collate->new(
103b39c5158Smillert  alternate => 'Non-ignorable',
104b39c5158Smillert  level => 3,
105b39c5158Smillert  table => undef,
106b39c5158Smillert  normalization => undef,
107b39c5158Smillert  UCA_Version => 9,
108b39c5158Smillert  entry => <<'ENTRIES',
109b39c5158Smillert0000  ; [.0000.0000.0000.0000] # [0000] NULL (in 6429)
110b39c5158Smillert0001  ; [.0000.0000.0000.0000] # [0001] START OF HEADING (in 6429)
111b39c5158Smillert0591  ; [.0000.0000.0000.0591] # HEBREW ACCENT ETNAHTA
112b39c5158Smillert1D165 ; [.0000.0000.0000.1D165] # MUSICAL SYMBOL COMBINING STEM
113b39c5158Smillert0021  ; [*024B.0020.0002.0021] # EXCLAMATION MARK
114b39c5158Smillert09BE  ; [.114E.0020.0002.09BE] # BENGALI VOWEL SIGN AA
115b39c5158Smillert09C7  ; [.1157.0020.0002.09C7] # BENGALI VOWEL SIGN E
116b39c5158Smillert09CB  ; [.1159.0020.0002.09CB] # BENGALI VOWEL SIGN O
117b39c5158Smillert09C7 09BE ; [.1159.0020.0002.09CB] # BENGALI VOWEL SIGN O
118b39c5158Smillert1D1B9 ; [*098A.0020.0002.1D1B9] # MUSICAL SYMBOL SEMIBREVIS WHITE
119b39c5158Smillert1D1BA ; [*098B.0020.0002.1D1BA] # MUSICAL SYMBOL SEMIBREVIS BLACK
120b39c5158Smillert1D1BB ; [*098A.0020.0002.1D1B9][.0000.0000.0000.1D165] # M.S. MINIMA
121b39c5158Smillert1D1BC ; [*098B.0020.0002.1D1BA][.0000.0000.0000.1D165] # M.S. MINIMA BLACK
122b39c5158SmillertENTRIES
123b39c5158Smillert);
124b39c5158Smillert
125b39c5158Smillertok($L3ignorable->lt("\cA", "!"));
126b39c5158Smillertok($L3ignorable->lt("\x{591}", "!"));
127b39c5158Smillertok($L3ignorable->eq("\cA", "\x{591}"));
128898184e3Ssthenok($L3ignorable->eq("\x{9C7}\x{9BE}A", "\x{9C7}\cA\x{9BE}A"));
129898184e3Ssthenok($L3ignorable->eq("\x{9C7}\x{9BE}A", "\x{9C7}\x{591}\x{9BE}A"));
130898184e3Ssthenok($L3ignorable->eq("\x{9C7}\x{9BE}A", "\x{9C7}\x{1D165}\x{9BE}A"));
131898184e3Ssthenok($L3ignorable->eq("\x{9C7}\x{9BE}A", "\x{9CB}A"));
132b39c5158Smillertok($L3ignorable->lt("\x{1D1BB}", "\x{1D1BC}"));
133b39c5158Smillertok($L3ignorable->eq("\x{1D1BB}", "\x{1D1B9}"));
134b39c5158Smillertok($L3ignorable->eq("\x{1D1BC}", "\x{1D1BA}"));
135b39c5158Smillertok($L3ignorable->eq("\x{1D1BB}", "\x{1D1B9}\x{1D165}"));
136b39c5158Smillertok($L3ignorable->eq("\x{1D1BC}", "\x{1D1BA}\x{1D165}"));
137b39c5158Smillert
138b39c5158Smillert##### 32..41
139b39c5158Smillert
140b39c5158Smillertmy $c = Unicode::Collate->new(
141b39c5158Smillert  table => 'keys.txt',
142b39c5158Smillert  normalization => undef,
143b39c5158Smillert  level => 1,
144b39c5158Smillert  UCA_Version => 14,
145b39c5158Smillert  entry => << 'ENTRIES',
146b39c5158Smillert034F  ; [.0000.0000.0000.034F] # COMBINING GRAPHEME JOINER
147b39c5158Smillert0063 0068 ; [.0A3F.0020.0002.0063] % "ch" in traditional Spanish
148b39c5158Smillert0043 0068 ; [.0A3F.0020.0007.0043] # "Ch" in traditional Spanish
149b39c5158Smillert0043 0048 ; [.0A3F.0020.0008.0043] # "CH" in traditional Spanish
150b39c5158SmillertENTRIES
151b39c5158Smillert);
152b39c5158Smillert# 0063  ; [.0A3D.0020.0002.0063] # LATIN SMALL LETTER C
153b39c5158Smillert# 0064  ; [.0A49.0020.0002.0064] # LATIN SMALL LETTER D
154b39c5158Smillert
155b39c5158Smillertok($c->gt("ocho", "oc\x00\x00ho"));
156b39c5158Smillertok($c->gt("ocho", "oc\cAho"));
157898184e3Ssthenok($c->gt("ocho", "oc\x{34F}ho"));
158898184e3Ssthenok($c->gt("ocio", "oc\x{34F}ho"));
159898184e3Ssthenok($c->lt("ocgo", "oc\x{34F}ho"));
160898184e3Ssthenok($c->lt("oceo", "oc\x{34F}ho"));
161b39c5158Smillert
162b39c5158Smillertok($c->viewSortKey("ocho"),         "[0B4B 0A3F 0B4B | | |]");
163b39c5158Smillertok($c->viewSortKey("oc\x00\x00ho"), "[0B4B 0A3D 0AB9 0B4B | | |]");
164b39c5158Smillertok($c->viewSortKey("oc\cAho"),      "[0B4B 0A3D 0AB9 0B4B | | |]");
165898184e3Ssthenok($c->viewSortKey("oc\x{34F}ho"),  "[0B4B 0A3D 0AB9 0B4B | | |]");
166b39c5158Smillert
167b39c5158Smillert
168