This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pat-advanced.t: Add new test
[perl5.git] / t / re / pat_advanced.t
CommitLineData
e425a60b
YO
1#!./perl
2#
3# This is a home for regular expression tests that don't fit into
4# the format supported by re/regexp.t. If you want to add a test
5# that does fit that format, add it to re/re_tests, not here.
6
7use strict;
8use warnings;
9use 5.010;
10
11
12sub run_tests;
13
14$| = 1;
15
e425a60b
YO
16
17BEGIN {
18 chdir 't' if -d 't';
9d45b377
YO
19 @INC = ('../lib','.');
20 do "re/ReTest.pl" or die $@;
e425a60b 21}
e425a60b 22
e425a60b 23
0ab1ff8e 24plan tests => 1343; # Update this when adding/deleting tests.
e425a60b 25
9d45b377 26run_tests() unless caller;
e425a60b
YO
27
28#
29# Tests start here.
30#
31sub run_tests {
32
e425a60b
YO
33 SKIP:
34 {
35 local $Message = '\C matches octet';
36 $_ = "a\x{100}b";
37 ok /(.)(\C)(\C)(.)/ or skip q [\C doesn't match], 4;
38 iseq $1, "a";
39 if ($IS_ASCII) { # ASCII (or equivalent), should be UTF-8
40 iseq $2, "\xC4";
41 iseq $3, "\x80";
42 }
43 elsif ($IS_EBCDIC) { # EBCDIC (or equivalent), should be UTF-EBCDIC
44 iseq $2, "\x8C";
45 iseq $3, "\x41";
46 }
47 else {
48 SKIP: {
49 ok 0, "Unexpected platform", "ord ('A') = $ordA";
50 skip "Unexpected platform";
51 }
52 }
53 iseq $4, "b";
54 }
55
56
57 SKIP:
58 {
59 local $Message = '\C matches octet';
60 $_ = "\x{100}";
61 ok /(\C)/g or skip q [\C doesn't match], 2;
62 if ($IS_ASCII) {
63 iseq $1, "\xC4";
64 }
65 elsif ($IS_EBCDIC) {
66 iseq $1, "\x8C";
67 }
68 else {
69 ok 0, "Unexpected platform", "ord ('A') = $ordA";
70 }
71 ok /(\C)/g or skip q [\C doesn't match];
72 if ($IS_ASCII) {
73 iseq $1, "\x80";
74 }
75 elsif ($IS_EBCDIC) {
76 iseq $1, "\x41";
77 }
78 else {
79 ok 0, "Unexpected platform", "ord ('A') = $ordA";
80 }
81 }
82
83
84 {
85 # Japhy -- added 03/03/2001
86 () = (my $str = "abc") =~ /(...)/;
87 $str = "def";
88 iseq $1, "abc", 'Changing subject does not modify $1';
89 }
90
91
92 SKIP:
93 {
94 # The trick is that in EBCDIC the explicit numeric range should
95 # match (as also in non-EBCDIC) but the explicit alphabetic range
96 # should not match.
97 ok "\x8e" =~ /[\x89-\x91]/, '"\x8e" =~ /[\x89-\x91]/';
98 ok "\xce" =~ /[\xc9-\xd1]/, '"\xce" =~ /[\xc9-\xd1]/';
99
100 skip "Not an EBCDIC platform", 2 unless ord ('i') == 0x89 &&
101 ord ('J') == 0xd1;
102
103 # In most places these tests would succeed since \x8e does not
104 # in most character sets match 'i' or 'j' nor would \xce match
105 # 'I' or 'J', but strictly speaking these tests are here for
106 # the good of EBCDIC, so let's test these only there.
107 nok "\x8e" !~ /[i-j]/, '"\x8e" !~ /[i-j]/';
108 nok "\xce" !~ /[I-J]/, '"\xce" !~ /[I-J]/';
109 }
110
111
112 {
113 ok "\x{ab}" =~ /\x{ab}/, '"\x{ab}" =~ /\x{ab}/ ';
114 ok "\x{abcd}" =~ /\x{abcd}/, '"\x{abcd}" =~ /\x{abcd}/';
115 }
116
117
118 {
119 local $Message = 'bug id 20001008.001';
120
121 my @x = ("stra\337e 138", "stra\337e 138");
122 for (@x) {
123 ok s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
124 ok my ($latin) = /^(.+)(?:\s+\d)/;
125 iseq $latin, "stra\337e";
0f289c68 126 ok $latin =~ s/stra\337e/straße/;
e425a60b
YO
127 #
128 # Previous code follows, but outcommented - there were no tests.
129 #
130 # $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
131 # use utf8; # needed for the raw UTF-8
132 # $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
133 }
134 }
135
136
137 {
138 local $Message = 'Test \x escapes';
139 ok "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
140 ok "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
141 ok "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
142 ok "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
143 ok "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
144 ok "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
145 ok "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
146 ok "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
147 }
148
149
e425a60b
YO
150 SKIP:
151 {
152 local $Message = 'Match code points > 255';
153 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
154 ok /(.\x{300})./ or skip "No match", 4;
155 ok $` eq "abc\x{100}" && length ($`) == 4;
156 ok $& eq "\x{200}\x{300}\x{380}" && length ($&) == 3;
157 ok $' eq "\x{400}defg" && length ($') == 5;
158 ok $1 eq "\x{200}\x{300}" && length ($1) == 2;
159 }
160
161
e425a60b
YO
162
163 {
164 my $x = "\x{10FFFD}";
165 $x =~ s/(.)/$1/g;
166 ok ord($x) == 0x10FFFD && length($x) == 1, "From Robin Houston";
167 }
168
169
170 {
171 my %d = (
172 "7f" => [0, 0, 0],
173 "80" => [1, 1, 0],
174 "ff" => [1, 1, 0],
175 "100" => [0, 1, 1],
176 );
177 SKIP:
178 while (my ($code, $match) = each %d) {
179 local $Message = "Properties of \\x$code";
180 my $char = eval qq ["\\x{$code}"];
181 my $i = 0;
182 ok (($char =~ /[\x80-\xff]/) xor !$$match [$i ++]);
183 ok (($char =~ /[\x80-\x{100}]/) xor !$$match [$i ++]);
184 ok (($char =~ /[\x{100}]/) xor !$$match [$i ++]);
185 }
186 }
187
188
189 {
190 # From Japhy
191 local $Message;
192 must_warn 'qr/(?c)/', '^Useless \(\?c\)';
193 must_warn 'qr/(?-c)/', '^Useless \(\?-c\)';
194 must_warn 'qr/(?g)/', '^Useless \(\?g\)';
195 must_warn 'qr/(?-g)/', '^Useless \(\?-g\)';
196 must_warn 'qr/(?o)/', '^Useless \(\?o\)';
197 must_warn 'qr/(?-o)/', '^Useless \(\?-o\)';
198
199 # Now test multi-error regexes
200 must_warn 'qr/(?g-o)/', '^Useless \(\?g\).*\nUseless \(\?-o\)';
201 must_warn 'qr/(?g-c)/', '^Useless \(\?g\).*\nUseless \(\?-c\)';
202 # (?c) means (?g) error won't be thrown
203 must_warn 'qr/(?o-cg)/', '^Useless \(\?o\).*\nUseless \(\?-c\)';
204 must_warn 'qr/(?ogc)/', '^Useless \(\?o\).*\nUseless \(\?g\).*\n' .
205 'Useless \(\?c\)';
206 }
207
208
209 {
210 local $Message = "/x tests";
211 $_ = "foo";
212 eval_ok <<" --";
213 /f
214 o\r
215 o
216 \$
217 /x
218 --
219 eval_ok <<" --";
220 /f
221 o
222 o
223 \$\r
224 /x
225 --
226 }
227
228
229 {
230 local $Message = "/o feature";
231 sub test_o {$_ [0] =~ /$_[1]/o; return $1}
232 iseq test_o ('abc', '(.)..'), 'a';
233 iseq test_o ('abc', '..(.)'), 'a';
234 }
235
e425a60b
YO
236 {
237 # Test basic $^N usage outside of a regex
238 local $Message = '$^N usage outside of a regex';
239 my $x = "abcdef";
240 ok ($x =~ /cde/ and !defined $^N);
241 ok ($x =~ /(cde)/ and $^N eq "cde");
242 ok ($x =~ /(c)(d)(e)/ and $^N eq "e");
243 ok ($x =~ /(c(d)e)/ and $^N eq "cde");
244 ok ($x =~ /(foo)|(c(d)e)/ and $^N eq "cde");
245 ok ($x =~ /(c(d)e)|(foo)/ and $^N eq "cde");
246 ok ($x =~ /(c(d)e)|(abc)/ and $^N eq "abc");
247 ok ($x =~ /(c(d)e)|(abc)x/ and $^N eq "cde");
248 ok ($x =~ /(c(d)e)(abc)?/ and $^N eq "cde");
249 ok ($x =~ /(?:c(d)e)/ and $^N eq "d");
250 ok ($x =~ /(?:c(d)e)(?:f)/ and $^N eq "d");
251 ok ($x =~ /(?:([abc])|([def]))*/ and $^N eq "f");
252 ok ($x =~ /(?:([ace])|([bdf]))*/ and $^N eq "f");
253 ok ($x =~ /(([ace])|([bd]))*/ and $^N eq "e");
254 {ok ($x =~ /(([ace])|([bdf]))*/ and $^N eq "f");}
255 ## Test to see if $^N is automatically localized -- it should now
256 ## have the value set in the previous test.
257 iseq $^N, "e", '$^N is automatically localized';
258
259 # Now test inside (?{ ... })
260 local $Message = '$^N usage inside (?{ ... })';
261 our ($y, $z);
262 ok ($x =~ /a([abc])(?{$y=$^N})c/ and $y eq "b");
263 ok ($x =~ /a([abc]+)(?{$y=$^N})d/ and $y eq "bc");
264 ok ($x =~ /a([abcdefg]+)(?{$y=$^N})d/ and $y eq "bc");
265 ok ($x =~ /(a([abcdefg]+)(?{$y=$^N})d)(?{$z=$^N})e/ and $y eq "bc"
266 and $z eq "abcd");
267 ok ($x =~ /(a([abcdefg]+)(?{$y=$^N})de)(?{$z=$^N})/ and $y eq "bc"
268 and $z eq "abcde");
269
270 }
271
272
273 SKIP:
274 {
275 ## Should probably put in tests for all the POSIX stuff,
276 ## but not sure how to guarantee a specific locale......
277
278 skip "Not an ASCII platform", 2 unless $IS_ASCII;
279 local $Message = 'Test [[:cntrl:]]';
280 my $AllBytes = join "" => map {chr} 0 .. 255;
281 (my $x = $AllBytes) =~ s/[[:cntrl:]]//g;
282 iseq $x, join "", map {chr} 0x20 .. 0x7E, 0x80 .. 0xFF;
283
284 ($x = $AllBytes) =~ s/[^[:cntrl:]]//g;
285 iseq $x, join "", map {chr} 0x00 .. 0x1F, 0x7F;
286 }
287
288
289 {
290 # With /s modifier UTF8 chars were interpreted as bytes
291 local $Message = "UTF-8 chars aren't bytes";
292 my $a = "Hello \x{263A} World";
293 my @a = ($a =~ /./gs);
294 iseq $#a, 12;
295 }
296
297
298 {
299 local $Message = '. matches \n with /s';
300 my $str1 = "foo\nbar";
301 my $str2 = "foo\n\x{100}bar";
302 my ($a, $b) = map {chr} $IS_ASCII ? (0xc4, 0x80) : (0x8c, 0x41);
303 my @a;
304 @a = $str1 =~ /./g; iseq @a, 6; iseq "@a", "f o o b a r";
305 @a = $str1 =~ /./gs; iseq @a, 7; iseq "@a", "f o o \n b a r";
306 @a = $str1 =~ /\C/g; iseq @a, 7; iseq "@a", "f o o \n b a r";
307 @a = $str1 =~ /\C/gs; iseq @a, 7; iseq "@a", "f o o \n b a r";
308 @a = $str2 =~ /./g; iseq @a, 7; iseq "@a", "f o o \x{100} b a r";
309 @a = $str2 =~ /./gs; iseq @a, 8; iseq "@a", "f o o \n \x{100} b a r";
310 @a = $str2 =~ /\C/g; iseq @a, 9; iseq "@a", "f o o \n $a $b b a r";
311 @a = $str2 =~ /\C/gs; iseq @a, 9; iseq "@a", "f o o \n $a $b b a r";
312 }
313
314
315 {
e425a60b
YO
316 no warnings 'digit';
317 # Check that \x## works. 5.6.1 and 5.005_03 fail some of these.
318 my $x;
319 $x = "\x4e" . "E";
320 ok ($x =~ /^\x4EE$/, "Check only 2 bytes of hex are matched.");
321
322 $x = "\x4e" . "i";
323 ok ($x =~ /^\x4Ei$/, "Check that invalid hex digit stops it (2)");
324
325 $x = "\x4" . "j";
326 ok ($x =~ /^\x4j$/, "Check that invalid hex digit stops it (1)");
327
328 $x = "\x0" . "k";
329 ok ($x =~ /^\xk$/, "Check that invalid hex digit stops it (0)");
330
331 $x = "\x0" . "x";
332 ok ($x =~ /^\xx$/, "\\xx isn't to be treated as \\0");
333
334 $x = "\x0" . "xa";
335 ok ($x =~ /^\xxa$/, "\\xxa isn't to be treated as \\xa");
336
337 $x = "\x9" . "_b";
338 ok ($x =~ /^\x9_b$/, "\\x9_b isn't to be treated as \\x9b");
339
340 # and now again in [] ranges
341
342 $x = "\x4e" . "E";
343 ok ($x =~ /^[\x4EE]{2}$/, "Check only 2 bytes of hex are matched.");
344
345 $x = "\x4e" . "i";
346 ok ($x =~ /^[\x4Ei]{2}$/, "Check that invalid hex digit stops it (2)");
347
348 $x = "\x4" . "j";
349 ok ($x =~ /^[\x4j]{2}$/, "Check that invalid hex digit stops it (1)");
350
351 $x = "\x0" . "k";
352 ok ($x =~ /^[\xk]{2}$/, "Check that invalid hex digit stops it (0)");
353
354 $x = "\x0" . "x";
355 ok ($x =~ /^[\xx]{2}$/, "\\xx isn't to be treated as \\0");
356
357 $x = "\x0" . "xa";
358 ok ($x =~ /^[\xxa]{3}$/, "\\xxa isn't to be treated as \\xa");
359
360 $x = "\x9" . "_b";
361 ok ($x =~ /^[\x9_b]{3}$/, "\\x9_b isn't to be treated as \\x9b");
362
363 # Check that \x{##} works. 5.6.1 fails quite a few of these.
364
365 $x = "\x9b";
366 ok ($x =~ /^\x{9_b}$/, "\\x{9_b} is to be treated as \\x9b");
367
368 $x = "\x9b" . "y";
369 ok ($x =~ /^\x{9_b}y$/, "\\x{9_b} is to be treated as \\x9b (again)");
370
371 $x = "\x9b" . "y";
372 ok ($x =~ /^\x{9b_}y$/, "\\x{9b_} is to be treated as \\x9b");
373
374 $x = "\x9b" . "y";
375 ok ($x =~ /^\x{9_bq}y$/, "\\x{9_bc} is to be treated as \\x9b");
376
377 $x = "\x0" . "y";
378 ok ($x =~ /^\x{x9b}y$/, "\\x{x9b} is to be treated as \\x0");
379
380 $x = "\x0" . "y";
381 ok ($x =~ /^\x{0x9b}y$/, "\\x{0x9b} is to be treated as \\x0");
382
383 $x = "\x9b" . "y";
384 ok ($x =~ /^\x{09b}y$/, "\\x{09b} is to be treated as \\x9b");
385
386 $x = "\x9b";
387 ok ($x =~ /^[\x{9_b}]$/, "\\x{9_b} is to be treated as \\x9b");
388
389 $x = "\x9b" . "y";
390 ok ($x =~ /^[\x{9_b}y]{2}$/,
391 "\\x{9_b} is to be treated as \\x9b (again)");
392
393 $x = "\x9b" . "y";
394 ok ($x =~ /^[\x{9b_}y]{2}$/, "\\x{9b_} is to be treated as \\x9b");
395
396 $x = "\x9b" . "y";
397 ok ($x =~ /^[\x{9_bq}y]{2}$/, "\\x{9_bc} is to be treated as \\x9b");
398
399 $x = "\x0" . "y";
400 ok ($x =~ /^[\x{x9b}y]{2}$/, "\\x{x9b} is to be treated as \\x0");
401
402 $x = "\x0" . "y";
403 ok ($x =~ /^[\x{0x9b}y]{2}$/, "\\x{0x9b} is to be treated as \\x0");
404
405 $x = "\x9b" . "y";
406 ok ($x =~ /^[\x{09b}y]{2}$/, "\\x{09b} is to be treated as \\x9b");
407
408 }
409
410
411 {
412 # High bit bug -- japhy
413 my $x = "ab\200d";
414 ok $x =~ /.*?\200/, "High bit fine";
415 }
416
417
418 {
419 # The basic character classes and Unicode
420 ok "\x{0100}" =~ /\w/, 'LATIN CAPITAL LETTER A WITH MACRON in /\w/';
421 ok "\x{0660}" =~ /\d/, 'ARABIC-INDIC DIGIT ZERO in /\d/';
422 ok "\x{1680}" =~ /\s/, 'OGHAM SPACE MARK in /\s/';
423 }
424
425
426 {
427 local $Message = "Folding matches and Unicode";
428 ok "a\x{100}" =~ /A/i;
429 ok "A\x{100}" =~ /a/i;
430 ok "a\x{100}" =~ /a/i;
431 ok "A\x{100}" =~ /A/i;
432 ok "\x{101}a" =~ /\x{100}/i;
433 ok "\x{100}a" =~ /\x{100}/i;
434 ok "\x{101}a" =~ /\x{101}/i;
435 ok "\x{100}a" =~ /\x{101}/i;
436 ok "a\x{100}" =~ /A\x{100}/i;
437 ok "A\x{100}" =~ /a\x{100}/i;
438 ok "a\x{100}" =~ /a\x{100}/i;
439 ok "A\x{100}" =~ /A\x{100}/i;
440 ok "a\x{100}" =~ /[A]/i;
441 ok "A\x{100}" =~ /[a]/i;
442 ok "a\x{100}" =~ /[a]/i;
443 ok "A\x{100}" =~ /[A]/i;
444 ok "\x{101}a" =~ /[\x{100}]/i;
445 ok "\x{100}a" =~ /[\x{100}]/i;
446 ok "\x{101}a" =~ /[\x{101}]/i;
447 ok "\x{100}a" =~ /[\x{101}]/i;
448 }
449
450
451 {
452 use charnames ':full';
453 local $Message = "Folding 'LATIN LETTER A WITH GRAVE'";
454
455 my $lower = "\N{LATIN SMALL LETTER A WITH GRAVE}";
456 my $UPPER = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";
0f289c68 457
e425a60b
YO
458 ok $lower =~ m/$UPPER/i;
459 ok $UPPER =~ m/$lower/i;
460 ok $lower =~ m/[$UPPER]/i;
461 ok $UPPER =~ m/[$lower]/i;
462
463 local $Message = "Folding 'GREEK LETTER ALPHA WITH VRACHY'";
464
465 $lower = "\N{GREEK CAPITAL LETTER ALPHA WITH VRACHY}";
466 $UPPER = "\N{GREEK SMALL LETTER ALPHA WITH VRACHY}";
467
468 ok $lower =~ m/$UPPER/i;
469 ok $UPPER =~ m/$lower/i;
470 ok $lower =~ m/[$UPPER]/i;
471 ok $UPPER =~ m/[$lower]/i;
472
473 local $Message = "Folding 'LATIN LETTER Y WITH DIAERESIS'";
474
475 $lower = "\N{LATIN SMALL LETTER Y WITH DIAERESIS}";
476 $UPPER = "\N{LATIN CAPITAL LETTER Y WITH DIAERESIS}";
477
478 ok $lower =~ m/$UPPER/i;
479 ok $UPPER =~ m/$lower/i;
480 ok $lower =~ m/[$UPPER]/i;
481 ok $UPPER =~ m/[$lower]/i;
482 }
483
484
485 {
486 use charnames ':full';
487 local $PatchId = "13843";
488 local $Message = "GREEK CAPITAL LETTER SIGMA vs " .
489 "COMBINING GREEK PERISPOMENI";
490
491 my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}";
492 my $char = "\N{COMBINING GREEK PERISPOMENI}";
493
494 may_not_warn sub {ok "_:$char:_" !~ m/_:$SIGMA:_/i};
495 }
496
497
498 {
499 local $Message = '\X';
500 use charnames ':full';
501
502 ok "a!" =~ /^(\X)!/ && $1 eq "a";
503 ok "\xDF!" =~ /^(\X)!/ && $1 eq "\xDF";
504 ok "\x{100}!" =~ /^(\X)!/ && $1 eq "\x{100}";
505 ok "\x{100}\x{300}!" =~ /^(\X)!/ && $1 eq "\x{100}\x{300}";
506 ok "\N{LATIN CAPITAL LETTER E}!" =~ /^(\X)!/ &&
507 $1 eq "\N{LATIN CAPITAL LETTER E}";
508 ok "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}!"
509 =~ /^(\X)!/ &&
510 $1 eq "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}";
511
512 local $Message = '\C and \X';
513 ok "!abc!" =~ /a\Cc/;
514 ok "!abc!" =~ /a\Xc/;
515 }
516
517
518 {
519 local $Message = "Final Sigma";
520
521 my $SIGMA = "\x{03A3}"; # CAPITAL
522 my $Sigma = "\x{03C2}"; # SMALL FINAL
523 my $sigma = "\x{03C3}"; # SMALL
524
525 ok $SIGMA =~ /$SIGMA/i;
526 ok $SIGMA =~ /$Sigma/i;
527 ok $SIGMA =~ /$sigma/i;
528
529 ok $Sigma =~ /$SIGMA/i;
530 ok $Sigma =~ /$Sigma/i;
531 ok $Sigma =~ /$sigma/i;
532
533 ok $sigma =~ /$SIGMA/i;
534 ok $sigma =~ /$Sigma/i;
535 ok $sigma =~ /$sigma/i;
0f289c68 536
e425a60b
YO
537 ok $SIGMA =~ /[$SIGMA]/i;
538 ok $SIGMA =~ /[$Sigma]/i;
539 ok $SIGMA =~ /[$sigma]/i;
540
541 ok $Sigma =~ /[$SIGMA]/i;
542 ok $Sigma =~ /[$Sigma]/i;
543 ok $Sigma =~ /[$sigma]/i;
544
545 ok $sigma =~ /[$SIGMA]/i;
546 ok $sigma =~ /[$Sigma]/i;
547 ok $sigma =~ /[$sigma]/i;
548
549 local $Message = "More final Sigma";
550
551 my $S3 = "$SIGMA$Sigma$sigma";
552
553 ok ":$S3:" =~ /:(($SIGMA)+):/i && $1 eq $S3 && $2 eq $sigma;
554 ok ":$S3:" =~ /:(($Sigma)+):/i && $1 eq $S3 && $2 eq $sigma;
555 ok ":$S3:" =~ /:(($sigma)+):/i && $1 eq $S3 && $2 eq $sigma;
556
557 ok ":$S3:" =~ /:(([$SIGMA])+):/i && $1 eq $S3 && $2 eq $sigma;
558 ok ":$S3:" =~ /:(([$Sigma])+):/i && $1 eq $S3 && $2 eq $sigma;
559 ok ":$S3:" =~ /:(([$sigma])+):/i && $1 eq $S3 && $2 eq $sigma;
560 }
561
562
563 {
564 use charnames ':full';
565 local $Message = "Parlez-Vous " .
566 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais?";
567
568 ok "Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran.ais/ &&
569 $& eq "Francais";
570 ok "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran.ais/ &&
571 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais";
572 ok "Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran\Cais/ &&
573 $& eq "Francais";
574 # COMBINING CEDILLA is two bytes when encoded
575 ok "Franc\N{COMBINING CEDILLA}ais" =~ /Franc\C\Cais/;
576 ok "Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran\Xais/ &&
577 $& eq "Francais";
578 ok "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran\Xais/ &&
579 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais";
580 ok "Franc\N{COMBINING CEDILLA}ais" =~ /Fran\Xais/ &&
581 $& eq "Franc\N{COMBINING CEDILLA}ais";
582 ok "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
583 /Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais/ &&
584 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais";
585 ok "Franc\N{COMBINING CEDILLA}ais" =~ /Franc\N{COMBINING CEDILLA}ais/ &&
586 $& eq "Franc\N{COMBINING CEDILLA}ais";
587
588 my @f = (
589 ["Fran\N{LATIN SMALL LETTER C}ais", "Francais"],
590 ["Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais",
591 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais"],
592 ["Franc\N{COMBINING CEDILLA}ais", "Franc\N{COMBINING CEDILLA}ais"],
593 );
594 foreach my $entry (@f) {
595 my ($subject, $match) = @$entry;
596 ok $subject =~ /Fran(?:c\N{COMBINING CEDILLA}?|
597 \N{LATIN SMALL LETTER C WITH CEDILLA})ais/x &&
598 $& eq $match;
599 }
600 }
601
602
603 {
604 local $Message = "Lingering (and useless) UTF8 flag doesn't mess up /i";
605 my $pat = "ABcde";
606 my $str = "abcDE\x{100}";
607 chop $str;
608 ok $str =~ /$pat/i;
609
610 $pat = "ABcde\x{100}";
611 $str = "abcDE";
612 chop $pat;
613 ok $str =~ /$pat/i;
614
615 $pat = "ABcde\x{100}";
616 $str = "abcDE\x{100}";
617 chop $pat;
618 chop $str;
619 ok $str =~ /$pat/i;
620 }
621
622
623 {
624 use charnames ':full';
625 local $Message = "LATIN SMALL LETTER SHARP S " .
626 "(\N{LATIN SMALL LETTER SHARP S})";
627
628 ok "\N{LATIN SMALL LETTER SHARP S}" =~
629 /\N{LATIN SMALL LETTER SHARP S}/;
630 ok "\N{LATIN SMALL LETTER SHARP S}" =~
631 /\N{LATIN SMALL LETTER SHARP S}/i;
632 ok "\N{LATIN SMALL LETTER SHARP S}" =~
633 /[\N{LATIN SMALL LETTER SHARP S}]/;
634 ok "\N{LATIN SMALL LETTER SHARP S}" =~
635 /[\N{LATIN SMALL LETTER SHARP S}]/i;
636
637 ok "ss" =~ /\N{LATIN SMALL LETTER SHARP S}/i;
638 ok "SS" =~ /\N{LATIN SMALL LETTER SHARP S}/i;
639 ok "ss" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i;
640 ok "SS" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i;
641
642 ok "\N{LATIN SMALL LETTER SHARP S}" =~ /ss/i;
643 ok "\N{LATIN SMALL LETTER SHARP S}" =~ /SS/i;
0f289c68 644
e425a60b
YO
645 local $Message = "Unoptimized named sequence in class";
646 ok "ss" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i;
647 ok "SS" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i;
648 ok "\N{LATIN SMALL LETTER SHARP S}" =~
649 /[\N{LATIN SMALL LETTER SHARP S}x]/;
650 ok "\N{LATIN SMALL LETTER SHARP S}" =~
651 /[\N{LATIN SMALL LETTER SHARP S}x]/i;
652 }
653
654
655 {
656 # More whitespace: U+0085, U+2028, U+2029\n";
657
658 # U+0085, U+00A0 need to be forced to be Unicode, the \x{100} does that.
659 SKIP: {
660 skip "EBCDIC platform", 4 if $IS_EBCDIC;
661 # Do \x{0015} and \x{0041} match \s in EBCDIC?
662 ok "<\x{100}\x{0085}>" =~ /<\x{100}\s>/, '\x{0085} in \s';
663 ok "<\x{0085}>" =~ /<\v>/, '\x{0085} in \v';
664 ok "<\x{100}\x{00A0}>" =~ /<\x{100}\s>/, '\x{00A0} in \s';
665 ok "<\x{00A0}>" =~ /<\h>/, '\x{00A0} in \h';
666 }
667 my @h = map {sprintf "%05x" => $_} 0x01680, 0x0180E, 0x02000 .. 0x0200A,
668 0x0202F, 0x0205F, 0x03000;
669 my @v = map {sprintf "%05x" => $_} 0x02028, 0x02029;
670
671 my @H = map {sprintf "%05x" => $_} 0x01361, 0x0200B, 0x02408, 0x02420,
672 0x0303F, 0xE0020;
673 my @V = map {sprintf "%05x" => $_} 0x0008A .. 0x0008D, 0x00348, 0x10100,
674 0xE005F, 0xE007C;
675
676 for my $hex (@h) {
677 my $str = eval qq ["<\\x{$hex}>"];
678 ok $str =~ /<\s>/, "\\x{$hex} in \\s";
679 ok $str =~ /<\h>/, "\\x{$hex} in \\h";
680 ok $str !~ /<\v>/, "\\x{$hex} not in \\v";
681 }
682
683 for my $hex (@v) {
684 my $str = eval qq ["<\\x{$hex}>"];
685 ok $str =~ /<\s>/, "\\x{$hex} in \\s";
686 ok $str =~ /<\v>/, "\\x{$hex} in \\v";
687 ok $str !~ /<\h>/, "\\x{$hex} not in \\h";
688 }
689
690 for my $hex (@H) {
691 my $str = eval qq ["<\\x{$hex}>"];
692 ok $str =~ /<\S>/, "\\x{$hex} in \\S";
693 ok $str =~ /<\H>/, "\\x{$hex} in \\H";
694 }
695
696 for my $hex (@V) {
697 my $str = eval qq ["<\\x{$hex}>"];
698 ok $str =~ /<\S>/, "\\x{$hex} in \\S";
699 ok $str =~ /<\V>/, "\\x{$hex} in \\V";
700 }
701 }
702
703
704 {
705 # . with /s should work on characters, as opposed to bytes
706 local $Message = ". with /s works on characters, not bytes";
707
708 my $s = "\x{e4}\x{100}";
709 # This is not expected to match: the point is that
710 # neither should we get "Malformed UTF-8" warnings.
711 may_not_warn sub {$s =~ /\G(.+?)\n/gcs}, "No 'Malformed UTF-8' warning";
712
713 my @c;
714 push @c => $1 while $s =~ /\G(.)/gs;
715
716 local $" = "";
717 iseq "@c", $s;
718
719 # Test only chars < 256
720 my $t1 = "Q003\n\n\x{e4}\x{f6}\n\nQ004\n\n\x{e7}";
721 my $r1 = "";
722 while ($t1 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
0f289c68 723 $r1 .= $1 . $2;
e425a60b
YO
724 }
725
726 my $t2 = $t1 . "\x{100}"; # Repeat with a larger char
727 my $r2 = "";
728 while ($t2 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
0f289c68 729 $r2 .= $1 . $2;
e425a60b
YO
730 }
731 $r2 =~ s/\x{100}//;
732
733 iseq $r1, $r2;
734 }
735
736
737 {
738 local $Message = "Unicode lookbehind";
739 ok "A\x{100}B" =~ /(?<=A.)B/;
740 ok "A\x{200}\x{300}B" =~ /(?<=A..)B/;
741 ok "\x{400}AB" =~ /(?<=\x{400}.)B/;
742 ok "\x{500}\x{600}B" =~ /(?<=\x{500}.)B/;
743
744 # Original code also contained:
745 # ok "\x{500\x{600}}B" =~ /(?<=\x{500}.)B/;
746 # but that looks like a typo.
747 }
748
749
750 {
751 local $Message = 'UTF-8 hash keys and /$/';
752 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters
753 # /2002-01/msg01327.html
754
755 my $u = "a\x{100}";
756 my $v = substr ($u, 0, 1);
757 my $w = substr ($u, 1, 1);
758 my %u = ($u => $u, $v => $v, $w => $w);
759 for (keys %u) {
760 my $m1 = /^\w*$/ ? 1 : 0;
761 my $m2 = $u {$_} =~ /^\w*$/ ? 1 : 0;
762 iseq $m1, $m2;
763 }
764 }
765
766
767 {
e425a60b
YO
768 local $Message = "No SEGV in s/// and UTF-8";
769 my $s = "s#\x{100}" x 4;
770 ok $s =~ s/[^\w]/ /g;
2e84be61 771 if ( 1 or $ENV{PERL_TEST_LEGACY_POSIX_CC} ) {
e425a60b
YO
772 iseq $s, "s \x{100}" x 4;
773 }
774 else {
775 iseq $s, "s " x 4;
776 }
777 }
778
779
780 {
781 local $Message = "UTF-8 bug (maybe already known?)";
782 my $u = "foo";
783 $u =~ s/./\x{100}/g;
784 iseq $u, "\x{100}\x{100}\x{100}";
785
786 $u = "foobar";
787 $u =~ s/[ao]/\x{100}/g;
788 iseq $u, "f\x{100}\x{100}b\x{100}r";
789
790 $u =~ s/\x{100}/e/g;
791 iseq $u, "feeber";
792 }
793
794
795 {
796 local $Message = "UTF-8 bug with s///";
797 # check utf8/non-utf8 mixtures
798 # try to force all float/anchored check combinations
799
800 my $c = "\x{100}";
801 my $subst;
802 for my $re ("xx.*$c", "x.*$c$c", "$c.*xx", "$c$c.*x",
803 "xx.*(?=$c)", "(?=$c).*xx",) {
804 ok "xxx" !~ /$re/;
805 ok +($subst = "xxx") !~ s/$re//;
806 }
807 for my $re ("xx.*$c*", "$c*.*xx") {
808 ok "xxx" =~ /$re/;
809 ok +($subst = "xxx") =~ s/$re//;
810 iseq $subst, "";
811 }
812 for my $re ("xxy*", "y*xx") {
813 ok "xx$c" =~ /$re/;
814 ok +($subst = "xx$c") =~ s/$re//;
815 iseq $subst, $c;
816 ok "xy$c" !~ /$re/;
817 ok +($subst = "xy$c") !~ s/$re//;
818 }
819 for my $re ("xy$c*z", "x$c*yz") {
820 ok "xyz" =~ /$re/;
821 ok +($subst = "xyz") =~ s/$re//;
822 iseq $subst, "";
823 }
824 }
825
826
827 {
828 local $Message = "qr /.../x";
829 my $R = qr / A B C # D E/x;
830 ok "ABCDE" =~ $R && $& eq "ABC";
831 ok "ABCDE" =~ /$R/ && $& eq "ABC";
832 ok "ABCDE" =~ m/$R/ && $& eq "ABC";
833 ok "ABCDE" =~ /($R)/ && $1 eq "ABC";
834 ok "ABCDE" =~ m/($R)/ && $1 eq "ABC";
835 }
836
837
e425a60b 838
0f289c68 839
e425a60b
YO
840 {
841 local $\;
842 $_ = 'aaaaaaaaaa';
843 utf8::upgrade($_); chop $_; $\="\n";
844 ok /[^\s]+/, 'm/[^\s]/ utf8';
845 ok /[^\d]+/, 'm/[^\d]/ utf8';
846 ok +($a = $_, $_ =~ s/[^\s]+/./g), 's/[^\s]/ utf8';
847 ok +($a = $_, $a =~ s/[^\d]+/./g), 's/[^\s]/ utf8';
848 }
849
850
e425a60b
YO
851
852
853 {
854 # Subject: Odd regexp behavior
855 # From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
856 # Date: Wed, 26 Feb 2003 16:53:12 +0000
857 # Message-Id: <E18o4nw-0008Ly-00@wisbech.cl.cam.ac.uk>
858 # To: perl-unicode@perl.org
859
860 local $Message = 'Markus Kuhn 2003-02-26';
0f289c68 861
e425a60b
YO
862 my $x = "\x{2019}\nk";
863 ok $x =~ s/(\S)\n(\S)/$1 $2/sg;
864 ok $x eq "\x{2019} k";
865
866 $x = "b\nk";
867 ok $x =~ s/(\S)\n(\S)/$1 $2/sg;
868 ok $x eq "b k";
869
870 ok "\x{2019}" =~ /\S/;
871 }
872
873
874 {
e425a60b
YO
875 # XXX DAPM 13-Apr-06. Recursive split is still broken. It's only luck it
876 # hasn't been crashing. Disable this test until it is fixed properly.
877 # XXX also check what it returns rather than just doing ok(1,...)
878 # split /(?{ split "" })/, "abc";
879 local $TODO = "Recursive split is still broken";
880 ok 0, 'cache_re & "(?{": it dumps core in 5.6.1 & 5.8.0';
881 }
882
883
884 {
885 ok "\x{100}\n" =~ /\x{100}\n$/, "UTF-8 length cache and fbm_compile";
886 }
887
888
889 {
890 package Str;
891 use overload q /""/ => sub {${$_ [0]};};
892 sub new {my ($c, $v) = @_; bless \$v, $c;}
893
894 package main;
895 $_ = Str -> new ("a\x{100}/\x{100}b");
896 ok join (":", /\b(.)\x{100}/g) eq "a:/", "re_intuit_start and PL_bostr";
897 }
898
e425a60b
YO
899 {
900 my $re = qq /^([^X]*)X/;
901 utf8::upgrade ($re);
902 ok "\x{100}X" =~ /$re/, "S_cl_and ANYOF_UNICODE & ANYOF_INVERTED";
0ab1ff8e
KW
903 my $loc_re = qq /(?l:^([^X]*)X)/;
904 utf8::upgrade ($loc_re);
905 ok "\x{100}X" =~ /$loc_re/, "locale, S_cl_and ANYOF_UNICODE & ANYOF_INVERTED";
e425a60b
YO
906 }
907
e425a60b
YO
908 {
909 ok "123\x{100}" =~ /^.*1.*23\x{100}$/,
910 'UTF-8 + multiple floating substr';
911 }
912
e425a60b
YO
913 {
914 local $Message = '<20030808193656.5109.1@llama.ni-s.u-net.com>';
915
916 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
917 ok " \x{101}" =~ qr/\x{100}/i;
918
919 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
920 ok " \x{1E01}" =~ qr/\x{1E00}/i;
921
922 # DESERET SMALL/CAPITAL LETTER LONG I
923 ok " \x{10428}" =~ qr/\x{10400}/i;
924
925 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
926 ok " \x{1E01}x" =~ qr/\x{1E00}X/i;
927 }
928
e425a60b
YO
929 {
930 for (120 .. 130) {
931 my $head = 'x' x $_;
932 local $Message = q [Don't misparse \x{...} in regexp ] .
933 q [near 127 char EXACT limit];
934 for my $tail ('\x{0061}', '\x{1234}', '\x61') {
935 eval_ok qq ["$head$tail" =~ /$head$tail/];
936 }
937 local $Message = q [Don't misparse \N{...} in regexp ] .
938 q [near 127 char EXACT limit];
939 for my $tail ('\N{SNOWFLAKE}') {
940 eval_ok qq [use charnames ':full';
941 "$head$tail" =~ /$head$tail/];
942 }
943 }
944 }
945
e425a60b
YO
946 { # TRIE related
947 our @got = ();
948 "words" =~ /(word|word|word)(?{push @got, $1})s$/;
93f09d7b 949 iseq @got, 1, "TRIE optimisation";
e425a60b
YO
950
951 @got = ();
952 "words" =~ /(word|word|word)(?{push @got,$1})s$/i;
953 iseq @got, 1,"TRIEF optimisation";
954
955 my @nums = map {int rand 1000} 1 .. 100;
956 my $re = "(" . (join "|", @nums) . ")";
957 $re = qr/\b$re\b/;
958
959 foreach (@nums) {
960 ok $_ =~ /$re/, "Trie nums";
961 }
962
963 $_ = join " ", @nums;
964 @got = ();
965 push @got, $1 while /$re/g;
966
967 my %count;
968 $count {$_} ++ for @got;
969 my $ok = 1;
970 for (@nums) {
971 $ok = 0 if --$count {$_} < 0;
972 }
973 ok $ok, "Trie min count matches";
974 }
975
976
977 {
978 # TRIE related
979 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
980 ok "foba \x{101}foo" =~ qr/(foo|\x{100}foo|bar)/i &&
981 $1 eq "\x{101}foo",
982 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH MACRON";
983
984 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
985 ok "foba \x{1E01}foo" =~ qr/(foo|\x{1E00}foo|bar)/i &&
986 $1 eq "\x{1E01}foo",
987 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW";
988
989 # DESERET SMALL/CAPITAL LETTER LONG I
990 ok "foba \x{10428}foo" =~ qr/(foo|\x{10400}foo|bar)/i &&
991 $1 eq "\x{10428}foo",
992 "TRIEF + DESERET SMALL/CAPITAL LETTER LONG I";
993
994 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
995 ok "foba \x{1E01}xfoo" =~ qr/(foo|\x{1E00}Xfoo|bar)/i &&
996 $1 eq "\x{1E01}xfoo",
997 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'";
998
999 use charnames ':full';
1000
1001 my $s = "\N{LATIN SMALL LETTER SHARP S}";
1002 ok "foba ba$s" =~ qr/(foo|Ba$s|bar)/i && $1 eq "ba$s",
1003 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
1004 ok "foba ba$s" =~ qr/(Ba$s|foo|bar)/i && $1 eq "ba$s",
1005 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
1006 ok "foba ba$s" =~ qr/(foo|bar|Ba$s)/i && $1 eq "ba$s",
1007 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
1008
1009 ok "foba ba$s" =~ qr/(foo|Bass|bar)/i && $1 eq "ba$s",
1010 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
1011
1012 ok "foba ba$s" =~ qr/(foo|BaSS|bar)/i && $1 eq "ba$s",
1013 "TRIEF + LATIN SMALL LETTER SHARP S =~ SS";
1014
1015 ok "foba ba${s}pxySS$s$s" =~ qr/(b(?:a${s}t|a${s}f|a${s}p)[xy]+$s*)/i
1016 && $1 eq "ba${s}pxySS$s$s",
1017 "COMMON PREFIX TRIEF + LATIN SMALL LETTER SHARP S";
1018 }
1019
1020
e425a60b
YO
1021
1022
1023 {
0f289c68
YO
1024 BEGIN {
1025 unshift @INC, 'lib';
1026 }
e425a60b 1027 use Cname;
0f289c68 1028
e425a60b 1029 ok 'fooB' =~ /\N{foo}[\N{B}\N{b}]/, "Passthrough charname";
e425a60b
YO
1030 #
1031 # Why doesn't must_warn work here?
1032 #
1033 my $w;
1034 local $SIG {__WARN__} = sub {$w .= "@_"};
1035 eval 'q(xxWxx) =~ /[\N{WARN}]/';
ff3f963a
KW
1036 ok $w && $w =~ /Using just the first character returned by \\N{} in character class/,
1037 "single character in [\\N{}] warning";
e425a60b
YO
1038
1039 undef $w;
1040 eval q [ok "\0" !~ /[\N{EMPTY-STR}XY]/,
1041 "Zerolength charname in charclass doesn't match \\0"];
ff3f963a
KW
1042 ok $w && $w =~ /Ignoring zero length/,
1043 'Ignoring zero length \N{} in character class warning';
e425a60b
YO
1044
1045 ok 'AB' =~ /(\N{EVIL})/ && $1 eq 'A', 'Charname caching $1';
1046 ok 'ABC' =~ /(\N{EVIL})/, 'Charname caching $1';
1047 ok 'xy' =~ /x\N{EMPTY-STR}y/,
1048 'Empty string charname produces NOTHING node';
1049 ok '' =~ /\N{EMPTY-STR}/,
1050 'Empty string charname produces NOTHING node';
ff3f963a
KW
1051 ok "\N{LONG-STR}" =~ /^\N{LONG-STR}$/, 'Verify that long string works';
1052 ok "\N{LONG-STR}" =~ /^\N{LONG-STR}$/i, 'Verify under folding that long string works';
1053
1054 # If remove the limitation in regcomp code these should work
1055 # differently
1056 undef $w;
1057 eval q [ok "\N{LONG-STR}" =~ /^\N{TOO-LONG-STR}$/, 'Verify that too long a string fails gracefully'];
1058 ok $w && $w =~ /Using just the first characters returned/, 'Verify that got too-long string warning in \N{} that exceeds the limit';
1059 undef $w;
1060 eval q [ok "\N{LONG-STR}" =~ /^\N{TOO-LONG-STR}$/i, 'Verify under folding that too long a string fails gracefully'];
1061 ok $w && $w =~ /Using just the first characters returned/, 'Verify under folding that got too-long string warning in \N{} that exceeds the limit';
1062 undef $w;
1063 eval q [ok "\N{TOO-LONG-STR}" !~ /^\N{TOO-LONG-STR}$/, 'Verify that too long a string doesnt work'];
1064 ok $w && $w =~ /Using just the first characters returned/, 'Verify that got too-long string warning in \N{} that exceeds the limit';
1065 undef $w;
1066 eval q [ok "\N{TOO-LONG-STR}" !~ /^\N{TOO-LONG-STR}$/i, 'Verify under folding that too long a string doesnt work'];
1067 ok $w && $w =~ /Using just the first characters returned/i, 'Verify under folding that got too-long string warning in \N{} that exceeds the limit';
1068 undef $w;
1069 eval 'q(syntax error) =~ /\N{MALFORMED}/';
1070 ok $@ && $@ =~ /Malformed/, 'Verify that malformed utf8 gives an error';
cb233ae3
KW
1071 undef $w;
1072 eval 'q() =~ /\N{4F}/';
1073 ok $w && $w =~ /Deprecated/, 'Verify that leading digit in name gives warning';
1074 undef $w;
1075 eval 'q() =~ /\N{COM,MA}/';
1076 ok $w && $w =~ /Deprecated/, 'Verify that comma in name gives warning';
1077 undef $w;
1078 my $name = "A\x{D7}O";
1079 eval "q(W) =~ /\\N{$name}/";
1080 ok $w && $w =~ /Deprecated/, 'Verify that latin1 symbol in name gives warning';
1081 undef $w;
1082 $name = "A\x{D1}O";
1083 eval "q(W) =~ /\\N{$name}/";
1084 ok ! $w, 'Verify that latin1 letter in name doesnt give warning';
0f289c68 1085
e425a60b
YO
1086 }
1087
1088
1089 {
1090 use charnames ':full';
1091
1092 ok 'aabc' !~ /a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against aabc';
1093 ok 'a+bc' =~ /a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against a+bc';
1094
1095 ok ' A B' =~ /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
1096 'Intermixed named and unicode escapes';
1097 ok "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}" =~
1098 /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
1099 'Intermixed named and unicode escapes';
1100 ok "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}" =~
1101 /[\N{SPACE}\N{U+0041}][\N{SPACE}\N{U+0042}]/,
0f289c68 1102 'Intermixed named and unicode escapes';
ff3f963a 1103 ok "\0" =~ /^\N{NULL}$/, 'Verify that \N{NULL} works; is not confused with an error';
e425a60b
YO
1104 }
1105
1106
1107 {
1108 our $brackets;
1109 $brackets = qr{
1110 { (?> [^{}]+ | (??{ $brackets }) )* }
1111 }x;
1112
1113 ok "{b{c}d" !~ m/^((??{ $brackets }))/, "Bracket mismatch";
1114
1115 SKIP: {
1116 our @stack = ();
1117 my @expect = qw(
1118 stuff1
1119 stuff2
1120 <stuff1>and<stuff2>
1121 right
1122 <right>
1123 <<right>>
1124 <<<right>>>
1125 <<stuff1>and<stuff2>><<<<right>>>>
1126 );
1127
1128 local $_ = '<<<stuff1>and<stuff2>><<<<right>>>>>';
1129 ok /^(<((?:(?>[^<>]+)|(?1))*)>(?{push @stack, $2 }))$/,
1130 "Recursion matches";
1131 iseq @stack, @expect, "Right amount of matches"
1132 or skip "Won't test individual results as count isn't equal",
1133 0 + @expect;
1134 my $idx = 0;
1135 foreach my $expect (@expect) {
1136 iseq $stack [$idx], $expect,
1137 "Expecting '$expect' at stack pos #$idx";
1138 $idx ++;
1139 }
1140 }
1141 }
1142
1143
1144 {
1145 my $s = '123453456';
1146 $s =~ s/(?<digits>\d+)\k<digits>/$+{digits}/;
1147 ok $s eq '123456', 'Named capture (angle brackets) s///';
1148 $s = '123453456';
1149 $s =~ s/(?'digits'\d+)\k'digits'/$+{digits}/;
0f289c68 1150 ok $s eq '123456', 'Named capture (single quotes) s///';
e425a60b
YO
1151 }
1152
1153
1154 {
1155 my @ary = (
1156 pack('U', 0x00F1), # n-tilde
1157 '_'.pack('U', 0x00F1), # _ + n-tilde
1158 'c'.pack('U', 0x0327), # c + cedilla
1159 pack('U*', 0x00F1, 0x0327), # n-tilde + cedilla
e425a60b
YO
1160 pack('U', 0x0391), # ALPHA
1161 pack('U', 0x0391).'2', # ALPHA + 2
1162 pack('U', 0x0391).'_', # ALPHA + _
1163 );
1164
1165 for my $uni (@ary) {
1166 my ($r1, $c1, $r2, $c2) = eval qq {
1167 use utf8;
1168 scalar ("..foo foo.." =~ /(?'${uni}'foo) \\k'${uni}'/),
1169 \$+{${uni}},
1170 scalar ("..bar bar.." =~ /(?<${uni}>bar) \\k<${uni}>/),
1171 \$+{${uni}};
1172 };
1173 ok $r1, "Named capture UTF (?'')";
1174 ok defined $c1 && $c1 eq 'foo', "Named capture UTF \%+";
1175 ok $r2, "Named capture UTF (?<>)";
1176 ok defined $c2 && $c2 eq 'bar', "Named capture UTF \%+";
1177 }
1178 }
1179
e425a60b
YO
1180 {
1181 my $s = 'foo bar baz';
1182 my @res;
1183 if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) {
1184 foreach my $name (sort keys(%-)) {
1185 my $ary = $- {$name};
1186 foreach my $idx (0 .. $#$ary) {
1187 push @res, "$name:$idx:$ary->[$idx]";
1188 }
1189 }
1190 }
1191 my @expect = qw (A:0:1 A:1:3 B:0:2 B:1:4);
1192 iseq "@res", "@expect", "Check %-";
1193 eval'
1194 no warnings "uninitialized";
1195 print for $- {this_key_doesnt_exist};
1196 ';
1197 ok !$@,'lvalue $- {...} should not throw an exception';
1198 }
1199
e425a60b
YO
1200 {
1201 # \, breaks {3,4}
1202 ok "xaaay" !~ /xa{3\,4}y/, '\, in a pattern';
1203 ok "xa{3,4}y" =~ /xa{3\,4}y/, '\, in a pattern';
1204
1205 # \c\ followed by _
1206 ok "x\c_y" !~ /x\c\_y/, '\_ in a pattern';
1207 ok "x\c\_y" =~ /x\c\_y/, '\_ in a pattern';
1208
1209 # \c\ followed by other characters
1210 for my $c ("z", "\0", "!", chr(254), chr(256)) {
1211 my $targ = "a\034$c";
1212 my $reg = "a\\c\\$c";
1213 ok eval ("qq/$targ/ =~ /$reg/"), "\\c\\ in pattern";
1214 }
1215 }
1216
e425a60b
YO
1217 { # Test the (*PRUNE) pattern
1218 our $count = 0;
1219 'aaab' =~ /a+b?(?{$count++})(*FAIL)/;
1220 iseq $count, 9, "Expect 9 for no (*PRUNE)";
1221 $count = 0;
1222 'aaab' =~ /a+b?(*PRUNE)(?{$count++})(*FAIL)/;
1223 iseq $count, 3, "Expect 3 with (*PRUNE)";
1224 local $_ = 'aaab';
1225 $count = 0;
1226 1 while /.(*PRUNE)(?{$count++})(*FAIL)/g;
1227 iseq $count, 4, "/.(*PRUNE)/";
1228 $count = 0;
1229 'aaab' =~ /a+b?(??{'(*PRUNE)'})(?{$count++})(*FAIL)/;
1230 iseq $count, 3, "Expect 3 with (*PRUNE)";
1231 local $_ = 'aaab';
1232 $count = 0;
1233 1 while /.(??{'(*PRUNE)'})(?{$count++})(*FAIL)/g;
1234 iseq $count, 4, "/.(*PRUNE)/";
1235 }
1236
1237
1238 { # Test the (*SKIP) pattern
1239 our $count = 0;
1240 'aaab' =~ /a+b?(*SKIP)(?{$count++})(*FAIL)/;
1241 iseq $count, 1, "Expect 1 with (*SKIP)";
1242 local $_ = 'aaab';
1243 $count = 0;
1244 1 while /.(*SKIP)(?{$count++})(*FAIL)/g;
1245 iseq $count, 4, "/.(*SKIP)/";
1246 $_ = 'aaabaaab';
1247 $count = 0;
1248 our @res = ();
1249 1 while /(a+b?)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
1250 iseq $count, 2, "Expect 2 with (*SKIP)";
1251 iseq "@res", "aaab aaab", "Adjacent (*SKIP) works as expected";
1252 }
1253
1254
1255 { # Test the (*SKIP) pattern
1256 our $count = 0;
1257 'aaab' =~ /a+b?(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/;
1258 iseq $count, 1, "Expect 1 with (*SKIP)";
1259 local $_ = 'aaab';
1260 $count = 0;
1261 1 while /.(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/g;
1262 iseq $count, 4, "/.(*SKIP)/";
1263 $_ = 'aaabaaab';
1264 $count = 0;
1265 our @res = ();
1266 1 while /(a+b?)(*MARK:foo)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
1267 iseq $count, 2, "Expect 2 with (*SKIP)";
1268 iseq "@res", "aaab aaab", "Adjacent (*SKIP) works as expected";
1269 }
1270
1271
1272 { # Test the (*SKIP) pattern
1273 our $count = 0;
1274 'aaab' =~ /a*(*MARK:a)b?(*MARK:b)(*SKIP:a)(?{$count++})(*FAIL)/;
1275 iseq $count, 3, "Expect 3 with *MARK:a)b?(*MARK:b)(*SKIP:a)";
1276 local $_ = 'aaabaaab';
1277 $count = 0;
1278 our @res = ();
1279 1 while
1280 /(a*(*MARK:a)b?)(*MARK:x)(*SKIP:a)(?{$count++; push @res,$1})(*FAIL)/g;
1281 iseq $count, 5, "Expect 5 with (*MARK:a)b?)(*MARK:x)(*SKIP:a)";
1282 iseq "@res", "aaab b aaab b ",
1283 "Adjacent (*MARK:a)b?)(*MARK:x)(*SKIP:a) works as expected";
1284 }
1285
1286
1287 { # Test the (*COMMIT) pattern
1288 our $count = 0;
1289 'aaabaaab' =~ /a+b?(*COMMIT)(?{$count++})(*FAIL)/;
1290 iseq $count, 1, "Expect 1 with (*COMMIT)";
1291 local $_ = 'aaab';
1292 $count = 0;
1293 1 while /.(*COMMIT)(?{$count++})(*FAIL)/g;
1294 iseq $count, 1, "/.(*COMMIT)/";
1295 $_ = 'aaabaaab';
1296 $count = 0;
1297 our @res = ();
1298 1 while /(a+b?)(*COMMIT)(?{$count++; push @res,$1})(*FAIL)/g;
1299 iseq $count, 1, "Expect 1 with (*COMMIT)";
1300 iseq "@res", "aaab", "Adjacent (*COMMIT) works as expected";
1301 }
1302
1303
1304 {
1305 # Test named commits and the $REGERROR var
1306 our $REGERROR;
1307 for my $name ('', ':foo') {
1308 for my $pat ("(*PRUNE$name)",
1309 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)",
0f289c68 1310 "(*COMMIT$name)") {
e425a60b
YO
1311 for my $suffix ('(*FAIL)', '') {
1312 'aaaab' =~ /a+b$pat$suffix/;
1313 iseq $REGERROR,
1314 ($suffix ? ($name ? 'foo' : "1") : ""),
1315 "Test $pat and \$REGERROR $suffix";
1316 }
1317 }
1318 }
1319 }
1320
1321
1322 {
1323 # Test named commits and the $REGERROR var
1324 package Fnorble;
1325 our $REGERROR;
1326 for my $name ('', ':foo') {
1327 for my $pat ("(*PRUNE$name)",
1328 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)",
0f289c68 1329 "(*COMMIT$name)") {
e425a60b
YO
1330 for my $suffix ('(*FAIL)','') {
1331 'aaaab' =~ /a+b$pat$suffix/;
1332 ::iseq $REGERROR,
1333 ($suffix ? ($name ? 'foo' : "1") : ""),
1334 "Test $pat and \$REGERROR $suffix";
1335 }
1336 }
0f289c68
YO
1337 }
1338 }
e425a60b
YO
1339
1340
1341 {
1342 # Test named commits and the $REGERROR var
1343 local $Message = '$REGERROR';
1344 our $REGERROR;
1345 for my $word (qw (bar baz bop)) {
1346 $REGERROR = "";
1347 "aaaaa$word" =~
1348 /a+(?:bar(*COMMIT:bar)|baz(*COMMIT:baz)|bop(*COMMIT:bop))(*FAIL)/;
1349 iseq $REGERROR, $word;
0f289c68 1350 }
e425a60b
YO
1351 }
1352
e425a60b
YO
1353 {
1354 #Mindnumbingly simple test of (*THEN)
1355 for ("ABC","BAX") {
1356 ok /A (*THEN) X | B (*THEN) C/x, "Simple (*THEN) test";
1357 }
1358 }
1359
1360
1361 {
1362 local $Message = "Relative Recursion";
1363 my $parens = qr/(\((?:[^()]++|(?-1))*+\))/;
1364 local $_ = 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))';
1365 my ($all, $one, $two) = ('', '', '');
9d45b377 1366 ok m/foo $parens \s* \+ \s* bar $parens/x;
e425a60b
YO
1367 iseq $1, '((2*3)+4-3)';
1368 iseq $2, '(2*(3+4)-1*(2-3))';
1369 iseq $&, 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))';
1370 iseq $&, $_;
1371 }
1372
1373 {
1374 my $spaces=" ";
1375 local $_ = join 'bar', $spaces, $spaces;
1376 our $count = 0;
1377 s/(?>\s+bar)(?{$count++})//g;
1378 iseq $_, $spaces, "SUSPEND final string";
1379 iseq $count, 1, "Optimiser should have prevented more than one match";
1380 }
1381
e425a60b
YO
1382
1383 {
1384 # From Message-ID: <877ixs6oa6.fsf@k75.linux.bogus>
1385 my $dow_name = "nada";
1386 my $parser = "(\$dow_name) = \$time_string =~ /(D\x{e9}\\ " .
1387 "C\x{e9}adaoin|D\x{e9}\\ Sathairn|\\w+|\x{100})/";
1388 my $time_string = "D\x{e9} C\x{e9}adaoin";
1389 eval $parser;
1390 ok !$@, "Test Eval worked";
1391 iseq $dow_name, $time_string, "UTF-8 trie common prefix extraction";
1392 }
1393
1394
1395 {
1396 my $v;
1397 ($v = 'bar') =~ /(\w+)/g;
1398 $v = 'foo';
1399 iseq "$1", 'bar', '$1 is safe after /g - may fail due ' .
1400 'to specialized config in pp_hot.c'
1401 }
1402
1403
1404 {
1405 local $Message = "http://nntp.perl.org/group/perl.perl5.porters/118663";
1406 my $qr_barR1 = qr/(bar)\g-1/;
1407 ok "foobarbarxyz" =~ $qr_barR1;
1408 ok "foobarbarxyz" =~ qr/foo${qr_barR1}xyz/;
1409 ok "foobarbarxyz" =~ qr/(foo)${qr_barR1}xyz/;
1410 ok "foobarbarxyz" =~ qr/(foo)(bar)\g{-1}xyz/;
1411 ok "foobarbarxyz" =~ qr/(foo${qr_barR1})xyz/;
1412 ok "foobarbarxyz" =~ qr/(foo(bar)\g{-1})xyz/;
0f289c68 1413 }
e425a60b 1414
e425a60b
YO
1415 {
1416 local $Message = '$REGMARK';
1417 our @r = ();
1418 our ($REGMARK, $REGERROR);
1419 ok 'foofoo' =~ /foo (*MARK:foo) (?{push @r,$REGMARK}) /x;
0f289c68 1420 iseq "@r","foo";
e425a60b
YO
1421 iseq $REGMARK, "foo";
1422 ok 'foofoo' !~ /foo (*MARK:foo) (*FAIL) /x;
1423 ok !$REGMARK;
1424 iseq $REGERROR, 'foo';
1425 }
1426
1427
1428 {
1429 local $Message = '\K test';
1430 my $x;
1431 $x = "abc.def.ghi.jkl";
1432 $x =~ s/.*\K\..*//;
1433 iseq $x, "abc.def.ghi";
0f289c68 1434
e425a60b
YO
1435 $x = "one two three four";
1436 $x =~ s/o+ \Kthree//g;
1437 iseq $x, "one two four";
0f289c68 1438
e425a60b
YO
1439 $x = "abcde";
1440 $x =~ s/(.)\K/$1/g;
1441 iseq $x, "aabbccddee";
1442 }
1443
1444
1445 {
1446 sub kt {
1447 return '4' if $_[0] eq '09028623';
1448 }
1449 # Nested EVAL using PL_curpm (via $1 or friends)
1450 my $re;
1451 our $grabit = qr/ ([0-6][0-9]{7}) (??{ kt $1 }) [890] /x;
1452 $re = qr/^ ( (??{ $grabit }) ) $ /x;
1453 my @res = '0902862349' =~ $re;
1454 iseq join ("-", @res), "0902862349",
1455 'PL_curpm is set properly on nested eval';
1456
1457 our $qr = qr/ (o) (??{ $1 }) /x;
1458 ok 'boob'=~/( b (??{ $qr }) b )/x && 1, "PL_curpm, nested eval";
1459 }
1460
1461
1462 {
1463 use charnames ":full";
1464 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "I =~ Alphabetic";
1465 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Uppercase}/, "I =~ Uppercase";
1466 ok "\N{ROMAN NUMERAL ONE}" !~ /\p{Lowercase}/, "I !~ Lowercase";
1467 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "I =~ ID_Start";
1468 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "I =~ ID_Continue";
1469 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "i =~ Alphabetic";
1470 ok "\N{SMALL ROMAN NUMERAL ONE}" !~ /\p{Uppercase}/, "i !~ Uppercase";
0ab1ff8e
KW
1471 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Uppercase}/i, "i =~ Uppercase under /i";
1472 ok "\N{SMALL ROMAN NUMERAL ONE}" !~ /\p{Titlecase}/, "i !~ Titlecase";
1473 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Titlecase}/i, "i =~ Titlecase under /i";
1474 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Lowercase}/i, "I =~ Lowercase under
1475 /i";
e425a60b
YO
1476 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Lowercase}/, "i =~ Lowercase";
1477 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "i =~ ID_Start";
1478 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "i =~ ID_Continue"
1479 }
1480
0ab1ff8e
KW
1481 { # More checking that /i works on the few properties that it makes a
1482 # difference. Uppercase, Lowercase, and Titlecase were done in the
1483 # block above
1484 ok "A" =~ /\p{PosixUpper}/, "A =~ PosixUpper";
1485 ok "A" =~ /\p{PosixUpper}/i, "A =~ PosixUpper under /i";
1486 ok "A" !~ /\p{PosixLower}/, "A !~ PosixLower";
1487 ok "A" =~ /\p{PosixLower}/i, "A =~ PosixLower under /i";
1488 ok "a" !~ /\p{PosixUpper}/, "a !~ PosixUpper";
1489 ok "a" =~ /\p{PosixUpper}/i, "a =~ PosixUpper under /i";
1490 ok "a" =~ /\p{PosixLower}/, "a =~ PosixLower";
1491 ok "a" =~ /\p{PosixLower}/i, "a =~ PosixLower under /i";
1492
1493 ok "\xC0" =~ /\p{XPosixUpper}/, "\\xC0 =~ XPosixUpper";
1494 ok "\xC0" =~ /\p{XPosixUpper}/i, "\\xC0 =~ XPosixUpper under /i";
1495 ok "\xC0" !~ /\p{XPosixLower}/, "\\xC0 !~ XPosixLower";
1496 ok "\xC0" =~ /\p{XPosixLower}/i, "\\xC0 =~ XPosixLower under /i";
1497 ok "\xE0" !~ /\p{XPosixUpper}/, "\\xE0 !~ XPosixUpper";
1498 ok "\xE0" =~ /\p{XPosixUpper}/i, "\\xE0 =~ XPosixUpper under /i";
1499 ok "\xE0" =~ /\p{XPosixLower}/, "\\xE0 =~ XPosixLower";
1500 ok "\xE0" =~ /\p{XPosixLower}/i, "\\xE0 =~ XPosixLower under /i";
1501
1502 ok "\xC0" =~ /\p{UppercaseLetter}/, "\\xC0 =~ UppercaseLetter";
1503 ok "\xC0" =~ /\p{UppercaseLetter}/i, "\\xC0 =~ UppercaseLetter under /i";
1504 ok "\xC0" !~ /\p{LowercaseLetter}/, "\\xC0 !~ LowercaseLetter";
1505 ok "\xC0" =~ /\p{LowercaseLetter}/i, "\\xC0 =~ LowercaseLetter under /i";
1506 ok "\xC0" !~ /\p{TitlecaseLetter}/, "\\xC0 !~ TitlecaseLetter";
1507 ok "\xC0" =~ /\p{TitlecaseLetter}/i, "\\xC0 =~ TitlecaseLetter under /i";
1508 ok "\xE0" !~ /\p{UppercaseLetter}/, "\\xE0 !~ UppercaseLetter";
1509 ok "\xE0" =~ /\p{UppercaseLetter}/i, "\\xE0 =~ UppercaseLetter under /i";
1510 ok "\xE0" =~ /\p{LowercaseLetter}/, "\\xE0 =~ LowercaseLetter";
1511 ok "\xE0" =~ /\p{LowercaseLetter}/i, "\\xE0 =~ LowercaseLetter under /i";
1512 ok "\xE0" !~ /\p{TitlecaseLetter}/, "\\xE0 !~ TitlecaseLetter";
1513 ok "\xE0" =~ /\p{TitlecaseLetter}/i, "\\xE0 =~ TitlecaseLetter under /i";
1514 ok "\x{1C5}" !~ /\p{UppercaseLetter}/, "\\x{1C5} !~ UppercaseLetter";
1515 ok "\x{1C5}" =~ /\p{UppercaseLetter}/i, "\\x{1C5} =~ UppercaseLetter under /i";
1516 ok "\x{1C5}" !~ /\p{LowercaseLetter}/, "\\x{1C5} !~ LowercaseLetter";
1517 ok "\x{1C5}" =~ /\p{LowercaseLetter}/i, "\\x{1C5} =~ LowercaseLetter under /i";
1518 ok "\x{1C5}" =~ /\p{TitlecaseLetter}/, "\\x{1C5} =~ TitlecaseLetter";
1519 ok "\x{1C5}" =~ /\p{TitlecaseLetter}/i, "\\x{1C5} =~ TitlecaseLetter under /i";
1520 }
1521
e425a60b
YO
1522
1523 {
1524 # requirement of Unicode Technical Standard #18, 1.7 Code Points
1525 # cf. http://www.unicode.org/reports/tr18/#Supplementary_Characters
1526 for my $u (0x7FF, 0x800, 0xFFFF, 0x10000) {
1527 no warnings 'utf8'; # oops
1528 my $c = chr $u;
1529 my $x = sprintf '%04X', $u;
1530 ok "A${c}B" =~ /A[\0-\x{10000}]B/, "Unicode range - $x";
1531 }
1532 }
1533
1534
1535 {
1536 my $res="";
1537
1538 if ('1' =~ /(?|(?<digit>1)|(?<digit>2))/) {
1539 $res = "@{$- {digit}}";
1540 }
1541 iseq $res, "1",
1542 "Check that (?|...) doesnt cause dupe entries in the names array";
0f289c68 1543
e425a60b
YO
1544 $res = "";
1545 if ('11' =~ /(?|(?<digit>1)|(?<digit>2))(?&digit)/) {
1546 $res = "@{$- {digit}}";
1547 }
1548 iseq $res, "1", "Check that (?&..) to a buffer inside " .
1549 "a (?|...) goes to the leftmost";
1550 }
1551
1552
1553 {
1554 use warnings;
1555 local $Message = "ASCII pattern that really is UTF-8";
1556 my @w;
1557 local $SIG {__WARN__} = sub {push @w, "@_"};
0f289c68 1558 my $c = qq (\x{DF});
e425a60b
YO
1559 ok $c =~ /${c}|\x{100}/;
1560 ok @w == 0;
0f289c68 1561 }
e425a60b
YO
1562
1563
1564 {
1565 local $Message = "Corruption of match results of qr// across scopes";
1566 my $qr = qr/(fo+)(ba+r)/;
1567 'foobar' =~ /$qr/;
1568 iseq "$1$2", "foobar";
1569 {
1570 'foooooobaaaaar' =~ /$qr/;
0f289c68 1571 iseq "$1$2", 'foooooobaaaaar';
e425a60b
YO
1572 }
1573 iseq "$1$2", "foobar";
1574 }
1575
1576
1577 {
1578 local $Message = "HORIZWS";
1579 local $_ = "\t \r\n \n \t".chr(11)."\n";
1580 s/\H/H/g;
1581 s/\h/h/g;
1582 iseq $_, "hhHHhHhhHH";
1583 $_ = "\t \r\n \n \t" . chr (11) . "\n";
1584 utf8::upgrade ($_);
1585 s/\H/H/g;
1586 s/\h/h/g;
1587 iseq $_, "hhHHhHhhHH";
0f289c68 1588 }
e425a60b
YO
1589
1590
1591 {
1592 local $Message = "Various whitespace special patterns";
1593 my @h = map {chr $_} 0x09, 0x20, 0xa0, 0x1680, 0x180e, 0x2000,
1594 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006,
1595 0x2007, 0x2008, 0x2009, 0x200a, 0x202f, 0x205f,
1596 0x3000;
1597 my @v = map {chr $_} 0x0a, 0x0b, 0x0c, 0x0d, 0x85, 0x2028,
1598 0x2029;
1599 my @lb = ("\x0D\x0A", map {chr $_} 0x0A .. 0x0D, 0x85, 0x2028, 0x2029);
1600 foreach my $t ([\@h, qr/\h/, qr/\h+/],
1601 [\@v, qr/\v/, qr/\v+/],
1602 [\@lb, qr/\R/, qr/\R+/],) {
1603 my $ary = shift @$t;
1604 foreach my $pat (@$t) {
1605 foreach my $str (@$ary) {
1606 ok $str =~ /($pat)/, $pat;
1607 iseq $1, $str, $pat;
1608 utf8::upgrade ($str);
1609 ok $str =~ /($pat)/, "Upgraded string - $pat";
1610 iseq $1, $str, "Upgraded string - $pat";
1611 }
1612 }
1613 }
1614 }
1615
1616
1617 {
1618 local $Message = "Check that \\xDF match properly in its various forms";
1619 # Test that \xDF matches properly. this is pretty hacky stuff,
1620 # but its actually needed. The malarky with '-' is to prevent
1621 # compilation caching from playing any role in the test.
1622 my @df = (chr (0xDF), '-', chr (0xDF));
1623 utf8::upgrade ($df [2]);
1624 my @strs = ('ss', 'sS', 'Ss', 'SS', chr (0xDF));
1625 my @ss = map {("$_", "$_")} @strs;
1626 utf8::upgrade ($ss [$_ * 2 + 1]) for 0 .. $#strs;
1627
1628 for my $ssi (0 .. $#ss) {
1629 for my $dfi (0 .. $#df) {
1630 my $pat = $df [$dfi];
1631 my $str = $ss [$ssi];
1632 my $utf_df = ($dfi > 1) ? 'utf8' : '';
1633 my $utf_ss = ($ssi % 2) ? 'utf8' : '';
1634 (my $sstr = $str) =~ s/\xDF/\\xDF/;
1635
1636 if ($utf_df || $utf_ss || length ($ss [$ssi]) == 1) {
1637 my $ret = $str =~ /$pat/i;
1638 next if $pat eq '-';
1639 ok $ret, "\"$sstr\" =~ /\\xDF/i " .
1640 "(str is @{[$utf_ss||'latin']}, pat is " .
1641 "@{[$utf_df||'latin']})";
1642 }
1643 else {
1644 my $ret = $str !~ /$pat/i;
1645 next if $pat eq '-';
1646 ok $ret, "\"$sstr\" !~ /\\xDF/i " .
1647 "(str is @{[$utf_ss||'latin']}, pat is " .
1648 "@{[$utf_df||'latin']})";
1649 }
1650 }
1651 }
1652 }
1653
1654
1655 {
1656 local $Message = "BBC(Bleadperl Breaks CPAN) Today: String::Multibyte";
1657 my $re = qr/(?:[\x00-\xFF]{4})/;
1658 my $hyp = "\0\0\0-";
1659 my $esc = "\0\0\0\\";
1660
1661 my $str = "$esc$hyp$hyp$esc$esc";
1662 my @a = ($str =~ /\G(?:\Q$esc$esc\E|\Q$esc$hyp\E|$re)/g);
1663
1664 iseq @a,3;
1665 local $" = "=";
1666 iseq "@a","$esc$hyp=$hyp=$esc$esc";
1667 }
1668
1669
1670 {
1671 # Test for keys in %+ and %-
1672 local $Message = 'Test keys in %+ and %-';
1673 no warnings 'uninitialized';
1674 my $_ = "abcdef";
1675 /(?<foo>a)|(?<foo>b)/;
1676 iseq ((join ",", sort keys %+), "foo");
1677 iseq ((join ",", sort keys %-), "foo");
1678 iseq ((join ",", sort values %+), "a");
1679 iseq ((join ",", sort map "@$_", values %-), "a ");
1680 /(?<bar>a)(?<bar>b)(?<quux>.)/;
1681 iseq ((join ",", sort keys %+), "bar,quux");
1682 iseq ((join ",", sort keys %-), "bar,quux");
1683 iseq ((join ",", sort values %+), "a,c"); # leftmost
1684 iseq ((join ",", sort map "@$_", values %-), "a b,c");
1685 /(?<un>a)(?<deux>c)?/; # second buffer won't capture
1686 iseq ((join ",", sort keys %+), "un");
1687 iseq ((join ",", sort keys %-), "deux,un");
1688 iseq ((join ",", sort values %+), "a");
1689 iseq ((join ",", sort map "@$_", values %-), ",a");
1690 }
1691
1692
1693 {
1694 # length() on captures, the numbered ones end up in Perl_magic_len
1695 my $_ = "aoeu \xe6var ook";
1696 /^ \w+ \s (?<eek>\S+)/x;
1697
1698 iseq length ($`), 0, q[length $`];
1699 iseq length ($'), 4, q[length $'];
1700 iseq length ($&), 9, q[length $&];
1701 iseq length ($1), 4, q[length $1];
1702 iseq length ($+{eek}), 4, q[length $+{eek} == length $1];
1703 }
1704
1705
1706 {
1707 my $ok = -1;
1708
1709 $ok = exists ($-{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/;
1710 iseq $ok, 1, '$-{x} exists after "bar"=~/(?<x>foo)|bar/';
1711 iseq scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/';
1712 iseq scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/';
1713
1714 $ok = -1;
1715 $ok = exists ($+{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/;
1716 iseq $ok, 0, '$+{x} not exists after "bar"=~/(?<x>foo)|bar/';
1717 iseq scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/';
1718 iseq scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/';
1719
1720 $ok = -1;
1721 $ok = exists ($-{x}) ? 1 : 0 if 'foo' =~ /(?<x>foo)|bar/;
1722 iseq $ok, 1, '$-{x} exists after "foo"=~/(?<x>foo)|bar/';
1723 iseq scalar (%+), 1, 'scalar %+ == 1 after "foo"=~/(?<x>foo)|bar/';
1724 iseq scalar (%-), 1, 'scalar %- == 1 after "foo"=~/(?<x>foo)|bar/';
1725
1726 $ok = -1;
1727 $ok = exists ($+{x}) ? 1 : 0 if 'foo'=~/(?<x>foo)|bar/;
1728 iseq $ok, 1, '$+{x} exists after "foo"=~/(?<x>foo)|bar/';
1729 }
1730
1731
1732 {
1733 local $_;
1734 ($_ = 'abc') =~ /(abc)/g;
0f289c68 1735 $_ = '123';
e425a60b
YO
1736 iseq "$1", 'abc', "/g leads to unsafe match vars: $1";
1737 }
1738
1739
1740 {
1741 local $Message = 'Message-ID: <20070818091501.7eff4831@r2d2>';
1742 my $str = "";
1743 for (0 .. 5) {
1744 my @x;
1745 $str .= "@x"; # this should ALWAYS be the empty string
1746 'a' =~ /(a|)/;
1747 push @x, 1;
1748 }
1749 iseq length ($str), 0, "Trie scope error, string should be empty";
1750 $str = "";
1751 my @foo = ('a') x 5;
1752 for (@foo) {
1753 my @bar;
1754 $str .= "@bar";
1755 s/a|/push @bar, 1/e;
1756 }
1757 iseq length ($str), 0, "Trie scope error, string should be empty";
1758 }
1759
1760
1761 {
e425a60b 1762# more TRIE/AHOCORASICK problems with mixed utf8 / latin-1 and case folding
0f289c68
YO
1763 for my $chr (160 .. 255) {
1764 my $chr_byte = chr($chr);
1765 my $chr_utf8 = chr($chr); utf8::upgrade($chr_utf8);
1766 my $rx = qr{$chr_byte|X}i;
1767 ok($chr_utf8 =~ $rx, "utf8/latin, codepoint $chr");
1768 }
e425a60b
YO
1769 }
1770
1771 {
e425a60b
YO
1772 our $a = 3; "" =~ /(??{ $a })/;
1773 our $b = $a;
1774 iseq $b, $a, "Copy of scalar used for postponed subexpression";
1775 }
1776
1777
1778 {
e425a60b
YO
1779 our @ctl_n = ();
1780 our @plus = ();
1781 our $nested_tags;
1782 $nested_tags = qr{
1783 <
1784 (\w+)
1785 (?{
1786 push @ctl_n,$^N;
1787 push @plus,$+;
1788 })
1789 >
1790 (??{$nested_tags})*
1791 </\s* \w+ \s*>
1792 }x;
1793
1794 my $match = '<bla><blubb></blubb></bla>' =~ m/^$nested_tags$/;
1795 ok $match, 'nested construct matches';
1796 iseq "@ctl_n", "bla blubb", '$^N inside of (?{}) works as expected';
1797 iseq "@plus", "bla blubb", '$+ inside of (?{}) works as expected';
1798 }
1799
1800
e425a60b
YO
1801 SKIP: {
1802 # XXX: This set of tests is essentially broken, POSIX character classes
0f289c68 1803 # should not have differing definitions under Unicode.
e425a60b
YO
1804 # There are property names for that.
1805 skip "Tests assume ASCII", 4 unless $IS_ASCII;
1806
1807 my @notIsPunct = grep {/[[:punct:]]/ and not /\p{IsPunct}/}
1808 map {chr} 0x20 .. 0x7f;
1809 iseq join ('', @notIsPunct), '$+<=>^`|~',
93f09d7b 1810 '[:punct:] disagrees with IsPunct on Symbols';
e425a60b
YO
1811
1812 my @isPrint = grep {not /[[:print:]]/ and /\p{IsPrint}/}
1813 map {chr} 0 .. 0x1f, 0x7f .. 0x9f;
99870f4d
KW
1814 iseq join ('', @isPrint), "",
1815 'IsPrint agrees with [:print:] on control characters';
e425a60b
YO
1816
1817 my @isPunct = grep {/[[:punct:]]/ != /\p{IsPunct}/}
1818 map {chr} 0x80 .. 0xff;
0f289c68 1819 iseq join ('', @isPunct), "\xa1\xab\xb7\xbb\xbf", # ¡ « · » ¿
e425a60b
YO
1820 'IsPunct disagrees with [:punct:] outside ASCII';
1821
1822 my @isPunctLatin1 = eval q {
1823 use encoding 'latin1';
1824 grep {/[[:punct:]]/ != /\p{IsPunct}/} map {chr} 0x80 .. 0xff;
1825 };
1826 skip "Eval failed ($@)", 1 if $@;
1827 skip "PERL_LEGACY_UNICODE_CHARCLASS_MAPPINGS set to 0", 1
1828 if !$ENV{PERL_TEST_LEGACY_POSIX_CC};
0f289c68 1829 iseq join ('', @isPunctLatin1), '',
e425a60b 1830 'IsPunct agrees with [:punct:] with explicit Latin1';
0f289c68 1831 }
d1c771f5
B
1832
1833
1834 {
1835 # Tests for [#perl 71942]
1836 our $count_a;
1837 our $count_b;
1838
1839 my $c = 0;
1840 for my $re (
1841# [
1842# should match?,
1843# input string,
1844# re 1,
1845# re 2,
1846# expected values of count_a and count_b,
1847# ]
1848 [
1849 0,
1850 "xababz",
1851 qr/a+(?{$count_a++})b?(*COMMIT)(*FAIL)/,
1852 qr/a+(?{$count_b++})b?(*COMMIT)z/,
1853 1,
1854 ],
1855 [
1856 0,
1857 "xababz",
1858 qr/a+(?{$count_a++})b?(*COMMIT)\s*(*FAIL)/,
1859 qr/a+(?{$count_b++})b?(*COMMIT)\s*z/,
1860 1,
1861 ],
1862 [
1863 0,
1864 "xababz",
1865 qr/a+(?{$count_a++})(?:b|)?(*COMMIT)(*FAIL)/,
1866 qr/a+(?{$count_b++})(?:b|)?(*COMMIT)z/,
1867 1,
1868 ],
1869 [
1870 0,
1871 "xababz",
1872 qr/a+(?{$count_a++})b{0,6}(*COMMIT)(*FAIL)/,
1873 qr/a+(?{$count_b++})b{0,6}(*COMMIT)z/,
1874 1,
1875 ],
1876 [
1877 0,
1878 "xabcabcz",
1879 qr/a+(?{$count_a++})(bc){0,6}(*COMMIT)(*FAIL)/,
1880 qr/a+(?{$count_b++})(bc){0,6}(*COMMIT)z/,
1881 1,
1882 ],
1883 [
1884 0,
1885 "xabcabcz",
1886 qr/a+(?{$count_a++})(bc*){0,6}(*COMMIT)(*FAIL)/,
1887 qr/a+(?{$count_b++})(bc*){0,6}(*COMMIT)z/,
1888 1,
1889 ],
1890
1891
1892 [
1893 0,
1894 "aaaabtz",
1895 qr/a+(?{$count_a++})b?(*PRUNE)(*FAIL)/,
1896 qr/a+(?{$count_b++})b?(*PRUNE)z/,
1897 4,
1898 ],
1899 [
1900 0,
1901 "aaaabtz",
1902 qr/a+(?{$count_a++})b?(*PRUNE)\s*(*FAIL)/,
1903 qr/a+(?{$count_b++})b?(*PRUNE)\s*z/,
1904 4,
1905 ],
1906 [
1907 0,
1908 "aaaabtz",
1909 qr/a+(?{$count_a++})(?:b|)(*PRUNE)(*FAIL)/,
1910 qr/a+(?{$count_b++})(?:b|)(*PRUNE)z/,
1911 4,
1912 ],
1913 [
1914 0,
1915 "aaaabtz",
1916 qr/a+(?{$count_a++})b{0,6}(*PRUNE)(*FAIL)/,
1917 qr/a+(?{$count_b++})b{0,6}(*PRUNE)z/,
1918 4,
1919 ],
1920 [
1921 0,
1922 "aaaabctz",
1923 qr/a+(?{$count_a++})(bc){0,6}(*PRUNE)(*FAIL)/,
1924 qr/a+(?{$count_b++})(bc){0,6}(*PRUNE)z/,
1925 4,
1926 ],
1927 [
1928 0,
1929 "aaaabctz",
1930 qr/a+(?{$count_a++})(bc*){0,6}(*PRUNE)(*FAIL)/,
1931 qr/a+(?{$count_b++})(bc*){0,6}(*PRUNE)z/,
1932 4,
1933 ],
1934
1935 [
1936 0,
1937 "aaabaaab",
1938 qr/a+(?{$count_a++;})b?(*SKIP)(*FAIL)/,
1939 qr/a+(?{$count_b++;})b?(*SKIP)z/,
1940 2,
1941 ],
1942 [
1943 0,
1944 "aaabaaab",
1945 qr/a+(?{$count_a++;})b?(*SKIP)\s*(*FAIL)/,
1946 qr/a+(?{$count_b++;})b?(*SKIP)\s*z/,
1947 2,
1948 ],
1949 [
1950 0,
1951 "aaabaaab",
1952 qr/a+(?{$count_a++;})(?:b|)(*SKIP)(*FAIL)/,
1953 qr/a+(?{$count_b++;})(?:b|)(*SKIP)z/,
1954 2,
1955 ],
1956 [
1957 0,
1958 "aaabaaab",
1959 qr/a+(?{$count_a++;})b{0,6}(*SKIP)(*FAIL)/,
1960 qr/a+(?{$count_b++;})b{0,6}(*SKIP)z/,
1961 2,
1962 ],
1963 [
1964 0,
1965 "aaabcaaabc",
1966 qr/a+(?{$count_a++;})(bc){0,6}(*SKIP)(*FAIL)/,
1967 qr/a+(?{$count_b++;})(bc){0,6}(*SKIP)z/,
1968 2,
1969 ],
1970 [
1971 0,
1972 "aaabcaaabc",
1973 qr/a+(?{$count_a++;})(bc*){0,6}(*SKIP)(*FAIL)/,
1974 qr/a+(?{$count_b++;})(bc*){0,6}(*SKIP)z/,
1975 2,
1976 ],
1977
1978
1979 [
1980 0,
1981 "aaddbdaabyzc",
1982 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) (*FAIL) \s* c \1 /x,
1983 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) z \s* c \1 /x,
1984 4,
1985 ],
1986 [
1987 0,
1988 "aaddbdaabyzc",
1989 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) \s* (*FAIL) \s* c \1 /x,
1990 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) \s* z \s* c \1 /x,
1991 4,
1992 ],
1993 [
1994 0,
1995 "aaddbdaabyzc",
1996 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? (?:b|) (*SKIP:T1) (*FAIL) \s* c \1 /x,
1997 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? (?:b|) (*SKIP:T1) z \s* c \1 /x,
1998 4,
1999 ],
2000 [
2001 0,
2002 "aaddbdaabyzc",
2003 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? b{0,6} (*SKIP:T1) (*FAIL) \s* c \1 /x,
2004 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? b{0,6} (*SKIP:T1) z \s* c \1 /x,
2005 4,
2006 ],
2007 [
2008 0,
2009 "aaddbcdaabcyzc",
2010 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? (bc){0,6} (*SKIP:T1) (*FAIL) \s* c \1 /x,
2011 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? (bc){0,6} (*SKIP:T1) z \s* c \1 /x,
2012 4,
2013 ],
2014 [
2015 0,
2016 "aaddbcdaabcyzc",
2017 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? (bc*){0,6} (*SKIP:T1) (*FAIL) \s* c \1 /x,
2018 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? (bc*){0,6} (*SKIP:T1) z \s* c \1 /x,
2019 4,
2020 ],
2021
2022
2023 [
2024 0,
2025 "aaaaddbdaabyzc",
2026 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2027 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2028 2,
2029 ],
2030 [
2031 0,
2032 "aaaaddbdaabyzc",
2033 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) \s* (*FAIL) \s* c \1 /x,
2034 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) \s* z \s* c \1 /x,
2035 2,
2036 ],
2037 [
2038 0,
2039 "aaaaddbdaabyzc",
2040 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? (?:b|) (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2041 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? (?:b|) (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2042 2,
2043 ],
2044 [
2045 0,
2046 "aaaaddbdaabyzc",
2047 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? b{0,6} (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2048 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? b{0,6} (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2049 2,
2050 ],
2051 [
2052 0,
2053 "aaaaddbcdaabcyzc",
2054 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? (bc){0,6} (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2055 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? (bc){0,6} (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2056 2,
2057 ],
2058 [
2059 0,
2060 "aaaaddbcdaabcyzc",
2061 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? (bc*){0,6} (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2062 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? (bc*){0,6} (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2063 2,
2064 ],
2065
2066
2067 [
2068 0,
2069 "AbcdCBefgBhiBqz",
2070 qr/(A (.*) (?{ $count_a++ }) C? (*THEN) | A D) (*FAIL)/x,
2071 qr/(A (.*) (?{ $count_b++ }) C? (*THEN) | A D) z/x,
2072 1,
2073 ],
2074 [
2075 0,
2076 "AbcdCBefgBhiBqz",
2077 qr/(A (.*) (?{ $count_a++ }) C? (*THEN) | A D) \s* (*FAIL)/x,
2078 qr/(A (.*) (?{ $count_b++ }) C? (*THEN) | A D) \s* z/x,
2079 1,
2080 ],
2081 [
2082 0,
2083 "AbcdCBefgBhiBqz",
2084 qr/(A (.*) (?{ $count_a++ }) (?:C|) (*THEN) | A D) (*FAIL)/x,
2085 qr/(A (.*) (?{ $count_b++ }) (?:C|) (*THEN) | A D) z/x,
2086 1,
2087 ],
2088 [
2089 0,
2090 "AbcdCBefgBhiBqz",
2091 qr/(A (.*) (?{ $count_a++ }) C{0,6} (*THEN) | A D) (*FAIL)/x,
2092 qr/(A (.*) (?{ $count_b++ }) C{0,6} (*THEN) | A D) z/x,
2093 1,
2094 ],
2095 [
2096 0,
2097 "AbcdCEBefgBhiBqz",
2098 qr/(A (.*) (?{ $count_a++ }) (CE){0,6} (*THEN) | A D) (*FAIL)/x,
2099 qr/(A (.*) (?{ $count_b++ }) (CE){0,6} (*THEN) | A D) z/x,
2100 1,
2101 ],
2102 [
2103 0,
2104 "AbcdCBefgBhiBqz",
2105 qr/(A (.*) (?{ $count_a++ }) (CE*){0,6} (*THEN) | A D) (*FAIL)/x,
2106 qr/(A (.*) (?{ $count_b++ }) (CE*){0,6} (*THEN) | A D) z/x,
2107 1,
2108 ],
2109 ) {
2110 $c++;
2111 $count_a = 0;
2112 $count_b = 0;
2113
2114 my $match_a = ($re->[1] =~ $re->[2]) || 0;
2115 my $match_b = ($re->[1] =~ $re->[3]) || 0;
2116
2117 iseq($match_a, $re->[0], "match a " . ($re->[0] ? "succeeded" : "failed") . " ($c)");
2118 iseq($match_b, $re->[0], "match b " . ($re->[0] ? "succeeded" : "failed") . " ($c)");
2119 iseq($count_a, $re->[4], "count a ($c)");
2120 iseq($count_b, $re->[4], "count b ($c)");
2121 }
2122 }
e425a60b 2123
b57e4118
KW
2124 { # Bleadperl v5.13.8-292-gf56b639 breaks NEZUMI/Unicode-LineBreak-1.011
2125 # \xdf in lookbehind failed to compile as is multi-char fold
2126 eval_ok 'qr{
2127 (?u: (?<=^url:) |
2128 (?<=[/]) (?=[^/]) |
2129 (?<=[^-.]) (?=[-~.,_?\#%=&]) |
2130 (?<=[=&]) (?=.)
2131 )}iox', "Lookbehind with \\xdf matchable compiles";
2132 }
2133
e425a60b
YO
2134 #
2135 # Keep the following tests last -- they may crash perl
2136 #
2137 print "# Tests that follow may crash perl\n";
e425a60b
YO
2138 {
2139 eval '/\k/';
2140 ok $@ =~ /\QSequence \k... not terminated in regex;\E/,
2141 'Lone \k not allowed';
2142 }
2143
e425a60b
YO
2144 {
2145 local $Message = "Substitution with lookahead (possible segv)";
2146 $_ = "ns1ns1ns1";
2147 s/ns(?=\d)/ns_/g;
2148 iseq $_, "ns_1ns_1ns_1";
2149 $_ = "ns1";
2150 s/ns(?=\d)/ns_/;
2151 iseq $_, "ns_1";
2152 $_ = "123";
2153 s/(?=\d+)|(?<=\d)/!Bang!/g;
2154 iseq $_, "!Bang!1!Bang!2!Bang!3!Bang!";
2155 }
2156
6182169b
KW
2157 {
2158 # Earlier versions of Perl said this was fatal.
2159 local $Message = "U+0FFFF shouldn't crash the regex engine";
2160 no warnings 'utf8';
2161 my $a = eval "chr(65535)";
2162 use warnings;
2163 my $warning_message;
2164 local $SIG{__WARN__} = sub { $warning_message = $_[0] };
2165 eval $a =~ /[a-z]/;
2166 ok(1); # If it didn't crash, it worked.
2167 }
b57e4118
KW
2168
2169 # !!! NOTE that tests that aren't at all likely to crash perl should go
2170 # a ways above, above these last ones.
e425a60b
YO
2171} # End of sub run_tests
2172
21731;