xref: /openbsd-src/gnu/usr.bin/perl/cpan/Unicode-Collate/t/index.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
1b39c5158Smillert
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;
1191f110e0Safresh1BEGIN { $| = 1; print "1..91\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
24898184e3Ssthenok(1);
25b39c5158Smillert
26*256a93a4Safresh1sub _pack_U   { Unicode::Collate::pack_U(@_) }
27*256a93a4Safresh1sub _unpack_U { Unicode::Collate::unpack_U(@_) }
28*256a93a4Safresh1
29*256a93a4Safresh1#########################
30*256a93a4Safresh1
31898184e3Ssthenour $IsEBCDIC = ord("A") != 0x41;
32b39c5158Smillert
33b39c5158Smillertmy $Collator = Unicode::Collate->new(
34b39c5158Smillert  table => 'keys.txt',
35b39c5158Smillert  normalization => undef,
36b39c5158Smillert);
37b39c5158Smillert
3891f110e0Safresh1##### 1
39b39c5158Smillert
40b39c5158Smillertmy %old_level = $Collator->change(level => 2);
41b39c5158Smillert
42b39c5158Smillertmy $str;
43b39c5158Smillert
44b39c5158Smillertmy $orig = "This is a Perl book.";
45b39c5158Smillertmy $sub = "PERL";
46b39c5158Smillertmy $rep = "camel";
47b39c5158Smillertmy $ret = "This is a camel book.";
48b39c5158Smillert
49b39c5158Smillert$str = $orig;
50b39c5158Smillertif (my($pos,$len) = $Collator->index($str, $sub)) {
51b39c5158Smillert  substr($str, $pos, $len, $rep);
52b39c5158Smillert}
53b39c5158Smillert
54b39c5158Smillertok($str, $ret);
55b39c5158Smillert
56b39c5158Smillert$Collator->change(%old_level);
57b39c5158Smillert
58b39c5158Smillert$str = $orig;
59b39c5158Smillertif (my($pos,$len) = $Collator->index($str, $sub)) {
60b39c5158Smillert  substr($str, $pos, $len, $rep);
61b39c5158Smillert}
62b39c5158Smillert
63b39c5158Smillertok($str, $orig);
64b39c5158Smillert
6591f110e0Safresh1##### 3
66b39c5158Smillert
67b39c5158Smillertmy $match;
68b39c5158Smillert
69b39c5158Smillert$Collator->change(level => 1);
70b39c5158Smillert
71b39c5158Smillert$str = "Pe\x{300}rl";
72b39c5158Smillert$sub = "pe";
73b39c5158Smillert$ret = "Pe\x{300}";
74b39c5158Smillert$match = undef;
75b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
76b39c5158Smillert    $match = substr($str, $pos, $len);
77b39c5158Smillert}
78b39c5158Smillertok($match, $ret);
79b39c5158Smillert
80b39c5158Smillert$str = "P\x{300}e\x{300}\x{301}\x{303}rl";
81b39c5158Smillert$sub = "pE";
82b39c5158Smillert$ret = "P\x{300}e\x{300}\x{301}\x{303}";
83b39c5158Smillert$match = undef;
84b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
85b39c5158Smillert    $match = substr($str, $pos, $len);
86b39c5158Smillert}
87b39c5158Smillertok($match, $ret);
88b39c5158Smillert
89b39c5158Smillert$Collator->change(level => 2);
90b39c5158Smillert
91b39c5158Smillert$str = "Pe\x{300}rl";
92b39c5158Smillert$sub = "pe";
93b39c5158Smillert$ret = undef;
94b39c5158Smillert$match = undef;
95b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
96b39c5158Smillert    $match = substr($str, $pos, $len);
97b39c5158Smillert}
98b39c5158Smillertok($match, $ret);
99b39c5158Smillert
100b39c5158Smillert$str = "P\x{300}e\x{300}\x{301}\x{303}rl";
101b39c5158Smillert$sub = "pE";
102b39c5158Smillert$ret = undef;
103b39c5158Smillert$match = undef;
104b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
105b39c5158Smillert    $match = substr($str, $pos, $len);
106b39c5158Smillert}
107b39c5158Smillertok($match, $ret);
108b39c5158Smillert
109b39c5158Smillert$str = "Pe\x{300}rl";
110b39c5158Smillert$sub = "pe\x{300}";
111b39c5158Smillert$ret = "Pe\x{300}";
112b39c5158Smillert$match = undef;
113b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
114b39c5158Smillert    $match = substr($str, $pos, $len);
115b39c5158Smillert}
116b39c5158Smillertok($match, $ret);
117b39c5158Smillert
118b39c5158Smillert$str = "P\x{300}e\x{300}\x{301}\x{303}rl";
119b39c5158Smillert$sub = "p\x{300}E\x{300}\x{301}\x{303}";
120b39c5158Smillert$ret = "P\x{300}e\x{300}\x{301}\x{303}";
121b39c5158Smillert$match = undef;
122b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
123b39c5158Smillert    $match = substr($str, $pos, $len);
124b39c5158Smillert}
125b39c5158Smillertok($match, $ret);
126b39c5158Smillert
12791f110e0Safresh1##### 9
128b39c5158Smillert
129b39c5158Smillert$Collator->change(level => 1);
130b39c5158Smillert
131b39c5158Smillert$str = $IsEBCDIC
132b39c5158Smillert    ? "Ich mu\x{0059} studieren Perl."
133b39c5158Smillert    : "Ich mu\x{00DF} studieren Perl.";
134b39c5158Smillert$sub = $IsEBCDIC
135b39c5158Smillert    ? "m\x{00DC}ss"
136b39c5158Smillert    : "m\x{00FC}ss";
137b39c5158Smillert$ret = $IsEBCDIC
138b39c5158Smillert    ? "mu\x{0059}"
139b39c5158Smillert    : "mu\x{00DF}";
140b39c5158Smillert$match = undef;
141b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
142b39c5158Smillert    $match = substr($str, $pos, $len);
143b39c5158Smillert}
144b39c5158Smillertok($match, $ret);
145b39c5158Smillert
146b39c5158Smillert$Collator->change(%old_level);
147b39c5158Smillert
148b39c5158Smillert$match = undef;
149b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
150b39c5158Smillert    $match = substr($str, $pos, $len);
151b39c5158Smillert}
152b39c5158Smillertok($match, undef);
153b39c5158Smillert
154b39c5158Smillert$match = undef;
155b39c5158Smillertif (my($pos,$len) = $Collator->index("", "")) {
156b39c5158Smillert    $match = substr("", $pos, $len);
157b39c5158Smillert}
158b39c5158Smillertok($match, "");
159b39c5158Smillert
160b39c5158Smillert$match = undef;
161b39c5158Smillertif (my($pos,$len) = $Collator->index("", "abc")) {
162b39c5158Smillert    $match = substr("", $pos, $len);
163b39c5158Smillert}
164b39c5158Smillertok($match, undef);
165b39c5158Smillert
16691f110e0Safresh1##### 13
167b39c5158Smillert
168b39c5158Smillert$Collator->change(level => 1);
169b39c5158Smillert
170b39c5158Smillert$str = "\0\cA\0\cAe\0\x{300}\cA\x{301}\cB\x{302}\0 \0\cA";
171b39c5158Smillert$sub = "e";
172b39c5158Smillert$ret = "e\0\x{300}\cA\x{301}\cB\x{302}\0";
173b39c5158Smillert$match = undef;
174b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
175b39c5158Smillert    $match = substr($str, $pos, $len);
176b39c5158Smillert}
177b39c5158Smillertok($match, $ret);
178b39c5158Smillert
179b39c5158Smillert$Collator->change(level => 1);
180b39c5158Smillert
181b39c5158Smillert$str = "\0\cA\0\cAe\0\cA\x{300}\0\cAe";
182b39c5158Smillert$sub = "e";
183b39c5158Smillert$ret = "e\0\cA\x{300}\0\cA";
184b39c5158Smillert$match = undef;
185b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
186b39c5158Smillert    $match = substr($str, $pos, $len);
187b39c5158Smillert}
188b39c5158Smillertok($match, $ret);
189b39c5158Smillert
190b39c5158Smillert
191b39c5158Smillert$Collator->change(%old_level);
192b39c5158Smillert
193b39c5158Smillert$str = "e\x{300}";
194b39c5158Smillert$sub = "e";
195b39c5158Smillert$ret = undef;
196b39c5158Smillert$match = undef;
197b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub)) {
198b39c5158Smillert    $match = substr($str, $pos, $len);
199b39c5158Smillert}
200b39c5158Smillertok($match, $ret);
201b39c5158Smillert
20291f110e0Safresh1##### 16
203b39c5158Smillert
204b39c5158Smillert$Collator->change(level => 1);
205b39c5158Smillert
206b39c5158Smillert$str = "The Perl is a language, and the perl is an interpreter.";
207b39c5158Smillert$sub = "PERL";
208b39c5158Smillert
209b39c5158Smillert$match = undef;
210b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub, -40)) {
211b39c5158Smillert    $match = substr($str, $pos, $len);
212b39c5158Smillert}
213b39c5158Smillertok($match, "Perl");
214b39c5158Smillert
215b39c5158Smillert$match = undef;
216b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub, 4)) {
217b39c5158Smillert    $match = substr($str, $pos, $len);
218b39c5158Smillert}
219b39c5158Smillertok($match, "Perl");
220b39c5158Smillert
221b39c5158Smillert$match = undef;
222b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub, 5)) {
223b39c5158Smillert    $match = substr($str, $pos, $len);
224b39c5158Smillert}
225b39c5158Smillertok($match, "perl");
226b39c5158Smillert
227b39c5158Smillert$match = undef;
228b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub, 32)) {
229b39c5158Smillert    $match = substr($str, $pos, $len);
230b39c5158Smillert}
231b39c5158Smillertok($match, "perl");
232b39c5158Smillert
233b39c5158Smillert$match = undef;
234b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub, 33)) {
235b39c5158Smillert    $match = substr($str, $pos, $len);
236b39c5158Smillert}
237b39c5158Smillertok($match, undef);
238b39c5158Smillert
239b39c5158Smillert$match = undef;
240b39c5158Smillertif (my($pos, $len) = $Collator->index($str, $sub, 100)) {
241b39c5158Smillert    $match = substr($str, $pos, $len);
242b39c5158Smillert}
243b39c5158Smillertok($match, undef);
244b39c5158Smillert
245b39c5158Smillert$Collator->change(%old_level);
246b39c5158Smillert
24791f110e0Safresh1##### 22
248b39c5158Smillert
249b39c5158Smillertmy @ret;
250b39c5158Smillert
251b39c5158Smillert$Collator->change(level => 1);
252b39c5158Smillert
253b39c5158Smillert$ret = $Collator->match("P\cBe\x{300}\cBrl and PERL", "pe");
254b39c5158Smillertok($ret);
255b39c5158Smillertok($$ret eq "P\cBe\x{300}\cB");
256b39c5158Smillert
257b39c5158Smillert@ret = $Collator->match("P\cBe\x{300}\cBrl and PERL", "pe");
258b39c5158Smillertok($ret[0], "P\cBe\x{300}\cB");
259b39c5158Smillert
260b39c5158Smillert$str = $IsEBCDIC ? "mu\x{0059}" : "mu\x{00DF}";
261b39c5158Smillert$sub = $IsEBCDIC ? "m\x{00DC}ss" : "m\x{00FC}ss";
262b39c5158Smillert
263b39c5158Smillert($ret) = $Collator->match($str, $sub);
264b39c5158Smillertok($ret, $str);
265b39c5158Smillert
266b39c5158Smillert$str = $IsEBCDIC ? "mu\x{0059}" : "mu\x{00DF}";
267b39c5158Smillert$sub = $IsEBCDIC ? "m\x{00DC}s" : "m\x{00FC}s";
268b39c5158Smillert
269b39c5158Smillert($ret) = $Collator->match($str, $sub);
270b39c5158Smillertok($ret, undef);
271b39c5158Smillert
272b39c5158Smillert$ret = join ':', $Collator->gmatch("P\cBe\x{300}\cBrl, perl, and PERL", "pe");
273b39c5158Smillertok($ret eq "P\cBe\x{300}\cB:pe:PE");
274b39c5158Smillert
275b39c5158Smillert$ret = $Collator->gmatch("P\cBe\x{300}\cBrl, perl, and PERL", "pe");
276b39c5158Smillertok($ret == 3);
277b39c5158Smillert
278b39c5158Smillert$str = "ABCDEF";
279b39c5158Smillert$sub = "cde";
280b39c5158Smillert$ret = $Collator->match($str, $sub);
281b39c5158Smillert$str = "01234567";
282b39c5158Smillertok($ret && $$ret, "CDE");
283b39c5158Smillert
284b39c5158Smillert$str = "ABCDEF";
285b39c5158Smillert$sub = "cde";
286b39c5158Smillert($ret) = $Collator->match($str, $sub);
287b39c5158Smillert$str = "01234567";
288b39c5158Smillertok($ret, "CDE");
289b39c5158Smillert
290b39c5158Smillert
291b39c5158Smillert$Collator->change(level => 3);
292b39c5158Smillert
293b39c5158Smillert$ret = $Collator->match("P\cBe\x{300}\cBrl and PERL", "pe");
294b39c5158Smillertok($ret, undef);
295b39c5158Smillert
296b39c5158Smillert@ret = $Collator->match("P\cBe\x{300}\cBrl and PERL", "pe");
297b39c5158Smillertok(@ret == 0);
298b39c5158Smillert
299b39c5158Smillert$ret = join ':', $Collator->gmatch("P\cBe\x{300}\cBrl and PERL", "pe");
300b39c5158Smillertok($ret eq "");
301b39c5158Smillert
302b39c5158Smillert$ret = $Collator->gmatch("P\cBe\x{300}\cBrl and PERL", "pe");
303b39c5158Smillertok($ret == 0);
304b39c5158Smillert
305b39c5158Smillert$ret = join ':', $Collator->gmatch("P\cBe\x{300}\cBrl, perl, and PERL", "pe");
306b39c5158Smillertok($ret eq "pe");
307b39c5158Smillert
308b39c5158Smillert$ret = $Collator->gmatch("P\cBe\x{300}\cBrl, perl, and PERL", "pe");
309b39c5158Smillertok($ret == 1);
310b39c5158Smillert
311b39c5158Smillert$str = $IsEBCDIC ? "mu\x{0059}" : "mu\x{00DF}";
312b39c5158Smillert$sub = $IsEBCDIC ? "m\x{00DC}ss" : "m\x{00FC}ss";
313b39c5158Smillert
314b39c5158Smillert($ret) = $Collator->match($str, $sub);
315b39c5158Smillertok($ret, undef);
316b39c5158Smillert
317b39c5158Smillert$Collator->change(%old_level);
318b39c5158Smillert
31991f110e0Safresh1##### 38
320b39c5158Smillert
321b39c5158Smillert$Collator->change(level => 1);
322b39c5158Smillert
323b39c5158Smillertsub strreverse { scalar reverse shift }
324b39c5158Smillert
325b39c5158Smillert$str = "P\cBe\x{300}\cBrl and PERL.";
326b39c5158Smillert$ret = $Collator->subst($str, "perl", 'Camel');
327b39c5158Smillertok($ret, 1);
328b39c5158Smillertok($str, "Camel and PERL.");
329b39c5158Smillert
330b39c5158Smillert$str = "P\cBe\x{300}\cBrl and PERL.";
331b39c5158Smillert$ret = $Collator->subst($str, "perl", \&strreverse);
332b39c5158Smillertok($ret, 1);
333b39c5158Smillertok($str, "lr\cB\x{300}e\cBP and PERL.");
334b39c5158Smillert
335b39c5158Smillert$str = "P\cBe\x{300}\cBrl and PERL.";
336b39c5158Smillert$ret = $Collator->gsubst($str, "perl", 'Camel');
337b39c5158Smillertok($ret, 2);
338b39c5158Smillertok($str, "Camel and Camel.");
339b39c5158Smillert
340b39c5158Smillert$str = "P\cBe\x{300}\cBrl and PERL.";
341b39c5158Smillert$ret = $Collator->gsubst($str, "perl", \&strreverse);
342b39c5158Smillertok($ret, 2);
343b39c5158Smillertok($str, "lr\cB\x{300}e\cBP and LREP.");
344b39c5158Smillert
345b39c5158Smillert$str = "Camel donkey zebra came\x{301}l CAMEL horse cAm\0E\0L...";
346b39c5158Smillert$Collator->gsubst($str, "camel", sub { "<b>$_[0]</b>" });
347b39c5158Smillertok($str, "<b>Camel</b> donkey zebra <b>came\x{301}l</b> "
348b39c5158Smillert	. "<b>CAMEL</b> horse <b>cAm\0E\0L</b>...");
349b39c5158Smillert
35091f110e0Safresh1##### 47
35191f110e0Safresh1
352898184e3Ssthen# http://www.xray.mpe.mpg.de/mailing-lists/perl-unicode/2010-09/msg00014.html
353898184e3Ssthen# when the substring includes an ignorable element like a space...
354898184e3Ssthen
355898184e3Ssthen$str = "Camel donkey zebra came\x{301}l CAMEL horse cAm\0E\0L...";
356898184e3Ssthen$Collator->gsubst($str, "camel horse", sub { "<b>$_[0]</b>" });
357898184e3Ssthenok($str, "Camel donkey zebra came\x{301}l <b>CAMEL horse</b> cAm\0E\0L...");
358898184e3Ssthen
359898184e3Ssthen$str = "Camel donkey zebra camex{301}l CAMEL horse cAmEL-horse...";
360898184e3Ssthen$Collator->gsubst($str, "camel horse", sub { "=$_[0]=" });
361898184e3Ssthenok($str, "Camel donkey zebra camex{301}l =CAMEL horse= =cAmEL-horse=...");
362898184e3Ssthen
363898184e3Ssthen$str = "Camel donkey zebra camex{301}l CAMEL horse cAmEL-horse...";
364898184e3Ssthen$Collator->gsubst($str, "camel-horse", sub { "=$_[0]=" });
365898184e3Ssthenok($str, "Camel donkey zebra camex{301}l =CAMEL horse= =cAmEL-horse=...");
366898184e3Ssthen
367898184e3Ssthen$str = "Camel donkey zebra camex{301}l CAMEL horse cAmEL-horse...";
368898184e3Ssthen$Collator->gsubst($str, "camelhorse", sub { "=$_[0]=" });
369898184e3Ssthenok($str, "Camel donkey zebra camex{301}l =CAMEL horse= =cAmEL-horse=...");
370898184e3Ssthen
371898184e3Ssthen$str = "Camel donkey zebra camex{301}l CAMEL horse cAmEL-horse...";
372898184e3Ssthen$Collator->gsubst($str, "  ca  mel  hor  se  ", sub { "=$_[0]=" });
373898184e3Ssthenok($str, "Camel donkey zebra camex{301}l =CAMEL horse= =cAmEL-horse=...");
374898184e3Ssthen
375898184e3Ssthen$str = "Camel donkey zebra camex{301}l CAMEL horse cAmEL-horse...";
376898184e3Ssthen$Collator->gsubst($str, "ca\x{300}melho\x{302}rse", sub { "=$_[0]=" });
377898184e3Ssthenok($str, "Camel donkey zebra camex{301}l =CAMEL horse= =cAmEL-horse=...");
378898184e3Ssthen
37991f110e0Safresh1##### 53
38091f110e0Safresh1
381b39c5158Smillert$Collator->change(level => 3);
382b39c5158Smillert
383b39c5158Smillert$str = "P\cBe\x{300}\cBrl and PERL.";
384b39c5158Smillert$ret = $Collator->subst($str, "perl", "Camel");
385b39c5158Smillertok(! $ret);
386b39c5158Smillertok($str, "P\cBe\x{300}\cBrl and PERL.");
387b39c5158Smillert
388b39c5158Smillert$str = "P\cBe\x{300}\cBrl and PERL.";
389b39c5158Smillert$ret = $Collator->subst($str, "perl", \&strreverse);
390b39c5158Smillertok(! $ret);
391b39c5158Smillertok($str, "P\cBe\x{300}\cBrl and PERL.");
392b39c5158Smillert
393b39c5158Smillert$str = "P\cBe\x{300}\cBrl and PERL.";
394b39c5158Smillert$ret = $Collator->gsubst($str, "perl", "Camel");
395b39c5158Smillertok($ret, 0);
396b39c5158Smillertok($str, "P\cBe\x{300}\cBrl and PERL.");
397b39c5158Smillert
398b39c5158Smillert$str = "P\cBe\x{300}\cBrl and PERL.";
399b39c5158Smillert$ret = $Collator->gsubst($str, "perl", \&strreverse);
400b39c5158Smillertok($ret, 0);
401b39c5158Smillertok($str, "P\cBe\x{300}\cBrl and PERL.");
402b39c5158Smillert
403b39c5158Smillert$Collator->change(%old_level);
404b39c5158Smillert
40591f110e0Safresh1##### 61
406b39c5158Smillert
407b39c5158Smillert$str = "Perl and Camel";
408b39c5158Smillert$ret = $Collator->gsubst($str, "\cA\cA\0", "AB");
409b39c5158Smillertok($ret, 15);
410b39c5158Smillertok($str, "ABPABeABrABlAB ABaABnABdAB ABCABaABmABeABlAB");
411b39c5158Smillert
412b39c5158Smillert$str = '';
413b39c5158Smillert$ret = $Collator->subst($str, "", "ABC");
414b39c5158Smillertok($ret, 1);
415b39c5158Smillertok($str, "ABC");
416b39c5158Smillert
417b39c5158Smillert$str = '';
418b39c5158Smillert$ret = $Collator->gsubst($str, "", "ABC");
419b39c5158Smillertok($ret, 1);
420b39c5158Smillertok($str, "ABC");
421b39c5158Smillert
422b39c5158Smillert$str = 'PPPPP';
423b39c5158Smillert$ret = $Collator->gsubst($str, 'PP', "ABC");
424b39c5158Smillertok($ret, 2);
425b39c5158Smillertok($str, "ABCABCP");
426b39c5158Smillert
42791f110e0Safresh1##### 69
428b39c5158Smillert
429b39c5158Smillert# Shifted; ignorable after variable
430b39c5158Smillert
431b39c5158Smillert($ret) = $Collator->match("A?\x{300}!\x{301}\x{344}B\x{315}", "?!");
432b39c5158Smillertok($ret, "?\x{300}!\x{301}\x{344}");
433b39c5158Smillert
434b39c5158Smillert$Collator->change(alternate => 'Non-ignorable');
435b39c5158Smillert
436b39c5158Smillert($ret) = $Collator->match("A?\x{300}!\x{301}B\x{315}", "?!");
437b39c5158Smillertok($ret, undef);
438b39c5158Smillert
43991f110e0Safresh1##### 71
44091f110e0Safresh1
44191f110e0Safresh1# Now preprocess is defined.
44291f110e0Safresh1
44391f110e0Safresh1$Collator->change(preprocess => sub {''});
44491f110e0Safresh1
44591f110e0Safresh1eval { $Collator->index("", "") };
44691f110e0Safresh1ok($@ && $@ =~ /Don't use Preprocess with index\(\)/);
44791f110e0Safresh1
44891f110e0Safresh1eval { $Collator->index("a", "a") };
44991f110e0Safresh1ok($@ && $@ =~ /Don't use Preprocess with index\(\)/);
45091f110e0Safresh1
45191f110e0Safresh1eval { $Collator->match("", "") };
45291f110e0Safresh1ok($@ && $@ =~ /Don't use Preprocess with.*match\(\)/);
45391f110e0Safresh1
45491f110e0Safresh1eval { $Collator->match("a", "a") };
45591f110e0Safresh1ok($@ && $@ =~ /Don't use Preprocess with.*match\(\)/);
45691f110e0Safresh1
45791f110e0Safresh1$Collator->change(preprocess => sub { uc shift });
45891f110e0Safresh1
45991f110e0Safresh1eval { $Collator->index("", "") };
46091f110e0Safresh1ok($@ && $@ =~ /Don't use Preprocess with index\(\)/);
46191f110e0Safresh1
46291f110e0Safresh1eval { $Collator->index("a", "a") };
46391f110e0Safresh1ok($@ && $@ =~ /Don't use Preprocess with index\(\)/);
46491f110e0Safresh1
46591f110e0Safresh1eval { $Collator->match("", "") };
46691f110e0Safresh1ok($@ && $@ =~ /Don't use Preprocess with.*match\(\)/);
46791f110e0Safresh1
46891f110e0Safresh1eval { $Collator->match("a", "a") };
46991f110e0Safresh1ok($@ && $@ =~ /Don't use Preprocess with.*match\(\)/);
47091f110e0Safresh1
47191f110e0Safresh1##### 79
47291f110e0Safresh1
47391f110e0Safresh1eval { require Unicode::Normalize };
47491f110e0Safresh1my $has_norm = !$@;
47591f110e0Safresh1
47691f110e0Safresh1if ($has_norm) {
47791f110e0Safresh1    # Now preprocess and normalization are defined.
47891f110e0Safresh1
47991f110e0Safresh1    $Collator->change(normalization => 'NFD');
48091f110e0Safresh1
48191f110e0Safresh1    eval { $Collator->index("", "") };
48291f110e0Safresh1    ok($@ && $@ =~ /Don't use Preprocess with index\(\)/);
48391f110e0Safresh1
48491f110e0Safresh1    eval { $Collator->index("a", "a") };
48591f110e0Safresh1    ok($@ && $@ =~ /Don't use Preprocess with index\(\)/);
48691f110e0Safresh1
48791f110e0Safresh1    eval { $Collator->match("", "") };
48891f110e0Safresh1    ok($@ && $@ =~ /Don't use Preprocess with.*match\(\)/);
48991f110e0Safresh1
49091f110e0Safresh1    eval { $Collator->match("a", "a") };
49191f110e0Safresh1    ok($@ && $@ =~ /Don't use Preprocess with.*match\(\)/);
49291f110e0Safresh1} else {
49391f110e0Safresh1    ok(1) for 1..4;
49491f110e0Safresh1}
49591f110e0Safresh1
49691f110e0Safresh1$Collator->change(preprocess => undef);
49791f110e0Safresh1
49891f110e0Safresh1if ($has_norm) {
49991f110e0Safresh1    # Now only normalization is defined.
50091f110e0Safresh1
50191f110e0Safresh1    eval { $Collator->index("", "") };
50291f110e0Safresh1    ok($@ && $@ =~ /Don't use Normalization with index\(\)/);
50391f110e0Safresh1
50491f110e0Safresh1    eval { $Collator->index("a", "a") };
50591f110e0Safresh1    ok($@ && $@ =~ /Don't use Normalization with index\(\)/);
50691f110e0Safresh1
50791f110e0Safresh1    eval { $Collator->match("", "") };
50891f110e0Safresh1    ok($@ && $@ =~ /Don't use Normalization with.*match\(\)/);
50991f110e0Safresh1
51091f110e0Safresh1    eval { $Collator->match("a", "a") };
51191f110e0Safresh1    ok($@ && $@ =~ /Don't use Normalization with.*match\(\)/);
51291f110e0Safresh1
51391f110e0Safresh1    $Collator->change(normalization => undef);
51491f110e0Safresh1} else {
51591f110e0Safresh1    ok(1) for 1..4;
51691f110e0Safresh1}
51791f110e0Safresh1
51891f110e0Safresh1##### 87
51991f110e0Safresh1
52091f110e0Safresh1# Now preprocess and normalization are undef.
52191f110e0Safresh1
52291f110e0Safresh1eval { $Collator->index("", "") };
52391f110e0Safresh1ok(!$@);
52491f110e0Safresh1
52591f110e0Safresh1eval { $Collator->index("a", "a") };
52691f110e0Safresh1ok(!$@);
52791f110e0Safresh1
52891f110e0Safresh1eval { $Collator->match("", "") };
52991f110e0Safresh1ok(!$@);
53091f110e0Safresh1
53191f110e0Safresh1eval { $Collator->match("a", "a") };
53291f110e0Safresh1ok(!$@);
53391f110e0Safresh1
53491f110e0Safresh1##### 91
535