4 print "1..0 # Unicode::Collate not ported to EBCDIC\n";
10 if ($ENV{PERL_CORE}) {
12 @INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
17 BEGIN { plan tests => 65 };
20 our $IsEBCDIC = ord("A") != 0x41;
22 #########################
24 ok(1); # If we made it this far, we're ok.
26 my $Collator = Unicode::Collate->new(
28 normalization => undef,
33 my %old_level = $Collator->change(level => 2);
37 my $orig = "This is a Perl book.";
40 my $ret = "This is a camel book.";
43 if (my($pos,$len) = $Collator->index($str, $sub)) {
44 substr($str, $pos, $len, $rep);
49 $Collator->change(%old_level);
52 if (my($pos,$len) = $Collator->index($str, $sub)) {
53 substr($str, $pos, $len, $rep);
62 $Collator->change(level => 1);
68 if (my($pos, $len) = $Collator->index($str, $sub)) {
69 $match = substr($str, $pos, $len);
73 $str = "P\x{300}e\x{300}\x{301}\x{303}rl";
75 $ret = "P\x{300}e\x{300}\x{301}\x{303}";
77 if (my($pos, $len) = $Collator->index($str, $sub)) {
78 $match = substr($str, $pos, $len);
82 $Collator->change(level => 2);
88 if (my($pos, $len) = $Collator->index($str, $sub)) {
89 $match = substr($str, $pos, $len);
93 $str = "P\x{300}e\x{300}\x{301}\x{303}rl";
97 if (my($pos, $len) = $Collator->index($str, $sub)) {
98 $match = substr($str, $pos, $len);
102 $str = "Pe\x{300}rl";
106 if (my($pos, $len) = $Collator->index($str, $sub)) {
107 $match = substr($str, $pos, $len);
111 $str = "P\x{300}e\x{300}\x{301}\x{303}rl";
112 $sub = "p\x{300}E\x{300}\x{301}\x{303}";
113 $ret = "P\x{300}e\x{300}\x{301}\x{303}";
115 if (my($pos, $len) = $Collator->index($str, $sub)) {
116 $match = substr($str, $pos, $len);
122 $Collator->change(level => 1);
125 ? "Ich mu\x{0059} studieren Perl."
126 : "Ich mu\x{00DF} studieren Perl.";
134 if (my($pos, $len) = $Collator->index($str, $sub)) {
135 $match = substr($str, $pos, $len);
139 $Collator->change(%old_level);
142 if (my($pos, $len) = $Collator->index($str, $sub)) {
143 $match = substr($str, $pos, $len);
148 if (my($pos,$len) = $Collator->index("", "")) {
149 $match = substr("", $pos, $len);
154 if (my($pos,$len) = $Collator->index("", "abc")) {
155 $match = substr("", $pos, $len);
161 $Collator->change(level => 1);
163 $str = "\0\cA\0\cAe\0\x{300}\cA\x{301}\cB\x{302}\0 \0\cA";
165 $ret = "e\0\x{300}\cA\x{301}\cB\x{302}\0";
167 if (my($pos, $len) = $Collator->index($str, $sub)) {
168 $match = substr($str, $pos, $len);
172 $Collator->change(level => 1);
174 $str = "\0\cA\0\cAe\0\cA\x{300}\0\cAe";
176 $ret = "e\0\cA\x{300}\0\cA";
178 if (my($pos, $len) = $Collator->index($str, $sub)) {
179 $match = substr($str, $pos, $len);
184 $Collator->change(%old_level);
190 if (my($pos, $len) = $Collator->index($str, $sub)) {
191 $match = substr($str, $pos, $len);
197 $Collator->change(level => 1);
199 $str = "The Perl is a language, and the perl is an interpreter.";
203 if (my($pos, $len) = $Collator->index($str, $sub, -40)) {
204 $match = substr($str, $pos, $len);
209 if (my($pos, $len) = $Collator->index($str, $sub, 4)) {
210 $match = substr($str, $pos, $len);
215 if (my($pos, $len) = $Collator->index($str, $sub, 5)) {
216 $match = substr($str, $pos, $len);
221 if (my($pos, $len) = $Collator->index($str, $sub, 32)) {
222 $match = substr($str, $pos, $len);
227 if (my($pos, $len) = $Collator->index($str, $sub, 33)) {
228 $match = substr($str, $pos, $len);
233 if (my($pos, $len) = $Collator->index($str, $sub, 100)) {
234 $match = substr($str, $pos, $len);
238 $Collator->change(%old_level);
244 $Collator->change(level => 1);
246 $ret = $Collator->match("P\cBe\x{300}\cBrl and PERL", "pe");
248 ok($$ret eq "P\cBe\x{300}\cB");
250 @ret = $Collator->match("P\cBe\x{300}\cBrl and PERL", "pe");
251 ok($ret[0], "P\cBe\x{300}\cB");
253 $str = $IsEBCDIC ? "mu\x{0059}" : "mu\x{00DF}";
254 $sub = $IsEBCDIC ? "m\x{00DC}ss" : "m\x{00FC}ss";
256 ($ret) = $Collator->match($str, $sub);
259 $str = $IsEBCDIC ? "mu\x{0059}" : "mu\x{00DF}";
260 $sub = $IsEBCDIC ? "m\x{00DC}s" : "m\x{00FC}s";
262 ($ret) = $Collator->match($str, $sub);
265 $ret = join ':', $Collator->gmatch("P\cBe\x{300}\cBrl, perl, and PERL", "pe");
266 ok($ret eq "P\cBe\x{300}\cB:pe:PE");
268 $ret = $Collator->gmatch("P\cBe\x{300}\cBrl, perl, and PERL", "pe");
273 $ret = $Collator->match($str, $sub);
275 ok($ret && $$ret, "CDE");
279 ($ret) = $Collator->match($str, $sub);
284 $Collator->change(level => 3);
286 $ret = $Collator->match("P\cBe\x{300}\cBrl and PERL", "pe");
289 @ret = $Collator->match("P\cBe\x{300}\cBrl and PERL", "pe");
292 $ret = join ':', $Collator->gmatch("P\cBe\x{300}\cBrl and PERL", "pe");
295 $ret = $Collator->gmatch("P\cBe\x{300}\cBrl and PERL", "pe");
298 $ret = join ':', $Collator->gmatch("P\cBe\x{300}\cBrl, perl, and PERL", "pe");
301 $ret = $Collator->gmatch("P\cBe\x{300}\cBrl, perl, and PERL", "pe");
304 $str = $IsEBCDIC ? "mu\x{0059}" : "mu\x{00DF}";
305 $sub = $IsEBCDIC ? "m\x{00DC}ss" : "m\x{00FC}ss";
307 ($ret) = $Collator->match($str, $sub);
310 $Collator->change(%old_level);
314 $Collator->change(level => 1);
316 sub strreverse { scalar reverse shift }
318 $str = "P\cBe\x{300}\cBrl and PERL.";
319 $ret = $Collator->subst($str, "perl", 'Camel');
321 ok($str, "Camel and PERL.");
323 $str = "P\cBe\x{300}\cBrl and PERL.";
324 $ret = $Collator->subst($str, "perl", \&strreverse);
326 ok($str, "lr\cB\x{300}e\cBP and PERL.");
328 $str = "P\cBe\x{300}\cBrl and PERL.";
329 $ret = $Collator->gsubst($str, "perl", 'Camel');
331 ok($str, "Camel and Camel.");
333 $str = "P\cBe\x{300}\cBrl and PERL.";
334 $ret = $Collator->gsubst($str, "perl", \&strreverse);
336 ok($str, "lr\cB\x{300}e\cBP and LREP.");
338 $str = "Camel ass came\x{301}l CAMEL horse cAm\0E\0L...";
339 $Collator->gsubst($str, "camel", sub { "<b>$_[0]</b>" });
341 "<b>Camel</b> ass <b>came\x{301}l</b> <b>CAMEL</b> horse <b>cAm\0E\0L</b>...");
343 $Collator->change(level => 3);
345 $str = "P\cBe\x{300}\cBrl and PERL.";
346 $ret = $Collator->subst($str, "perl", "Camel");
348 ok($str, "P\cBe\x{300}\cBrl and PERL.");
350 $str = "P\cBe\x{300}\cBrl and PERL.";
351 $ret = $Collator->subst($str, "perl", \&strreverse);
353 ok($str, "P\cBe\x{300}\cBrl and PERL.");
355 $str = "P\cBe\x{300}\cBrl and PERL.";
356 $ret = $Collator->gsubst($str, "perl", "Camel");
358 ok($str, "P\cBe\x{300}\cBrl and PERL.");
360 $str = "P\cBe\x{300}\cBrl and PERL.";
361 $ret = $Collator->gsubst($str, "perl", \&strreverse);
363 ok($str, "P\cBe\x{300}\cBrl and PERL.");
365 $Collator->change(%old_level);
369 $str = "Perl and Camel";
370 $ret = $Collator->gsubst($str, "\cA\cA\0", "AB");
372 ok($str, "ABPABeABrABlAB ABaABnABdAB ABCABaABmABeABlAB");
375 $ret = $Collator->subst($str, "", "ABC");
380 $ret = $Collator->gsubst($str, "", "ABC");
385 $ret = $Collator->gsubst($str, 'PP', "ABC");
391 # Shifted; ignorable after variable
393 ($ret) = $Collator->match("A?\x{300}!\x{301}\x{344}B\x{315}", "?!");
394 ok($ret, "?\x{300}!\x{301}\x{344}");
396 $Collator->change(alternate => 'Non-ignorable');
398 ($ret) = $Collator->match("A?\x{300}!\x{301}B\x{315}", "?!");