This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
new perldelta
[perl5.git] / t / re / pat_advanced.t
CommitLineData
e425a60b
YO
1#!./perl
2#
c5de0829 3# This is a home for regular expression tests that do not fit into
e425a60b
YO
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
3fe9640a
JH
7BEGIN {
8 chdir 't' if -d 't';
3fe9640a 9 require './test.pl';
624c42e2 10 set_up_inc(qw '../lib .');
8c892c9b 11 require './charset_tools.pl';
624c42e2 12 skip_all_if_miniperl("miniperl can't load Tie::Hash::NamedCapture, need for %+ and %-");
5b39eca1 13}
3fe9640a 14
e425a60b
YO
15use strict;
16use warnings;
17use 5.010;
fee50582 18our ($REGMARK, $REGERROR);
e425a60b 19
e425a60b
YO
20sub run_tests;
21
22$| = 1;
23
9d45b377 24run_tests() unless caller;
e425a60b
YO
25
26#
27# Tests start here.
28#
29sub run_tests {
30
e425a60b 31 {
e425a60b
YO
32 # Japhy -- added 03/03/2001
33 () = (my $str = "abc") =~ /(...)/;
34 $str = "def";
de26e0cc 35 is($1, "abc", 'Changing subject does not modify $1');
e425a60b
YO
36 }
37
e425a60b
YO
38 SKIP:
39 {
40 # The trick is that in EBCDIC the explicit numeric range should
41 # match (as also in non-EBCDIC) but the explicit alphabetic range
42 # should not match.
b7ad6c3e
KW
43 like "\x8e", qr/[\x89-\x91]/, '"\x8e" =~ /[\x89-\x91]/';
44 like "\xce", qr/[\xc9-\xd1]/, '"\xce" =~ /[\xc9-\xd1]/';
45 like "\xd0", qr/[\xc9-\xd1]/, '"\xd0" =~ /[\xc9-\xd1]/';
e425a60b
YO
46
47 skip "Not an EBCDIC platform", 2 unless ord ('i') == 0x89 &&
48 ord ('J') == 0xd1;
49
50 # In most places these tests would succeed since \x8e does not
51 # in most character sets match 'i' or 'j' nor would \xce match
52 # 'I' or 'J', but strictly speaking these tests are here for
53 # the good of EBCDIC, so let's test these only there.
b33825c4
NC
54 unlike("\x8e", qr/[i-j]/, '"\x8e" !~ /[i-j]/');
55 unlike("\xce", qr/[I-J]/, '"\xce" !~ /[I-J]/');
2ca8589c 56 unlike("\xd0", qr/[I-J]/, '"\xd0" !~ /[I-J]/');
e425a60b
YO
57 }
58
e425a60b 59 {
b7ad6c3e
KW
60 like "\x{ab}", qr/\x{ab}/, '"\x{ab}" =~ /\x{ab}/ ';
61 like "\x{abcd}", qr/\x{abcd}/, '"\x{abcd}" =~ /\x{abcd}/';
e425a60b
YO
62 }
63
e425a60b 64 {
ee95e30c 65 my $message = 'bug id 20001008.001 (#4407)';
e425a60b 66
f36cc39d
KW
67 my $strasse = "stra" . uni_to_native("\337") . "e";
68 my @x = ("$strasse 138", "$strasse 138");
e425a60b 69 for (@x) {
de946258
NC
70 ok(s/(\d+)\s*([\w\-]+)/$1 . uc $2/e, $message);
71 ok(my ($latin) = /^(.+)(?:\s+\d)/, $message);
f36cc39d
KW
72 is($latin, $strasse, $message);
73 ok($latin =~ s/$strasse/straße/, $message);
e425a60b
YO
74 #
75 # Previous code follows, but outcommented - there were no tests.
76 #
77 # $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
78 # use utf8; # needed for the raw UTF-8
79 # $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
80 }
81 }
82
e425a60b 83 {
de946258
NC
84 my $message = 'Test \x escapes';
85 ok("ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4", $message);
86 ok("ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}", $message);
87 ok("ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}", $message);
88 ok("ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4", $message);
89 ok("ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4", $message);
90 ok("ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}", $message);
91 ok("ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}", $message);
92 ok("ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4", $message);
e425a60b
YO
93 }
94
e425a60b 95 {
de946258 96 my $message = 'Match code points > 255';
e425a60b 97 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
de946258
NC
98 ok(/(.\x{300})./, $message);
99 ok($` eq "abc\x{100}" && length ($`) == 4, $message);
100 ok($& eq "\x{200}\x{300}\x{380}" && length ($&) == 3, $message);
101 ok($' eq "\x{400}defg" && length ($') == 5, $message);
102 ok($1 eq "\x{200}\x{300}" && length ($1) == 2, $message);
e425a60b
YO
103 }
104
e425a60b
YO
105 {
106 my $x = "\x{10FFFD}";
107 $x =~ s/(.)/$1/g;
108 ok ord($x) == 0x10FFFD && length($x) == 1, "From Robin Houston";
109 }
110
e425a60b
YO
111 {
112 my %d = (
113 "7f" => [0, 0, 0],
114 "80" => [1, 1, 0],
115 "ff" => [1, 1, 0],
116 "100" => [0, 1, 1],
117 );
a2d248f9 118
e425a60b 119 while (my ($code, $match) = each %d) {
de946258 120 my $message = "Properties of \\x$code";
e425a60b 121 my $char = eval qq ["\\x{$code}"];
a2d248f9 122
de946258
NC
123 is(0 + ($char =~ /[\x80-\xff]/), $$match[0], $message);
124 is(0 + ($char =~ /[\x80-\x{100}]/), $$match[1], $message);
125 is(0 + ($char =~ /[\x{100}]/), $$match[2], $message);
e425a60b
YO
126 }
127 }
128
e425a60b
YO
129 {
130 # From Japhy
e4e5d8ba 131 foreach (qw(c g o)) {
4d18b353
NC
132 warning_like(sub {'' =~ "(?$_)"}, qr/^Useless \(\?$_\)/);
133 warning_like(sub {'' =~ "(?-$_)"}, qr/^Useless \(\?-$_\)/);
e4e5d8ba 134 }
e425a60b
YO
135
136 # Now test multi-error regexes
f4554ed5
NC
137 foreach (['(?g-o)', qr/^Useless \(\?g\)/, qr/^Useless \(\?-o\)/],
138 ['(?g-c)', qr/^Useless \(\?g\)/, qr/^Useless \(\?-c\)/],
139 # (?c) means (?g) error won't be thrown
140 ['(?o-cg)', qr/^Useless \(\?o\)/, qr/^Useless \(\?-c\)/],
141 ['(?ogc)', qr/^Useless \(\?o\)/, qr/^Useless \(\?g\)/,
142 qr/^Useless \(\?c\)/],
143 ) {
144 my ($re, @warnings) = @$_;
145 warnings_like(sub {eval "qr/$re/"}, \@warnings, "qr/$re/ warns");
146 }
e425a60b
YO
147 }
148
e425a60b 149 {
de946258 150 my $message = "/x tests";
e425a60b 151 $_ = "foo";
14358a41 152 foreach my $pat (<<" --", <<" --") {
e425a60b
YO
153 /f
154 o\r
155 o
156 \$
157 /x
158 --
e425a60b
YO
159 /f
160 o
161 o
162 \$\r
163 /x
164 --
14358a41
NC
165 is(eval $pat, 1, $message);
166 is($@, '', $message);
167 }
e425a60b
YO
168 }
169
e425a60b 170 {
de946258 171 my $message = "/o feature";
e425a60b 172 sub test_o {$_ [0] =~ /$_[1]/o; return $1}
de946258
NC
173 is(test_o ('abc', '(.)..'), 'a', $message);
174 is(test_o ('abc', '..(.)'), 'a', $message);
e425a60b
YO
175 }
176
e425a60b
YO
177 {
178 # Test basic $^N usage outside of a regex
de946258 179 my $message = '$^N usage outside of a regex';
e425a60b 180 my $x = "abcdef";
de946258
NC
181 ok(($x =~ /cde/ and !defined $^N), $message);
182 ok(($x =~ /(cde)/ and $^N eq "cde"), $message);
183 ok(($x =~ /(c)(d)(e)/ and $^N eq "e"), $message);
184 ok(($x =~ /(c(d)e)/ and $^N eq "cde"), $message);
185 ok(($x =~ /(foo)|(c(d)e)/ and $^N eq "cde"), $message);
186 ok(($x =~ /(c(d)e)|(foo)/ and $^N eq "cde"), $message);
187 ok(($x =~ /(c(d)e)|(abc)/ and $^N eq "abc"), $message);
188 ok(($x =~ /(c(d)e)|(abc)x/ and $^N eq "cde"), $message);
189 ok(($x =~ /(c(d)e)(abc)?/ and $^N eq "cde"), $message);
190 ok(($x =~ /(?:c(d)e)/ and $^N eq "d"), $message);
191 ok(($x =~ /(?:c(d)e)(?:f)/ and $^N eq "d"), $message);
192 ok(($x =~ /(?:([abc])|([def]))*/ and $^N eq "f"), $message);
193 ok(($x =~ /(?:([ace])|([bdf]))*/ and $^N eq "f"), $message);
194 ok(($x =~ /(([ace])|([bd]))*/ and $^N eq "e"), $message);
195 {ok(($x =~ /(([ace])|([bdf]))*/ and $^N eq "f"), $message);}
e425a60b
YO
196 ## Test to see if $^N is automatically localized -- it should now
197 ## have the value set in the previous test.
de26e0cc 198 is($^N, "e", '$^N is automatically localized');
e425a60b
YO
199
200 # Now test inside (?{ ... })
de946258 201 $message = '$^N usage inside (?{ ... })';
e425a60b 202 our ($y, $z);
de946258
NC
203 ok(($x =~ /a([abc])(?{$y=$^N})c/ and $y eq "b"), $message);
204 ok(($x =~ /a([abc]+)(?{$y=$^N})d/ and $y eq "bc"), $message);
205 ok(($x =~ /a([abcdefg]+)(?{$y=$^N})d/ and $y eq "bc"), $message);
206 ok(($x =~ /(a([abcdefg]+)(?{$y=$^N})d)(?{$z=$^N})e/ and $y eq "bc"
207 and $z eq "abcd"), $message);
208 ok(($x =~ /(a([abcdefg]+)(?{$y=$^N})de)(?{$z=$^N})/ and $y eq "bc"
209 and $z eq "abcde"), $message);
e425a60b
YO
210
211 }
212
e425a60b
YO
213 SKIP:
214 {
215 ## Should probably put in tests for all the POSIX stuff,
216 ## but not sure how to guarantee a specific locale......
217
de946258 218 my $message = 'Test [[:cntrl:]]';
e425a60b
YO
219 my $AllBytes = join "" => map {chr} 0 .. 255;
220 (my $x = $AllBytes) =~ s/[[:cntrl:]]//g;
628d95af
KW
221 $x = join "", sort { $a cmp $b }
222 map { chr utf8::native_to_unicode(ord $_) } split "", $x;
de946258 223 is($x, join("", map {chr} 0x20 .. 0x7E, 0x80 .. 0xFF), $message);
e425a60b
YO
224
225 ($x = $AllBytes) =~ s/[^[:cntrl:]]//g;
628d95af
KW
226 $x = join "", sort { $a cmp $b }
227 map { chr utf8::native_to_unicode(ord $_) } split "", $x;
de946258 228 is($x, (join "", map {chr} 0x00 .. 0x1F, 0x7F), $message);
e425a60b
YO
229 }
230
e425a60b
YO
231 {
232 # With /s modifier UTF8 chars were interpreted as bytes
de946258 233 my $message = "UTF-8 chars aren't bytes";
e425a60b
YO
234 my $a = "Hello \x{263A} World";
235 my @a = ($a =~ /./gs);
de946258 236 is($#a, 12, $message);
e425a60b
YO
237 }
238
e425a60b 239 {
e425a60b
YO
240 no warnings 'digit';
241 # Check that \x## works. 5.6.1 and 5.005_03 fail some of these.
242 my $x;
243 $x = "\x4e" . "E";
b7ad6c3e 244 like ($x, qr/^\x4EE$/, "Check only 2 bytes of hex are matched.");
e425a60b
YO
245
246 $x = "\x4e" . "i";
b7ad6c3e 247 like ($x, qr/^\x4Ei$/, "Check that invalid hex digit stops it (2)");
e425a60b
YO
248
249 $x = "\x4" . "j";
b7ad6c3e 250 like ($x, qr/^\x4j$/, "Check that invalid hex digit stops it (1)");
e425a60b
YO
251
252 $x = "\x0" . "k";
b7ad6c3e 253 like ($x, qr/^\xk$/, "Check that invalid hex digit stops it (0)");
e425a60b
YO
254
255 $x = "\x0" . "x";
b7ad6c3e 256 like ($x, qr/^\xx$/, "\\xx isn't to be treated as \\0");
e425a60b
YO
257
258 $x = "\x0" . "xa";
b7ad6c3e 259 like ($x, qr/^\xxa$/, "\\xxa isn't to be treated as \\xa");
e425a60b
YO
260
261 $x = "\x9" . "_b";
b7ad6c3e 262 like ($x, qr/^\x9_b$/, "\\x9_b isn't to be treated as \\x9b");
e425a60b
YO
263
264 # and now again in [] ranges
265
266 $x = "\x4e" . "E";
b7ad6c3e 267 like ($x, qr/^[\x4EE]{2}$/, "Check only 2 bytes of hex are matched.");
e425a60b
YO
268
269 $x = "\x4e" . "i";
b7ad6c3e 270 like ($x, qr/^[\x4Ei]{2}$/, "Check that invalid hex digit stops it (2)");
e425a60b
YO
271
272 $x = "\x4" . "j";
b7ad6c3e 273 like ($x, qr/^[\x4j]{2}$/, "Check that invalid hex digit stops it (1)");
e425a60b
YO
274
275 $x = "\x0" . "k";
b7ad6c3e 276 like ($x, qr/^[\xk]{2}$/, "Check that invalid hex digit stops it (0)");
e425a60b
YO
277
278 $x = "\x0" . "x";
b7ad6c3e 279 like ($x, qr/^[\xx]{2}$/, "\\xx isn't to be treated as \\0");
e425a60b
YO
280
281 $x = "\x0" . "xa";
b7ad6c3e 282 like ($x, qr/^[\xxa]{3}$/, "\\xxa isn't to be treated as \\xa");
e425a60b
YO
283
284 $x = "\x9" . "_b";
b7ad6c3e 285 like ($x, qr/^[\x9_b]{3}$/, "\\x9_b isn't to be treated as \\x9b");
e425a60b
YO
286
287 # Check that \x{##} works. 5.6.1 fails quite a few of these.
288
289 $x = "\x9b";
b7ad6c3e 290 like ($x, qr/^\x{9_b}$/, "\\x{9_b} is to be treated as \\x9b");
e425a60b
YO
291
292 $x = "\x9b" . "y";
b7ad6c3e 293 like ($x, qr/^\x{9_b}y$/, "\\x{9_b} is to be treated as \\x9b (again)");
e425a60b
YO
294
295 $x = "\x9b" . "y";
b7ad6c3e 296 like ($x, qr/^\x{9b_}y$/, "\\x{9b_} is to be treated as \\x9b");
e425a60b
YO
297
298 $x = "\x9b" . "y";
b7ad6c3e 299 like ($x, qr/^\x{9_bq}y$/, "\\x{9_bc} is to be treated as \\x9b");
e425a60b
YO
300
301 $x = "\x0" . "y";
b7ad6c3e 302 like ($x, qr/^\x{x9b}y$/, "\\x{x9b} is to be treated as \\x0");
e425a60b
YO
303
304 $x = "\x0" . "y";
b7ad6c3e 305 like ($x, qr/^\x{0x9b}y$/, "\\x{0x9b} is to be treated as \\x0");
e425a60b
YO
306
307 $x = "\x9b" . "y";
b7ad6c3e 308 like ($x, qr/^\x{09b}y$/, "\\x{09b} is to be treated as \\x9b");
e425a60b
YO
309
310 $x = "\x9b";
b7ad6c3e 311 like ($x, qr/^[\x{9_b}]$/, "\\x{9_b} is to be treated as \\x9b");
e425a60b
YO
312
313 $x = "\x9b" . "y";
b7ad6c3e 314 like ($x, qr/^[\x{9_b}y]{2}$/,
e425a60b
YO
315 "\\x{9_b} is to be treated as \\x9b (again)");
316
317 $x = "\x9b" . "y";
b7ad6c3e 318 like ($x, qr/^[\x{9b_}y]{2}$/, "\\x{9b_} is to be treated as \\x9b");
e425a60b
YO
319
320 $x = "\x9b" . "y";
b7ad6c3e 321 like ($x, qr/^[\x{9_bq}y]{2}$/, "\\x{9_bc} is to be treated as \\x9b");
e425a60b
YO
322
323 $x = "\x0" . "y";
b7ad6c3e 324 like ($x, qr/^[\x{x9b}y]{2}$/, "\\x{x9b} is to be treated as \\x0");
e425a60b
YO
325
326 $x = "\x0" . "y";
b7ad6c3e 327 like ($x, qr/^[\x{0x9b}y]{2}$/, "\\x{0x9b} is to be treated as \\x0");
e425a60b
YO
328
329 $x = "\x9b" . "y";
b7ad6c3e 330 like ($x, qr/^[\x{09b}y]{2}$/, "\\x{09b} is to be treated as \\x9b");
e425a60b
YO
331
332 }
333
e425a60b
YO
334 {
335 # High bit bug -- japhy
336 my $x = "ab\200d";
b7ad6c3e 337 like $x, qr/.*?\200/, "High bit fine";
e425a60b
YO
338 }
339
e425a60b
YO
340 {
341 # The basic character classes and Unicode
b7ad6c3e
KW
342 like "\x{0100}", qr/\w/, 'LATIN CAPITAL LETTER A WITH MACRON in /\w/';
343 like "\x{0660}", qr/\d/, 'ARABIC-INDIC DIGIT ZERO in /\d/';
344 like "\x{1680}", qr/\s/, 'OGHAM SPACE MARK in /\s/';
e425a60b
YO
345 }
346
e425a60b 347 {
de946258
NC
348 my $message = "Folding matches and Unicode";
349 like("a\x{100}", qr/A/i, $message);
350 like("A\x{100}", qr/a/i, $message);
351 like("a\x{100}", qr/a/i, $message);
352 like("A\x{100}", qr/A/i, $message);
353 like("\x{101}a", qr/\x{100}/i, $message);
354 like("\x{100}a", qr/\x{100}/i, $message);
355 like("\x{101}a", qr/\x{101}/i, $message);
356 like("\x{100}a", qr/\x{101}/i, $message);
357 like("a\x{100}", qr/A\x{100}/i, $message);
358 like("A\x{100}", qr/a\x{100}/i, $message);
359 like("a\x{100}", qr/a\x{100}/i, $message);
360 like("A\x{100}", qr/A\x{100}/i, $message);
361 like("a\x{100}", qr/[A]/i, $message);
362 like("A\x{100}", qr/[a]/i, $message);
363 like("a\x{100}", qr/[a]/i, $message);
364 like("A\x{100}", qr/[A]/i, $message);
365 like("\x{101}a", qr/[\x{100}]/i, $message);
366 like("\x{100}a", qr/[\x{100}]/i, $message);
367 like("\x{101}a", qr/[\x{101}]/i, $message);
368 like("\x{100}a", qr/[\x{101}]/i, $message);
e425a60b
YO
369 }
370
e425a60b
YO
371 {
372 use charnames ':full';
de946258 373 my $message = "Folding 'LATIN LETTER A WITH GRAVE'";
e425a60b
YO
374
375 my $lower = "\N{LATIN SMALL LETTER A WITH GRAVE}";
376 my $UPPER = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";
0f289c68 377
de946258
NC
378 like($lower, qr/$UPPER/i, $message);
379 like($UPPER, qr/$lower/i, $message);
380 like($lower, qr/[$UPPER]/i, $message);
381 like($UPPER, qr/[$lower]/i, $message);
e425a60b 382
de946258 383 $message = "Folding 'GREEK LETTER ALPHA WITH VRACHY'";
e425a60b
YO
384
385 $lower = "\N{GREEK CAPITAL LETTER ALPHA WITH VRACHY}";
386 $UPPER = "\N{GREEK SMALL LETTER ALPHA WITH VRACHY}";
387
de946258
NC
388 like($lower, qr/$UPPER/i, $message);
389 like($UPPER, qr/$lower/i, $message);
390 like($lower, qr/[$UPPER]/i, $message);
391 like($UPPER, qr/[$lower]/i, $message);
e425a60b 392
de946258 393 $message = "Folding 'LATIN LETTER Y WITH DIAERESIS'";
e425a60b
YO
394
395 $lower = "\N{LATIN SMALL LETTER Y WITH DIAERESIS}";
396 $UPPER = "\N{LATIN CAPITAL LETTER Y WITH DIAERESIS}";
397
de946258
NC
398 like($lower, qr/$UPPER/i, $message);
399 like($UPPER, qr/$lower/i, $message);
400 like($lower, qr/[$UPPER]/i, $message);
401 like($UPPER, qr/[$lower]/i, $message);
e425a60b
YO
402 }
403
e425a60b
YO
404 {
405 use charnames ':full';
de946258 406 my $message = "GREEK CAPITAL LETTER SIGMA vs " .
e425a60b
YO
407 "COMBINING GREEK PERISPOMENI";
408
409 my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}";
410 my $char = "\N{COMBINING GREEK PERISPOMENI}";
411
c11a8df3
NC
412 warning_is(sub {unlike("_:$char:_", qr/_:$SIGMA:_/i, $message)}, undef,
413 'Did not warn [change a5961de5f4215b5c]');
e425a60b
YO
414 }
415
e425a60b 416 {
de946258 417 my $message = '\X';
e425a60b
YO
418 use charnames ':full';
419
de946258
NC
420 ok("a!" =~ /^(\X)!/ && $1 eq "a", $message);
421 ok("\xDF!" =~ /^(\X)!/ && $1 eq "\xDF", $message);
422 ok("\x{100}!" =~ /^(\X)!/ && $1 eq "\x{100}", $message);
423 ok("\x{100}\x{300}!" =~ /^(\X)!/ && $1 eq "\x{100}\x{300}", $message);
424 ok("\N{LATIN CAPITAL LETTER E}!" =~ /^(\X)!/ &&
425 $1 eq "\N{LATIN CAPITAL LETTER E}", $message);
426 ok("\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}!"
e425a60b 427 =~ /^(\X)!/ &&
de946258 428 $1 eq "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}", $message);
e425a60b 429
e425a60b
YO
430 }
431
e425a60b 432 {
de946258 433 my $message = "Final Sigma";
e425a60b
YO
434
435 my $SIGMA = "\x{03A3}"; # CAPITAL
436 my $Sigma = "\x{03C2}"; # SMALL FINAL
437 my $sigma = "\x{03C3}"; # SMALL
438
de946258
NC
439 like($SIGMA, qr/$SIGMA/i, $message);
440 like($SIGMA, qr/$Sigma/i, $message);
441 like($SIGMA, qr/$sigma/i, $message);
e425a60b 442
de946258
NC
443 like($Sigma, qr/$SIGMA/i, $message);
444 like($Sigma, qr/$Sigma/i, $message);
445 like($Sigma, qr/$sigma/i, $message);
e425a60b 446
de946258
NC
447 like($sigma, qr/$SIGMA/i, $message);
448 like($sigma, qr/$Sigma/i, $message);
449 like($sigma, qr/$sigma/i, $message);
0f289c68 450
de946258
NC
451 like($SIGMA, qr/[$SIGMA]/i, $message);
452 like($SIGMA, qr/[$Sigma]/i, $message);
453 like($SIGMA, qr/[$sigma]/i, $message);
e425a60b 454
de946258
NC
455 like($Sigma, qr/[$SIGMA]/i, $message);
456 like($Sigma, qr/[$Sigma]/i, $message);
457 like($Sigma, qr/[$sigma]/i, $message);
e425a60b 458
de946258
NC
459 like($sigma, qr/[$SIGMA]/i, $message);
460 like($sigma, qr/[$Sigma]/i, $message);
461 like($sigma, qr/[$sigma]/i, $message);
e425a60b 462
de946258 463 $message = "More final Sigma";
e425a60b
YO
464
465 my $S3 = "$SIGMA$Sigma$sigma";
466
de946258
NC
467 ok(":$S3:" =~ /:(($SIGMA)+):/i && $1 eq $S3 && $2 eq $sigma, $message);
468 ok(":$S3:" =~ /:(($Sigma)+):/i && $1 eq $S3 && $2 eq $sigma, $message);
469 ok(":$S3:" =~ /:(($sigma)+):/i && $1 eq $S3 && $2 eq $sigma, $message);
e425a60b 470
de946258
NC
471 ok(":$S3:" =~ /:(([$SIGMA])+):/i && $1 eq $S3 && $2 eq $sigma, $message);
472 ok(":$S3:" =~ /:(([$Sigma])+):/i && $1 eq $S3 && $2 eq $sigma, $message);
473 ok(":$S3:" =~ /:(([$sigma])+):/i && $1 eq $S3 && $2 eq $sigma, $message);
e425a60b
YO
474 }
475
e425a60b
YO
476 {
477 use charnames ':full';
de946258 478 my $message = "Parlez-Vous " .
e425a60b
YO
479 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais?";
480
de946258
NC
481 ok("Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran.ais/ &&
482 $& eq "Francais", $message);
483 ok("Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran.ais/ &&
484 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais", $message);
de946258
NC
485 ok("Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran\Xais/ &&
486 $& eq "Francais", $message);
487 ok("Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran\Xais/ &&
488 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais", $message);
489 ok("Franc\N{COMBINING CEDILLA}ais" =~ /Fran\Xais/ &&
490 $& eq "Franc\N{COMBINING CEDILLA}ais", $message);
491 ok("Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
e425a60b 492 /Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais/ &&
de946258
NC
493 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais", $message);
494 ok("Franc\N{COMBINING CEDILLA}ais" =~ /Franc\N{COMBINING CEDILLA}ais/ &&
495 $& eq "Franc\N{COMBINING CEDILLA}ais", $message);
e425a60b
YO
496
497 my @f = (
498 ["Fran\N{LATIN SMALL LETTER C}ais", "Francais"],
499 ["Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais",
500 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais"],
501 ["Franc\N{COMBINING CEDILLA}ais", "Franc\N{COMBINING CEDILLA}ais"],
502 );
503 foreach my $entry (@f) {
504 my ($subject, $match) = @$entry;
de946258 505 ok($subject =~ /Fran(?:c\N{COMBINING CEDILLA}?|
e425a60b 506 \N{LATIN SMALL LETTER C WITH CEDILLA})ais/x &&
de946258 507 $& eq $match, $message);
e425a60b
YO
508 }
509 }
510
e425a60b 511 {
de946258 512 my $message = "Lingering (and useless) UTF8 flag doesn't mess up /i";
e425a60b
YO
513 my $pat = "ABcde";
514 my $str = "abcDE\x{100}";
515 chop $str;
de946258 516 like($str, qr/$pat/i, $message);
e425a60b
YO
517
518 $pat = "ABcde\x{100}";
519 $str = "abcDE";
520 chop $pat;
de946258 521 like($str, qr/$pat/i, $message);
e425a60b
YO
522
523 $pat = "ABcde\x{100}";
524 $str = "abcDE\x{100}";
525 chop $pat;
526 chop $str;
de946258 527 like($str, qr/$pat/i, $message);
e425a60b
YO
528 }
529
e425a60b
YO
530 {
531 use charnames ':full';
de946258 532 my $message = "LATIN SMALL LETTER SHARP S " .
e425a60b
YO
533 "(\N{LATIN SMALL LETTER SHARP S})";
534
de946258
NC
535 like("\N{LATIN SMALL LETTER SHARP S}",
536 qr/\N{LATIN SMALL LETTER SHARP S}/, $message);
537 like("\N{LATIN SMALL LETTER SHARP S}",
945961fd
KW
538 qr'\N{LATIN SMALL LETTER SHARP S}', $message);
539 like("\N{LATIN SMALL LETTER SHARP S}",
de946258
NC
540 qr/\N{LATIN SMALL LETTER SHARP S}/i, $message);
541 like("\N{LATIN SMALL LETTER SHARP S}",
945961fd
KW
542 qr'\N{LATIN SMALL LETTER SHARP S}'i, $message);
543 like("\N{LATIN SMALL LETTER SHARP S}",
de946258
NC
544 qr/[\N{LATIN SMALL LETTER SHARP S}]/, $message);
545 like("\N{LATIN SMALL LETTER SHARP S}",
945961fd
KW
546 qr'[\N{LATIN SMALL LETTER SHARP S}]', $message);
547 like("\N{LATIN SMALL LETTER SHARP S}",
de946258 548 qr/[\N{LATIN SMALL LETTER SHARP S}]/i, $message);
945961fd
KW
549 like("\N{LATIN SMALL LETTER SHARP S}",
550 qr'[\N{LATIN SMALL LETTER SHARP S}]'i, $message);
e425a60b 551
de946258 552 like("ss", qr /\N{LATIN SMALL LETTER SHARP S}/i, $message);
945961fd 553 like("ss", qr '\N{LATIN SMALL LETTER SHARP S}'i, $message);
de946258 554 like("SS", qr /\N{LATIN SMALL LETTER SHARP S}/i, $message);
945961fd 555 like("SS", qr '\N{LATIN SMALL LETTER SHARP S}'i, $message);
de946258 556 like("ss", qr/[\N{LATIN SMALL LETTER SHARP S}]/i, $message);
945961fd 557 like("ss", qr'[\N{LATIN SMALL LETTER SHARP S}]'i, $message);
de946258 558 like("SS", qr/[\N{LATIN SMALL LETTER SHARP S}]/i, $message);
945961fd 559 like("SS", qr'[\N{LATIN SMALL LETTER SHARP S}]'i, $message);
e425a60b 560
de946258
NC
561 like("\N{LATIN SMALL LETTER SHARP S}", qr/ss/i, $message);
562 like("\N{LATIN SMALL LETTER SHARP S}", qr/SS/i, $message);
0f289c68 563
de946258
NC
564 $message = "Unoptimized named sequence in class";
565 like("ss", qr/[\N{LATIN SMALL LETTER SHARP S}x]/i, $message);
945961fd 566 like("ss", qr'[\N{LATIN SMALL LETTER SHARP S}x]'i, $message);
de946258 567 like("SS", qr/[\N{LATIN SMALL LETTER SHARP S}x]/i, $message);
945961fd 568 like("SS", qr'[\N{LATIN SMALL LETTER SHARP S}x]'i, $message);
de946258
NC
569 like("\N{LATIN SMALL LETTER SHARP S}",
570 qr/[\N{LATIN SMALL LETTER SHARP S}x]/, $message);
571 like("\N{LATIN SMALL LETTER SHARP S}",
945961fd
KW
572 qr'[\N{LATIN SMALL LETTER SHARP S}x]', $message);
573 like("\N{LATIN SMALL LETTER SHARP S}",
de946258 574 qr/[\N{LATIN SMALL LETTER SHARP S}x]/i, $message);
945961fd
KW
575 like("\N{LATIN SMALL LETTER SHARP S}",
576 qr'[\N{LATIN SMALL LETTER SHARP S}x]'i, $message);
e425a60b
YO
577 }
578
e425a60b
YO
579 {
580 # More whitespace: U+0085, U+2028, U+2029\n";
581
582 # U+0085, U+00A0 need to be forced to be Unicode, the \x{100} does that.
b7ad6c3e
KW
583 like "<\x{100}" . uni_to_native("\x{0085}") . ">", qr/<\x{100}\s>/, '\x{0085} in \s';
584 like "<" . uni_to_native("\x{0085}") . ">", qr/<\v>/, '\x{0085} in \v';
585 like "<\x{100}" . uni_to_native("\x{00A0}") . ">", qr/<\x{100}\s>/, '\x{00A0} in \s';
586 like "<" . uni_to_native("\x{00A0}") . ">", qr/<\h>/, '\x{00A0} in \h';
a9c9e371 587 my @h = map {sprintf "%05x" => $_} 0x01680, 0x02000 .. 0x0200A,
e425a60b
YO
588 0x0202F, 0x0205F, 0x03000;
589 my @v = map {sprintf "%05x" => $_} 0x02028, 0x02029;
590
591 my @H = map {sprintf "%05x" => $_} 0x01361, 0x0200B, 0x02408, 0x02420,
a9c9e371 592 0x0303F, 0xE0020, 0x180E;
e425a60b 593 my @V = map {sprintf "%05x" => $_} 0x0008A .. 0x0008D, 0x00348, 0x10100,
a9c9e371 594 0xE005F, 0xE007C, 0x180E;
e425a60b
YO
595
596 for my $hex (@h) {
597 my $str = eval qq ["<\\x{$hex}>"];
b7ad6c3e
KW
598 like $str, qr/<\s>/, "\\x{$hex} in \\s";
599 like $str, qr/<\h>/, "\\x{$hex} in \\h";
600 unlike $str, qr/<\v>/, "\\x{$hex} not in \\v";
e425a60b
YO
601 }
602
603 for my $hex (@v) {
604 my $str = eval qq ["<\\x{$hex}>"];
b7ad6c3e
KW
605 like $str, qr/<\s>/, "\\x{$hex} in \\s";
606 like $str, qr/<\v>/, "\\x{$hex} in \\v";
607 unlike $str, qr/<\h>/, "\\x{$hex} not in \\h";
e425a60b
YO
608 }
609
610 for my $hex (@H) {
611 my $str = eval qq ["<\\x{$hex}>"];
b7ad6c3e
KW
612 like $str, qr/<\S>/, "\\x{$hex} in \\S";
613 like $str, qr/<\H>/, "\\x{$hex} in \\H";
e425a60b
YO
614 }
615
616 for my $hex (@V) {
617 my $str = eval qq ["<\\x{$hex}>"];
b7ad6c3e
KW
618 like $str, qr/<\S>/, "\\x{$hex} in \\S";
619 like $str, qr/<\V>/, "\\x{$hex} in \\V";
e425a60b
YO
620 }
621 }
622
e425a60b
YO
623 {
624 # . with /s should work on characters, as opposed to bytes
de946258 625 my $message = ". with /s works on characters, not bytes";
e425a60b
YO
626
627 my $s = "\x{e4}\x{100}";
628 # This is not expected to match: the point is that
629 # neither should we get "Malformed UTF-8" warnings.
c11a8df3
NC
630 warning_is(sub {$s =~ /\G(.+?)\n/gcs}, undef,
631 "No 'Malformed UTF-8' warning");
e425a60b
YO
632
633 my @c;
634 push @c => $1 while $s =~ /\G(.)/gs;
635
636 local $" = "";
de946258 637 is("@c", $s, $message);
e425a60b
YO
638
639 # Test only chars < 256
640 my $t1 = "Q003\n\n\x{e4}\x{f6}\n\nQ004\n\n\x{e7}";
641 my $r1 = "";
642 while ($t1 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
0f289c68 643 $r1 .= $1 . $2;
e425a60b
YO
644 }
645
646 my $t2 = $t1 . "\x{100}"; # Repeat with a larger char
647 my $r2 = "";
648 while ($t2 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
0f289c68 649 $r2 .= $1 . $2;
e425a60b
YO
650 }
651 $r2 =~ s/\x{100}//;
652
de946258 653 is($r1, $r2, $message);
e425a60b
YO
654 }
655
e425a60b 656 {
de946258 657 my $message = "Unicode lookbehind";
b7ad6c3e 658 like("A\x{100}B", qr/(?<=A.)B/, $message);
de946258 659 like("A\x{200}\x{300}B", qr/(?<=A..)B/, $message);
b7ad6c3e
KW
660 like("\x{400}AB", qr/(?<=\x{400}.)B/, $message);
661 like("\x{500}\x{600}B", qr/(?<=\x{500}.)B/, $message);
e425a60b
YO
662
663 # Original code also contained:
664 # ok "\x{500\x{600}}B" =~ /(?<=\x{500}.)B/;
665 # but that looks like a typo.
666 }
667
e425a60b 668 {
de946258 669 my $message = 'UTF-8 hash keys and /$/';
e425a60b
YO
670 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters
671 # /2002-01/msg01327.html
672
673 my $u = "a\x{100}";
674 my $v = substr ($u, 0, 1);
675 my $w = substr ($u, 1, 1);
676 my %u = ($u => $u, $v => $v, $w => $w);
677 for (keys %u) {
678 my $m1 = /^\w*$/ ? 1 : 0;
679 my $m2 = $u {$_} =~ /^\w*$/ ? 1 : 0;
de946258 680 is($m1, $m2, $message);
e425a60b
YO
681 }
682 }
683
e425a60b 684 {
de946258 685 my $message = "No SEGV in s/// and UTF-8";
e425a60b 686 my $s = "s#\x{100}" x 4;
de946258 687 ok($s =~ s/[^\w]/ /g, $message);
2e84be61 688 if ( 1 or $ENV{PERL_TEST_LEGACY_POSIX_CC} ) {
de946258 689 is($s, "s \x{100}" x 4, $message);
e425a60b
YO
690 }
691 else {
de946258 692 is($s, "s " x 4, $message);
e425a60b
YO
693 }
694 }
695
e425a60b 696 {
de946258 697 my $message = "UTF-8 bug (maybe already known?)";
e425a60b
YO
698 my $u = "foo";
699 $u =~ s/./\x{100}/g;
de946258 700 is($u, "\x{100}\x{100}\x{100}", $message);
e425a60b
YO
701
702 $u = "foobar";
703 $u =~ s/[ao]/\x{100}/g;
de946258 704 is($u, "f\x{100}\x{100}b\x{100}r", $message);
e425a60b
YO
705
706 $u =~ s/\x{100}/e/g;
de946258 707 is($u, "feeber", $message);
e425a60b
YO
708 }
709
e425a60b 710 {
de946258 711 my $message = "UTF-8 bug with s///";
e425a60b
YO
712 # check utf8/non-utf8 mixtures
713 # try to force all float/anchored check combinations
714
715 my $c = "\x{100}";
716 my $subst;
717 for my $re ("xx.*$c", "x.*$c$c", "$c.*xx", "$c$c.*x",
718 "xx.*(?=$c)", "(?=$c).*xx",) {
de946258
NC
719 unlike("xxx", qr/$re/, $message);
720 ok(+($subst = "xxx") !~ s/$re//, $message);
e425a60b
YO
721 }
722 for my $re ("xx.*$c*", "$c*.*xx") {
de946258
NC
723 like("xxx", qr/$re/, $message);
724 ok(+($subst = "xxx") =~ s/$re//, $message);
725 is($subst, "", $message);
e425a60b
YO
726 }
727 for my $re ("xxy*", "y*xx") {
de946258
NC
728 like("xx$c", qr/$re/, $message);
729 ok(+($subst = "xx$c") =~ s/$re//, $message);
730 is($subst, $c, $message);
731 unlike("xy$c", qr/$re/, $message);
732 ok(+($subst = "xy$c") !~ s/$re//, $message);
e425a60b
YO
733 }
734 for my $re ("xy$c*z", "x$c*yz") {
de946258
NC
735 like("xyz", qr/$re/, $message);
736 ok(+($subst = "xyz") =~ s/$re//, $message);
737 is($subst, "", $message);
e425a60b
YO
738 }
739 }
740
e425a60b 741 {
c72077c4
AC
742 # The second half of RT #114808
743 warning_is(sub {'aa' =~ /.+\x{100}/}, undef,
744 'utf8-only floating substr, non-utf8 target, no warning');
745 }
746
747 {
de946258 748 my $message = "qr /.../x";
e425a60b 749 my $R = qr / A B C # D E/x;
de946258
NC
750 ok("ABCDE" =~ $R && $& eq "ABC", $message);
751 ok("ABCDE" =~ /$R/ && $& eq "ABC", $message);
752 ok("ABCDE" =~ m/$R/ && $& eq "ABC", $message);
753 ok("ABCDE" =~ /($R)/ && $1 eq "ABC", $message);
754 ok("ABCDE" =~ m/($R)/ && $1 eq "ABC", $message);
e425a60b
YO
755 }
756
e425a60b
YO
757 {
758 local $\;
759 $_ = 'aaaaaaaaaa';
760 utf8::upgrade($_); chop $_; $\="\n";
761 ok /[^\s]+/, 'm/[^\s]/ utf8';
762 ok /[^\d]+/, 'm/[^\d]/ utf8';
763 ok +($a = $_, $_ =~ s/[^\s]+/./g), 's/[^\s]/ utf8';
764 ok +($a = $_, $a =~ s/[^\d]+/./g), 's/[^\s]/ utf8';
765 }
766
e425a60b
YO
767 {
768 # Subject: Odd regexp behavior
769 # From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
770 # Date: Wed, 26 Feb 2003 16:53:12 +0000
771 # Message-Id: <E18o4nw-0008Ly-00@wisbech.cl.cam.ac.uk>
772 # To: perl-unicode@perl.org
773
de946258 774 my $message = 'Markus Kuhn 2003-02-26';
0f289c68 775
e425a60b 776 my $x = "\x{2019}\nk";
de946258
NC
777 ok($x =~ s/(\S)\n(\S)/$1 $2/sg, $message);
778 is($x, "\x{2019} k", $message);
e425a60b
YO
779
780 $x = "b\nk";
de946258
NC
781 ok($x =~ s/(\S)\n(\S)/$1 $2/sg, $message);
782 is($x, "b k", $message);
e425a60b 783
de946258 784 like("\x{2019}", qr/\S/, $message);
e425a60b
YO
785 }
786
e425a60b 787 {
b7ad6c3e 788 like "\x{100}\n", qr/\x{100}\n$/, "UTF-8 length cache and fbm_compile";
e425a60b
YO
789 }
790
e425a60b
YO
791 {
792 package Str;
793 use overload q /""/ => sub {${$_ [0]};};
794 sub new {my ($c, $v) = @_; bless \$v, $c;}
795
796 package main;
797 $_ = Str -> new ("a\x{100}/\x{100}b");
798 ok join (":", /\b(.)\x{100}/g) eq "a:/", "re_intuit_start and PL_bostr";
799 }
800
e425a60b
YO
801 {
802 my $re = qq /^([^X]*)X/;
803 utf8::upgrade ($re);
8f46dbea 804 like "\x{100}X", qr/$re/, "S_cl_and ANYOF_UNICODE & ANYOF_INVERTED";
0ab1ff8e
KW
805 my $loc_re = qq /(?l:^([^X]*)X)/;
806 utf8::upgrade ($loc_re);
613abc6d 807 no warnings 'locale';
8f46dbea 808 like "\x{100}X", qr/$loc_re/, "locale, S_cl_and ANYOF_UNICODE & ANYOF_INVERTED";
e425a60b
YO
809 }
810
e425a60b 811 {
b7ad6c3e 812 like "123\x{100}", qr/^.*1.*23\x{100}$/,
e425a60b
YO
813 'UTF-8 + multiple floating substr';
814 }
815
e425a60b 816 {
de946258 817 my $message = '<20030808193656.5109.1@llama.ni-s.u-net.com>';
e425a60b
YO
818
819 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
de946258 820 like(" \x{101}", qr/\x{100}/i, $message);
e425a60b
YO
821
822 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
de946258 823 like(" \x{1E01}", qr/\x{1E00}/i, $message);
e425a60b
YO
824
825 # DESERET SMALL/CAPITAL LETTER LONG I
de946258 826 like(" \x{10428}", qr/\x{10400}/i, $message);
e425a60b
YO
827
828 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
de946258 829 like(" \x{1E01}x", qr/\x{1E00}X/i, $message);
e425a60b
YO
830 }
831
e425a60b 832 {
26faadbd 833 for (120 .. 130, 240 .. 260) {
e425a60b 834 my $head = 'x' x $_;
de946258 835 my $message = q [Don't misparse \x{...} in regexp ] .
26faadbd 836 q [near EXACT char count limit];
e425a60b 837 for my $tail ('\x{0061}', '\x{1234}', '\x61') {
14358a41
NC
838 eval qq{like("$head$tail", qr/$head$tail/, \$message)};
839 is($@, '', $message);
e425a60b 840 }
de946258 841 $message = q [Don't misparse \N{...} in regexp ] .
26faadbd 842 q [near EXACT char count limit];
e425a60b 843 for my $tail ('\N{SNOWFLAKE}') {
14358a41
NC
844 eval qq {use charnames ':full';
845 like("$head$tail", qr/$head$tail/, \$message)};
945961fd
KW
846 eval qq {use charnames ':full';
847 like("$head$tail", qr'$head$tail', \$message)};
14358a41 848 is($@, '', $message);
e425a60b
YO
849 }
850 }
851 }
852
e425a60b
YO
853 { # TRIE related
854 our @got = ();
855 "words" =~ /(word|word|word)(?{push @got, $1})s$/;
de26e0cc 856 is(@got, 1, "TRIE optimisation");
e425a60b
YO
857
858 @got = ();
859 "words" =~ /(word|word|word)(?{push @got,$1})s$/i;
de26e0cc 860 is(@got, 1,"TRIEF optimisation");
e425a60b
YO
861
862 my @nums = map {int rand 1000} 1 .. 100;
863 my $re = "(" . (join "|", @nums) . ")";
864 $re = qr/\b$re\b/;
865
866 foreach (@nums) {
b7ad6c3e 867 like $_, qr/$re/, "Trie nums";
e425a60b
YO
868 }
869
870 $_ = join " ", @nums;
871 @got = ();
872 push @got, $1 while /$re/g;
873
874 my %count;
875 $count {$_} ++ for @got;
876 my $ok = 1;
877 for (@nums) {
878 $ok = 0 if --$count {$_} < 0;
879 }
880 ok $ok, "Trie min count matches";
881 }
882
e425a60b
YO
883 {
884 # TRIE related
885 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
886 ok "foba \x{101}foo" =~ qr/(foo|\x{100}foo|bar)/i &&
887 $1 eq "\x{101}foo",
888 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH MACRON";
889
890 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
891 ok "foba \x{1E01}foo" =~ qr/(foo|\x{1E00}foo|bar)/i &&
892 $1 eq "\x{1E01}foo",
893 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW";
894
895 # DESERET SMALL/CAPITAL LETTER LONG I
896 ok "foba \x{10428}foo" =~ qr/(foo|\x{10400}foo|bar)/i &&
897 $1 eq "\x{10428}foo",
898 "TRIEF + DESERET SMALL/CAPITAL LETTER LONG I";
899
900 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
901 ok "foba \x{1E01}xfoo" =~ qr/(foo|\x{1E00}Xfoo|bar)/i &&
902 $1 eq "\x{1E01}xfoo",
903 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'";
904
905 use charnames ':full';
906
907 my $s = "\N{LATIN SMALL LETTER SHARP S}";
908 ok "foba ba$s" =~ qr/(foo|Ba$s|bar)/i && $1 eq "ba$s",
909 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
910 ok "foba ba$s" =~ qr/(Ba$s|foo|bar)/i && $1 eq "ba$s",
911 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
912 ok "foba ba$s" =~ qr/(foo|bar|Ba$s)/i && $1 eq "ba$s",
913 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
914
915 ok "foba ba$s" =~ qr/(foo|Bass|bar)/i && $1 eq "ba$s",
916 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
917
918 ok "foba ba$s" =~ qr/(foo|BaSS|bar)/i && $1 eq "ba$s",
919 "TRIEF + LATIN SMALL LETTER SHARP S =~ SS";
920
921 ok "foba ba${s}pxySS$s$s" =~ qr/(b(?:a${s}t|a${s}f|a${s}p)[xy]+$s*)/i
922 && $1 eq "ba${s}pxySS$s$s",
923 "COMMON PREFIX TRIEF + LATIN SMALL LETTER SHARP S";
924 }
925
e425a60b 926 {
3fe9640a
JH
927 BEGIN {
928 unshift @INC, 'lib';
929 }
b99b8a84
KW
930 use Cname; # Our custom charname plugin, currently found in
931 # t/lib/Cname.pm
0f289c68 932
b7ad6c3e 933 like 'fooB', qr/\N{foo}[\N{B}\N{b}]/, "Passthrough charname";
94ca1619
KW
934 my $name = "foo\xDF";
935 my $result = eval "'A${name}B' =~ /^A\\N{$name}B\$/";
936 ok !$@ && $result, "Passthrough charname of non-ASCII, Latin1";
673c254b
KW
937 eval "qr/\\p{name=foo}/";
938 like($@, qr/Can't find Unicode property definition "name=foo"/,
939 '\p{name=} doesn\'t see a cumstom charnames translator');
e425a60b
YO
940 #
941 # Why doesn't must_warn work here?
942 #
943 my $w;
944 local $SIG {__WARN__} = sub {$w .= "@_"};
a78e2a97 945 $result = eval 'q(WARN) =~ /^[\N{WARN}]$/';
8f0cd35a 946 ok !$@ && $result && ! $w, '\N{} returning multi-char works';
e425a60b
YO
947
948 undef $w;
b7ad6c3e 949 eval q [unlike "\0", qr/[\N{EMPTY-STR}XY]/,
5895685f 950 "Zerolength charname in charclass doesn't match \\\\0"];
ff3f963a
KW
951 ok $w && $w =~ /Ignoring zero length/,
952 'Ignoring zero length \N{} in character class warning';
67048c1b 953 undef $w;
b7ad6c3e 954 eval q [like 'xy', qr/x[\N{EMPTY-STR} y]/x,
67048c1b
KW
955 'Empty string charname in [] is ignored; finds a following character'];
956 ok $w && $w =~ /Ignoring zero length/,
957 'Ignoring zero length \N{} in character class warning';
958 undef $w;
b7ad6c3e 959 eval q [like 'x ', qr/x[\N{EMPTY-STR} y]/,
67048c1b 960 'Empty string charname in [] is ignored; finds a following blank under /x'];
b7ad6c3e 961 like $w, qr/Ignoring zero length/,
67048c1b 962 'Ignoring zero length \N{} in character class warning';
e425a60b 963
b99b8a84
KW
964 # EVIL keeps track of its calls, and appends a new character each
965 # time: A AB ABC ABCD ...
e425a60b 966 ok 'AB' =~ /(\N{EVIL})/ && $1 eq 'A', 'Charname caching $1';
b7ad6c3e 967 like 'ABC', qr/(\N{EVIL})/, 'Charname caching $1';
945961fd
KW
968 ok 'ABCD' =~ m'(\N{EVIL})' && $1 eq 'ABC', 'Charname caching $1';
969 ok 'ABCDE' =~ m'(\N{EVIL})', 'Charname caching $1';
b7ad6c3e 970 like 'xy', qr/x\N{EMPTY-STR}y/,
e425a60b 971 'Empty string charname produces NOTHING node';
945961fd
KW
972 ok 'xy' =~ 'x\N{EMPTY-STR}y',
973 'Empty string charname produces NOTHING node';
b7ad6c3e 974 like '', qr/\N{EMPTY-STR}/,
e425a60b 975 'Empty string charname produces NOTHING node';
b7ad6c3e
KW
976 like "\N{LONG-STR}", qr/^\N{LONG-STR}$/, 'Verify that long string works';
977 like "\N{LONG-STR}", qr/^\N{LONG-STR}$/i, 'Verify under folding that long string works';
1e629c22
KW
978
979 # perlhacktips points out that these work on both ASCII and EBCDIC
980 like "\xfc", qr/\N{EMPTY-STR}\xdc/i, 'Empty \N{} should change /d to /u';
945961fd 981 like "\xfc", qr'\N{EMPTY-STR}\xdc'i, 'Empty \N{} should change /d to /u';
ff3f963a 982
902994e4 983 eval '/(?[[\N{EMPTY-STR}]])/';
b7ad6c3e 984 like $@, qr/Zero length \\N\{\}/, 'Verify zero-length return from \N{} correctly fails';
945961fd
KW
985 ok "\N{LONG-STR}" =~ /^\N{LONG-STR}$/, 'Verify that long string works';
986 ok "\N{LONG-STR}" =~ '^\N{LONG-STR}$', 'Verify that long string works';
987 ok "\N{LONG-STR}" =~ /^\N{LONG-STR}$/i, 'Verify under folding that long string works';
988 ok "\N{LONG-STR}" =~ m'^\N{LONG-STR}$'i, 'Verify under folding that long string works';
902994e4 989
bd299e29 990 undef $w;
bd299e29 991 {
3036c853 992 () = eval q ["\N{TOO MANY SPACES}"];
2d8eb851 993 like ($@, qr/charnames alias definitions may not contain a sequence of multiple spaces/, "Multiple spaces in a row in a charnames alias is fatal");
3036c853 994 eval q [use utf8; () = "\N{TOO MANY SPACES}"];
2d8eb851 995 like ($@, qr/charnames alias definitions may not contain a sequence of multiple spaces/, "... same under utf8");
94ec3a20 996 }
bd299e29
KW
997
998 undef $w;
7fc82458 999 my $Cedilla_Latin1 = "GAR"
d1cef54a 1000 . uni_to_native("\xC7")
7fc82458
KW
1001 . "ON";
1002 my $Cedilla_utf8 = $Cedilla_Latin1;
1003 utf8::upgrade($Cedilla_utf8);
1004 eval qq[is("\\N{$Cedilla_Latin1}", "$Cedilla_Latin1", "A cedilla in character name works")];
1005 undef $w;
1006 {
1007 use feature 'unicode_eval';
1008 eval qq[use utf8; is("\\N{$Cedilla_utf8}", "$Cedilla_utf8", "... same under 'use utf8': they work")];
1009 }
1010
1011 undef $w;
df758df2 1012 my $NBSP_Latin1 = "NBSP"
d1cef54a 1013 . uni_to_native("\xA0")
df758df2 1014 . "SEPARATED"
d1cef54a 1015 . uni_to_native("\xA0")
df758df2
KW
1016 . "SPACE";
1017 my $NBSP_utf8 = $NBSP_Latin1;
1018 utf8::upgrade($NBSP_utf8);
61463a3e
KW
1019 () = eval qq[is("\\N{$NBSP_Latin1}", "$NBSP_Latin1"];
1020 like ($@, qr/Invalid character in \\N\{...}/, "A NO-BREAK SPACE in a charnames alias is fatal");
df758df2
KW
1021 undef $w;
1022 {
1023 use feature 'unicode_eval';
61463a3e
KW
1024 eval qq[use utf8; is("\\N{$NBSP_utf8}"];
1025 like ($@, qr/Invalid character in \\N\{...}/, "A NO-BREAK SPACE in a charnames alias is fatal");
df758df2
KW
1026 }
1027
6a642c21
FC
1028 {
1029 BEGIN { no strict; *CnameTest:: = *{"_charnames\0A::" } }
1030 package CnameTest { sub translator { pop } }
1031 BEGIN { $^H{charnames} = \&CnameTest::translator }
1032 undef $w;
1033 () = eval q ["\N{TOO MANY SPACES}"];
2d8eb851 1034 like ($@, qr/charnames alias definitions may not contain a sequence of multiple spaces/,
6a642c21
FC
1035 'translators in _charnames\0* packages get validated');
1036 }
1037
ff3f963a
KW
1038 # If remove the limitation in regcomp code these should work
1039 # differently
1040 undef $w;
b7ad6c3e 1041 eval q [like "\N{TOO-LONG-STR}" =~ /^\N{TOO-LONG-STR}$/, 'Verify that what once was too long a string works'];
cb233ae3 1042 eval 'q() =~ /\N{4F}/';
4d7cd482 1043 ok $@ && $@ =~ /Invalid character/, 'Verify that leading digit in name gives error';
cb233ae3 1044 eval 'q() =~ /\N{COM,MA}/';
4d7cd482 1045 ok $@ && $@ =~ /Invalid character/, 'Verify that comma in name gives error';
f36cc39d 1046 $name = "A" . uni_to_native("\x{D7}") . "O";
cb233ae3 1047 eval "q(W) =~ /\\N{$name}/";
4d7cd482 1048 ok $@ && $@ =~ /Invalid character/, 'Verify that latin1 symbol in name gives error';
bde9e88d
KW
1049 my $utf8_name = "7 CITIES OF GOLD";
1050 utf8::upgrade($utf8_name);
1051 eval "use utf8; q(W) =~ /\\N{$utf8_name}/";
1052 ok $@ && $@ =~ /Invalid character/, 'Verify that leading digit in utf8 name gives error';
1053 $utf8_name = "SHARP #";
1054 utf8::upgrade($utf8_name);
1055 eval "use utf8; q(W) =~ /\\N{$utf8_name}/";
1056 ok $@ && $@ =~ /Invalid character/, 'Verify that ASCII symbol in utf8 name gives error';
f36cc39d 1057 $utf8_name = "A HOUSE " . uni_to_native("\xF7") . " AGAINST ITSELF";
bde9e88d
KW
1058 utf8::upgrade($utf8_name);
1059 eval "use utf8; q(W) =~ /\\N{$utf8_name}/";
1060 ok $@ && $@ =~ /Invalid character/, 'Verify that latin1 symbol in utf8 name gives error';
1061 $utf8_name = "\x{664} HORSEMEN}";
1062 eval "use utf8; q(W) =~ /\\N{$utf8_name}/";
1063 ok $@ && $@ =~ /Invalid character/, 'Verify that leading above Latin1 digit in utf8 name gives error';
1064 $utf8_name = "A \x{1F4A9} WOULD SMELL AS SWEET}";
1065 eval "use utf8; q(W) =~ /\\N{$utf8_name}/";
1066 ok $@ && $@ =~ /Invalid character/, 'Verify that above Latin1 symbol in utf8 name gives error';
1067
cb233ae3 1068 undef $w;
f36cc39d 1069 $name = "A" . uni_to_native("\x{D1}") . "O";
cb233ae3
KW
1070 eval "q(W) =~ /\\N{$name}/";
1071 ok ! $w, 'Verify that latin1 letter in name doesnt give warning';
0f289c68 1072
ba7b73c5
NC
1073 # This tests the code path that restarts the parse when the recursive
1074 # call to S_reg() from within S_grok_bslash_N() discovers that the
1075 # pattern needs to be recalculated as UTF-8. use eval to avoid
1076 # needing literal Unicode in this source file:
1077 my $r = eval "qr/\\N{\x{100}\x{100}}/";
1078 isnt $r, undef, "Generated regex for multi-char UTF-8 charname"
1079 or diag($@);
b7ad6c3e 1080 like "\x{100}\x{100}", $r, "which matches";
e425a60b
YO
1081 }
1082
e425a60b
YO
1083 {
1084 use charnames ':full';
1085
b7ad6c3e
KW
1086 unlike 'aabc', qr/a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against aabc';
1087 like 'a+bc', qr/a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against a+bc';
e425a60b 1088
b7ad6c3e 1089 like ' A B', qr/\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
e425a60b 1090 'Intermixed named and unicode escapes';
b7ad6c3e
KW
1091 like "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}",
1092 qr/\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
e425a60b 1093 'Intermixed named and unicode escapes';
b7ad6c3e
KW
1094 like "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}",
1095 qr/[\N{SPACE}\N{U+0041}][\N{SPACE}\N{U+0042}]/,
0f289c68 1096 'Intermixed named and unicode escapes';
b7ad6c3e 1097 like "\0", qr/^\N{NULL}$/, 'Verify that \N{NULL} works; is not confused with an error';
e425a60b
YO
1098 }
1099
e425a60b
YO
1100 {
1101 our $brackets;
1102 $brackets = qr{
1103 { (?> [^{}]+ | (??{ $brackets }) )* }
1104 }x;
1105
b7ad6c3e 1106 unlike "{b{c}d", qr/^((??{ $brackets }))/, "Bracket mismatch";
e425a60b
YO
1107
1108 SKIP: {
1109 our @stack = ();
1110 my @expect = qw(
1111 stuff1
1112 stuff2
1113 <stuff1>and<stuff2>
1114 right
1115 <right>
1116 <<right>>
1117 <<<right>>>
1118 <<stuff1>and<stuff2>><<<<right>>>>
1119 );
1120
1121 local $_ = '<<<stuff1>and<stuff2>><<<<right>>>>>';
1122 ok /^(<((?:(?>[^<>]+)|(?1))*)>(?{push @stack, $2 }))$/,
1123 "Recursion matches";
de26e0cc 1124 is(@stack, @expect, "Right amount of matches")
e425a60b
YO
1125 or skip "Won't test individual results as count isn't equal",
1126 0 + @expect;
1127 my $idx = 0;
1128 foreach my $expect (@expect) {
de26e0cc
NC
1129 is($stack [$idx], $expect,
1130 "Expecting '$expect' at stack pos #$idx");
e425a60b
YO
1131 $idx ++;
1132 }
1133 }
1134 }
1135
e425a60b
YO
1136 {
1137 my $s = '123453456';
1138 $s =~ s/(?<digits>\d+)\k<digits>/$+{digits}/;
1139 ok $s eq '123456', 'Named capture (angle brackets) s///';
1140 $s = '123453456';
1141 $s =~ s/(?'digits'\d+)\k'digits'/$+{digits}/;
0f289c68 1142 ok $s eq '123456', 'Named capture (single quotes) s///';
e425a60b
YO
1143 }
1144
e425a60b
YO
1145 {
1146 my @ary = (
726f0605
KW
1147 pack('U', utf8::unicode_to_native(0x00F1)), # n-tilde
1148 '_'.pack('U', utf8::unicode_to_native(0x00F1)), # _ + n-tilde
e425a60b 1149 'c'.pack('U', 0x0327), # c + cedilla
726f0605 1150 pack('U*', utf8::unicode_to_native(0x00F1), 0x0327),# n-tilde + cedilla
e425a60b
YO
1151 pack('U', 0x0391), # ALPHA
1152 pack('U', 0x0391).'2', # ALPHA + 2
1153 pack('U', 0x0391).'_', # ALPHA + _
1154 );
1155
1156 for my $uni (@ary) {
1157 my ($r1, $c1, $r2, $c2) = eval qq {
1158 use utf8;
1159 scalar ("..foo foo.." =~ /(?'${uni}'foo) \\k'${uni}'/),
1160 \$+{${uni}},
1161 scalar ("..bar bar.." =~ /(?<${uni}>bar) \\k<${uni}>/),
1162 \$+{${uni}};
1163 };
1164 ok $r1, "Named capture UTF (?'')";
1165 ok defined $c1 && $c1 eq 'foo', "Named capture UTF \%+";
1166 ok $r2, "Named capture UTF (?<>)";
1167 ok defined $c2 && $c2 eq 'bar', "Named capture UTF \%+";
1168 }
1169 }
1170
e425a60b
YO
1171 {
1172 my $s = 'foo bar baz';
1173 my @res;
1174 if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) {
1175 foreach my $name (sort keys(%-)) {
1176 my $ary = $- {$name};
1177 foreach my $idx (0 .. $#$ary) {
1178 push @res, "$name:$idx:$ary->[$idx]";
1179 }
1180 }
1181 }
1182 my @expect = qw (A:0:1 A:1:3 B:0:2 B:1:4);
de26e0cc 1183 is("@res", "@expect", "Check %-");
e425a60b
YO
1184 eval'
1185 no warnings "uninitialized";
1186 print for $- {this_key_doesnt_exist};
1187 ';
1188 ok !$@,'lvalue $- {...} should not throw an exception';
1189 }
1190
e425a60b 1191 {
e425a60b 1192 # \c\ followed by _
b7ad6c3e
KW
1193 unlike "x\c_y", qr/x\c\_y/, '\_ in a pattern';
1194 like "x\c\_y", qr/x\c\_y/, '\_ in a pattern';
e425a60b
YO
1195
1196 # \c\ followed by other characters
1197 for my $c ("z", "\0", "!", chr(254), chr(256)) {
f36cc39d 1198 my $targ = "a" . uni_to_native("\034") . "$c";
e425a60b
YO
1199 my $reg = "a\\c\\$c";
1200 ok eval ("qq/$targ/ =~ /$reg/"), "\\c\\ in pattern";
1201 }
1202 }
1203
e425a60b
YO
1204 { # Test the (*PRUNE) pattern
1205 our $count = 0;
1206 'aaab' =~ /a+b?(?{$count++})(*FAIL)/;
de26e0cc 1207 is($count, 9, "Expect 9 for no (*PRUNE)");
e425a60b
YO
1208 $count = 0;
1209 'aaab' =~ /a+b?(*PRUNE)(?{$count++})(*FAIL)/;
de26e0cc 1210 is($count, 3, "Expect 3 with (*PRUNE)");
e425a60b
YO
1211 local $_ = 'aaab';
1212 $count = 0;
1213 1 while /.(*PRUNE)(?{$count++})(*FAIL)/g;
de26e0cc 1214 is($count, 4, "/.(*PRUNE)/");
e425a60b
YO
1215 $count = 0;
1216 'aaab' =~ /a+b?(??{'(*PRUNE)'})(?{$count++})(*FAIL)/;
de26e0cc 1217 is($count, 3, "Expect 3 with (*PRUNE)");
e425a60b
YO
1218 local $_ = 'aaab';
1219 $count = 0;
1220 1 while /.(??{'(*PRUNE)'})(?{$count++})(*FAIL)/g;
de26e0cc 1221 is($count, 4, "/.(*PRUNE)/");
e425a60b
YO
1222 }
1223
e425a60b
YO
1224 { # Test the (*SKIP) pattern
1225 our $count = 0;
1226 'aaab' =~ /a+b?(*SKIP)(?{$count++})(*FAIL)/;
de26e0cc 1227 is($count, 1, "Expect 1 with (*SKIP)");
e425a60b
YO
1228 local $_ = 'aaab';
1229 $count = 0;
1230 1 while /.(*SKIP)(?{$count++})(*FAIL)/g;
de26e0cc 1231 is($count, 4, "/.(*SKIP)/");
e425a60b
YO
1232 $_ = 'aaabaaab';
1233 $count = 0;
1234 our @res = ();
1235 1 while /(a+b?)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
de26e0cc
NC
1236 is($count, 2, "Expect 2 with (*SKIP)");
1237 is("@res", "aaab aaab", "Adjacent (*SKIP) works as expected");
b9f8f219
YO
1238
1239 $_ = "dir/file.mp3";
1240 my $got = m{ ( ([^/]+) (?: / (*SKIP)(*FAIL) | \z ) ) }x ? $1 : undef;
1241 is($got, "file.mp3", "(*SKIP) and find_byclass() work together");
e425a60b
YO
1242 }
1243
e425a60b
YO
1244 { # Test the (*SKIP) pattern
1245 our $count = 0;
1246 'aaab' =~ /a+b?(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/;
de26e0cc 1247 is($count, 1, "Expect 1 with (*SKIP)");
e425a60b
YO
1248 local $_ = 'aaab';
1249 $count = 0;
1250 1 while /.(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/g;
de26e0cc 1251 is($count, 4, "/.(*SKIP)/");
e425a60b
YO
1252 $_ = 'aaabaaab';
1253 $count = 0;
1254 our @res = ();
1255 1 while /(a+b?)(*MARK:foo)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
de26e0cc
NC
1256 is($count, 2, "Expect 2 with (*SKIP)");
1257 is("@res", "aaab aaab", "Adjacent (*SKIP) works as expected");
e425a60b
YO
1258 }
1259
e425a60b
YO
1260 { # Test the (*SKIP) pattern
1261 our $count = 0;
1262 'aaab' =~ /a*(*MARK:a)b?(*MARK:b)(*SKIP:a)(?{$count++})(*FAIL)/;
de26e0cc 1263 is($count, 3, "Expect 3 with *MARK:a)b?(*MARK:b)(*SKIP:a)");
e425a60b
YO
1264 local $_ = 'aaabaaab';
1265 $count = 0;
1266 our @res = ();
1267 1 while
1268 /(a*(*MARK:a)b?)(*MARK:x)(*SKIP:a)(?{$count++; push @res,$1})(*FAIL)/g;
de26e0cc
NC
1269 is($count, 5, "Expect 5 with (*MARK:a)b?)(*MARK:x)(*SKIP:a)");
1270 is("@res", "aaab b aaab b ",
1271 "Adjacent (*MARK:a)b?)(*MARK:x)(*SKIP:a) works as expected");
e425a60b
YO
1272 }
1273
e425a60b
YO
1274 { # Test the (*COMMIT) pattern
1275 our $count = 0;
1276 'aaabaaab' =~ /a+b?(*COMMIT)(?{$count++})(*FAIL)/;
de26e0cc 1277 is($count, 1, "Expect 1 with (*COMMIT)");
e425a60b
YO
1278 local $_ = 'aaab';
1279 $count = 0;
1280 1 while /.(*COMMIT)(?{$count++})(*FAIL)/g;
de26e0cc 1281 is($count, 1, "/.(*COMMIT)/");
e425a60b
YO
1282 $_ = 'aaabaaab';
1283 $count = 0;
1284 our @res = ();
1285 1 while /(a+b?)(*COMMIT)(?{$count++; push @res,$1})(*FAIL)/g;
de26e0cc
NC
1286 is($count, 1, "Expect 1 with (*COMMIT)");
1287 is("@res", "aaab", "Adjacent (*COMMIT) works as expected");
3542935d 1288
b7ad6c3e 1289 unlike("1\n2a\n", qr/^\d+(*COMMIT)\w+/m, "COMMIT and anchors");
e425a60b
YO
1290 }
1291
e425a60b
YO
1292 {
1293 # Test named commits and the $REGERROR var
fee50582 1294 local $REGERROR;
e425a60b
YO
1295 for my $name ('', ':foo') {
1296 for my $pat ("(*PRUNE$name)",
1297 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)",
0f289c68 1298 "(*COMMIT$name)") {
e425a60b
YO
1299 for my $suffix ('(*FAIL)', '') {
1300 'aaaab' =~ /a+b$pat$suffix/;
de26e0cc 1301 is($REGERROR,
e425a60b 1302 ($suffix ? ($name ? 'foo' : "1") : ""),
de26e0cc 1303 "Test $pat and \$REGERROR $suffix");
e425a60b
YO
1304 }
1305 }
1306 }
1307 }
1308
e425a60b
YO
1309 {
1310 # Test named commits and the $REGERROR var
1311 package Fnorble;
1312 our $REGERROR;
fee50582 1313 local $REGERROR;
e425a60b
YO
1314 for my $name ('', ':foo') {
1315 for my $pat ("(*PRUNE$name)",
1316 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)",
0f289c68 1317 "(*COMMIT$name)") {
e425a60b
YO
1318 for my $suffix ('(*FAIL)','') {
1319 'aaaab' =~ /a+b$pat$suffix/;
de26e0cc 1320 ::is($REGERROR,
e425a60b 1321 ($suffix ? ($name ? 'foo' : "1") : ""),
de26e0cc 1322 "Test $pat and \$REGERROR $suffix");
e425a60b
YO
1323 }
1324 }
0f289c68
YO
1325 }
1326 }
e425a60b 1327
e425a60b
YO
1328 {
1329 # Test named commits and the $REGERROR var
de946258 1330 my $message = '$REGERROR';
fee50582 1331 local $REGERROR;
e425a60b
YO
1332 for my $word (qw (bar baz bop)) {
1333 $REGERROR = "";
1334 "aaaaa$word" =~
1335 /a+(?:bar(*COMMIT:bar)|baz(*COMMIT:baz)|bop(*COMMIT:bop))(*FAIL)/;
de946258 1336 is($REGERROR, $word, $message);
0f289c68 1337 }
e425a60b
YO
1338 }
1339
e425a60b
YO
1340 {
1341 #Mindnumbingly simple test of (*THEN)
1342 for ("ABC","BAX") {
1343 ok /A (*THEN) X | B (*THEN) C/x, "Simple (*THEN) test";
1344 }
1345 }
1346
e425a60b 1347 {
de946258 1348 my $message = "Relative Recursion";
e425a60b
YO
1349 my $parens = qr/(\((?:[^()]++|(?-1))*+\))/;
1350 local $_ = 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))';
1351 my ($all, $one, $two) = ('', '', '');
de946258
NC
1352 ok(m/foo $parens \s* \+ \s* bar $parens/x, $message);
1353 is($1, '((2*3)+4-3)', $message);
1354 is($2, '(2*(3+4)-1*(2-3))', $message);
1355 is($&, 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))', $message);
1356 is($&, $_, $message);
e425a60b
YO
1357 }
1358
1359 {
1360 my $spaces=" ";
1361 local $_ = join 'bar', $spaces, $spaces;
1362 our $count = 0;
1363 s/(?>\s+bar)(?{$count++})//g;
de26e0cc
NC
1364 is($_, $spaces, "SUSPEND final string");
1365 is($count, 1, "Optimiser should have prevented more than one match");
e425a60b
YO
1366 }
1367
e425a60b
YO
1368 {
1369 # From Message-ID: <877ixs6oa6.fsf@k75.linux.bogus>
1370 my $dow_name = "nada";
1371 my $parser = "(\$dow_name) = \$time_string =~ /(D\x{e9}\\ " .
1372 "C\x{e9}adaoin|D\x{e9}\\ Sathairn|\\w+|\x{100})/";
1373 my $time_string = "D\x{e9} C\x{e9}adaoin";
1374 eval $parser;
1375 ok !$@, "Test Eval worked";
de26e0cc 1376 is($dow_name, $time_string, "UTF-8 trie common prefix extraction");
e425a60b
YO
1377 }
1378
e425a60b
YO
1379 {
1380 my $v;
1381 ($v = 'bar') =~ /(\w+)/g;
1382 $v = 'foo';
de26e0cc
NC
1383 is("$1", 'bar',
1384 '$1 is safe after /g - may fail due to specialized config in pp_hot.c');
e425a60b
YO
1385 }
1386
e425a60b 1387 {
de946258 1388 my $message = "http://nntp.perl.org/group/perl.perl5.porters/118663";
e425a60b 1389 my $qr_barR1 = qr/(bar)\g-1/;
de946258
NC
1390 like("foobarbarxyz", $qr_barR1, $message);
1391 like("foobarbarxyz", qr/foo${qr_barR1}xyz/, $message);
1392 like("foobarbarxyz", qr/(foo)${qr_barR1}xyz/, $message);
1393 like("foobarbarxyz", qr/(foo)(bar)\g{-1}xyz/, $message);
1394 like("foobarbarxyz", qr/(foo${qr_barR1})xyz/, $message);
1395 like("foobarbarxyz", qr/(foo(bar)\g{-1})xyz/, $message);
0f289c68 1396 }
e425a60b 1397
e425a60b 1398 {
de946258 1399 my $message = '$REGMARK';
e425a60b 1400 our @r = ();
fee50582
YO
1401 local $REGMARK;
1402 local $REGERROR;
de946258
NC
1403 like('foofoo', qr/foo (*MARK:foo) (?{push @r,$REGMARK}) /x, $message);
1404 is("@r","foo", $message);
1405 is($REGMARK, "foo", $message);
1406 unlike('foofoo', qr/foo (*MARK:foo) (*FAIL) /x, $message);
1407 is($REGMARK, '', $message);
1408 is($REGERROR, 'foo', $message);
e425a60b
YO
1409 }
1410
e425a60b 1411 {
de946258 1412 my $message = '\K test';
e425a60b
YO
1413 my $x;
1414 $x = "abc.def.ghi.jkl";
1415 $x =~ s/.*\K\..*//;
de946258 1416 is($x, "abc.def.ghi", $message);
0f289c68 1417
e425a60b
YO
1418 $x = "one two three four";
1419 $x =~ s/o+ \Kthree//g;
de946258 1420 is($x, "one two four", $message);
0f289c68 1421
e425a60b
YO
1422 $x = "abcde";
1423 $x =~ s/(.)\K/$1/g;
de946258 1424 is($x, "aabbccddee", $message);
e425a60b
YO
1425 }
1426
e425a60b
YO
1427 {
1428 sub kt {
1429 return '4' if $_[0] eq '09028623';
1430 }
1431 # Nested EVAL using PL_curpm (via $1 or friends)
1432 my $re;
1433 our $grabit = qr/ ([0-6][0-9]{7}) (??{ kt $1 }) [890] /x;
1434 $re = qr/^ ( (??{ $grabit }) ) $ /x;
1435 my @res = '0902862349' =~ $re;
de26e0cc
NC
1436 is(join ("-", @res), "0902862349",
1437 'PL_curpm is set properly on nested eval');
e425a60b
YO
1438
1439 our $qr = qr/ (o) (??{ $1 }) /x;
1440 ok 'boob'=~/( b (??{ $qr }) b )/x && 1, "PL_curpm, nested eval";
1441 }
1442
e425a60b
YO
1443 {
1444 use charnames ":full";
b7ad6c3e
KW
1445 like "\N{ROMAN NUMERAL ONE}", qr/\p{Alphabetic}/, "I =~ Alphabetic";
1446 like "\N{ROMAN NUMERAL ONE}", qr/\p{Uppercase}/, "I =~ Uppercase";
1447 unlike "\N{ROMAN NUMERAL ONE}", qr/\p{Lowercase}/, "I !~ Lowercase";
1448 like "\N{ROMAN NUMERAL ONE}", qr/\p{IDStart}/, "I =~ ID_Start";
1449 like "\N{ROMAN NUMERAL ONE}", qr/\p{IDContinue}/, "I =~ ID_Continue";
1450 like "\N{SMALL ROMAN NUMERAL ONE}", qr/\p{Alphabetic}/, "i =~ Alphabetic";
1451 unlike "\N{SMALL ROMAN NUMERAL ONE}", qr/\p{Uppercase}/, "i !~ Uppercase";
1452 like "\N{SMALL ROMAN NUMERAL ONE}", qr/\p{Uppercase}/i, "i =~ Uppercase under /i";
1453 unlike "\N{SMALL ROMAN NUMERAL ONE}", qr/\p{Titlecase}/, "i !~ Titlecase";
1454 like "\N{SMALL ROMAN NUMERAL ONE}", qr/\p{Titlecase}/i, "i =~ Titlecase under /i";
1455 like "\N{ROMAN NUMERAL ONE}", qr/\p{Lowercase}/i, "I =~ Lowercase under /i";
1456
1457 like "\N{SMALL ROMAN NUMERAL ONE}", qr/\p{Lowercase}/, "i =~ Lowercase";
1458 like "\N{SMALL ROMAN NUMERAL ONE}", qr/\p{IDStart}/, "i =~ ID_Start";
1459 like "\N{SMALL ROMAN NUMERAL ONE}", qr/\p{IDContinue}/, "i =~ ID_Continue"
e425a60b
YO
1460 }
1461
0ab1ff8e
KW
1462 { # More checking that /i works on the few properties that it makes a
1463 # difference. Uppercase, Lowercase, and Titlecase were done in the
1464 # block above
b7ad6c3e
KW
1465 like "A", qr/\p{PosixUpper}/, "A =~ PosixUpper";
1466 like "A", qr/\p{PosixUpper}/i, "A =~ PosixUpper under /i";
1467 unlike "A", qr/\p{PosixLower}/, "A !~ PosixLower";
1468 like "A", qr/\p{PosixLower}/i, "A =~ PosixLower under /i";
1469 unlike "a", qr/\p{PosixUpper}/, "a !~ PosixUpper";
1470 like "a", qr/\p{PosixUpper}/i, "a =~ PosixUpper under /i";
1471 like "a", qr/\p{PosixLower}/, "a =~ PosixLower";
1472 like "a", qr/\p{PosixLower}/i, "a =~ PosixLower under /i";
1473
1474 like uni_to_native("\xC0"), qr/\p{XPosixUpper}/, "\\xC0 =~ XPosixUpper";
1475 like uni_to_native("\xC0"), qr/\p{XPosixUpper}/i, "\\xC0 =~ XPosixUpper under /i";
1476 unlike uni_to_native("\xC0"), qr/\p{XPosixLower}/, "\\xC0 !~ XPosixLower";
1477 like uni_to_native("\xC0"), qr/\p{XPosixLower}/i, "\\xC0 =~ XPosixLower under /i";
1478 unlike uni_to_native("\xE0"), qr/\p{XPosixUpper}/, "\\xE0 !~ XPosixUpper";
1479 like uni_to_native("\xE0"), qr/\p{XPosixUpper}/i, "\\xE0 =~ XPosixUpper under /i";
1480 like uni_to_native("\xE0"), qr/\p{XPosixLower}/, "\\xE0 =~ XPosixLower";
1481 like uni_to_native("\xE0"), qr/\p{XPosixLower}/i, "\\xE0 =~ XPosixLower under /i";
1482
1483 like uni_to_native("\xC0"), qr/\p{UppercaseLetter}/, "\\xC0 =~ UppercaseLetter";
1484 like uni_to_native("\xC0"), qr/\p{UppercaseLetter}/i, "\\xC0 =~ UppercaseLetter under /i";
1485 unlike uni_to_native("\xC0"), qr/\p{LowercaseLetter}/, "\\xC0 !~ LowercaseLetter";
1486 like uni_to_native("\xC0"), qr/\p{LowercaseLetter}/i, "\\xC0 =~ LowercaseLetter under /i";
1487 unlike uni_to_native("\xC0"), qr/\p{TitlecaseLetter}/, "\\xC0 !~ TitlecaseLetter";
1488 like uni_to_native("\xC0"), qr/\p{TitlecaseLetter}/i, "\\xC0 =~ TitlecaseLetter under /i";
1489 unlike uni_to_native("\xE0"), qr/\p{UppercaseLetter}/, "\\xE0 !~ UppercaseLetter";
1490 like uni_to_native("\xE0"), qr/\p{UppercaseLetter}/i, "\\xE0 =~ UppercaseLetter under /i";
1491 like uni_to_native("\xE0"), qr/\p{LowercaseLetter}/, "\\xE0 =~ LowercaseLetter";
1492 like uni_to_native("\xE0"), qr/\p{LowercaseLetter}/i, "\\xE0 =~ LowercaseLetter under /i";
1493 unlike uni_to_native("\xE0"), qr/\p{TitlecaseLetter}/, "\\xE0 !~ TitlecaseLetter";
1494 like uni_to_native("\xE0"), qr/\p{TitlecaseLetter}/i, "\\xE0 =~ TitlecaseLetter under /i";
1495 unlike "\x{1C5}", qr/\p{UppercaseLetter}/, "\\x{1C5} !~ UppercaseLetter";
1496 like "\x{1C5}", qr/\p{UppercaseLetter}/i, "\\x{1C5} =~ UppercaseLetter under /i";
1497 unlike "\x{1C5}", qr/\p{LowercaseLetter}/, "\\x{1C5} !~ LowercaseLetter";
1498 like "\x{1C5}", qr/\p{LowercaseLetter}/i, "\\x{1C5} =~ LowercaseLetter under /i";
1499 like "\x{1C5}", qr/\p{TitlecaseLetter}/, "\\x{1C5} =~ TitlecaseLetter";
1500 like "\x{1C5}", qr/\p{TitlecaseLetter}/i, "\\x{1C5} =~ TitlecaseLetter under /i";
0ab1ff8e
KW
1501 }
1502
e425a60b
YO
1503 {
1504 # requirement of Unicode Technical Standard #18, 1.7 Code Points
1505 # cf. http://www.unicode.org/reports/tr18/#Supplementary_Characters
1506 for my $u (0x7FF, 0x800, 0xFFFF, 0x10000) {
1507 no warnings 'utf8'; # oops
1508 my $c = chr $u;
1509 my $x = sprintf '%04X', $u;
b7ad6c3e 1510 like "A${c}B", qr/A[\0-\x{10000}]B/, "Unicode range - $x";
e425a60b
YO
1511 }
1512 }
1513
e425a60b 1514 {
fe5492d9
YO
1515 no warnings 'uninitialized';
1516 my $res = "";
e425a60b
YO
1517
1518 if ('1' =~ /(?|(?<digit>1)|(?<digit>2))/) {
1519 $res = "@{$- {digit}}";
1520 }
fe5492d9
YO
1521 is($res, "1 ",
1522 "Check that repeated named captures in branch reset (?|...) work as expected");
1523 if ('2' =~ /(?|(?<digit>1)|(?<digit>2))/) {
1524 $res = "@{$- {digit}}";
1525 }
1526 is($res, " 2",
1527 "Check that repeated named captures in branch reset (?|...) work as expected");
0f289c68 1528
e425a60b
YO
1529 $res = "";
1530 if ('11' =~ /(?|(?<digit>1)|(?<digit>2))(?&digit)/) {
1531 $res = "@{$- {digit}}";
1532 }
fe5492d9 1533 is($res, "1 ",
de26e0cc 1534 "Check that (?&..) to a buffer inside a (?|...) goes to the leftmost");
e425a60b
YO
1535 }
1536
e425a60b
YO
1537 {
1538 use warnings;
de946258 1539 my $message = "ASCII pattern that really is UTF-8";
e425a60b
YO
1540 my @w;
1541 local $SIG {__WARN__} = sub {push @w, "@_"};
0f289c68 1542 my $c = qq (\x{DF});
de946258
NC
1543 like($c, qr/${c}|\x{100}/, $message);
1544 is("@w", '', $message);
0f289c68 1545 }
e425a60b 1546
e425a60b 1547 {
de946258 1548 my $message = "Corruption of match results of qr// across scopes";
e425a60b
YO
1549 my $qr = qr/(fo+)(ba+r)/;
1550 'foobar' =~ /$qr/;
de946258 1551 is("$1$2", "foobar", $message);
e425a60b
YO
1552 {
1553 'foooooobaaaaar' =~ /$qr/;
de946258 1554 is("$1$2", 'foooooobaaaaar', $message);
e425a60b 1555 }
de946258 1556 is("$1$2", "foobar", $message);
e425a60b
YO
1557 }
1558
e425a60b 1559 {
de946258 1560 my $message = "HORIZWS";
e425a60b
YO
1561 local $_ = "\t \r\n \n \t".chr(11)."\n";
1562 s/\H/H/g;
1563 s/\h/h/g;
de946258 1564 is($_, "hhHHhHhhHH", $message);
e425a60b
YO
1565 $_ = "\t \r\n \n \t" . chr (11) . "\n";
1566 utf8::upgrade ($_);
1567 s/\H/H/g;
1568 s/\h/h/g;
de946258 1569 is($_, "hhHHhHhhHH", $message);
0f289c68 1570 }
e425a60b 1571
e425a60b 1572 {
de946258 1573 # Various whitespace special patterns
f36cc39d
KW
1574 my @h = map {chr utf8::unicode_to_native($_) }
1575 0x09, 0x20, 0xa0, 0x1680, 0x2000,
e425a60b
YO
1576 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006,
1577 0x2007, 0x2008, 0x2009, 0x200a, 0x202f, 0x205f,
1578 0x3000;
f36cc39d
KW
1579 my @v = map {chr utf8::unicode_to_native($_) }
1580 0x0a, 0x0b, 0x0c, 0x0d, 0x85, 0x2028,
e425a60b 1581 0x2029;
f36cc39d
KW
1582 my @lb = (uni_to_native("\x0D\x0A"),
1583 map {chr utf8::unicode_to_native($_) }
1584 0x0A .. 0x0D, 0x85, 0x2028, 0x2029);
e425a60b
YO
1585 foreach my $t ([\@h, qr/\h/, qr/\h+/],
1586 [\@v, qr/\v/, qr/\v+/],
1587 [\@lb, qr/\R/, qr/\R+/],) {
1588 my $ary = shift @$t;
1589 foreach my $pat (@$t) {
1590 foreach my $str (@$ary) {
df6841b6
KW
1591 my $temp_str = $str;
1592 $temp_str = display($temp_str);
1593 ok $str =~ /($pat)/, $temp_str . " =~ /($pat)";
1594 my $temp_1 = $1;
1595 is($1, $str, "\$1='" . display($temp_1) . "' eq '" . $temp_str . "' after ($pat)");
e425a60b 1596 utf8::upgrade ($str);
df6841b6
KW
1597 ok $str =~ /($pat)/, "Upgraded " . $temp_str . " =~ /($pat)/";
1598 is($1, $str, "\$1='" . display($temp_1) . "' eq '" . $temp_str . "'(upgraded) after ($pat)");
e425a60b
YO
1599 }
1600 }
1601 }
1602 }
1603
e425a60b 1604 {
de946258 1605 # Check that \\xDF match properly in its various forms
e425a60b
YO
1606 # Test that \xDF matches properly. this is pretty hacky stuff,
1607 # but its actually needed. The malarky with '-' is to prevent
1608 # compilation caching from playing any role in the test.
f36cc39d 1609 my @df = (chr utf8::unicode_to_native(0xDF), '-', chr utf8::unicode_to_native(0xDF));
e425a60b 1610 utf8::upgrade ($df [2]);
f36cc39d 1611 my @strs = ('ss', 'sS', 'Ss', 'SS', chr utf8::unicode_to_native(0xDF));
e425a60b
YO
1612 my @ss = map {("$_", "$_")} @strs;
1613 utf8::upgrade ($ss [$_ * 2 + 1]) for 0 .. $#strs;
1614
1615 for my $ssi (0 .. $#ss) {
1616 for my $dfi (0 .. $#df) {
1617 my $pat = $df [$dfi];
1618 my $str = $ss [$ssi];
1619 my $utf_df = ($dfi > 1) ? 'utf8' : '';
1620 my $utf_ss = ($ssi % 2) ? 'utf8' : '';
f36cc39d
KW
1621 my $sstr; # We hard-code the ebcdic value below to avoid
1622 # perturbing the test
1623 ($sstr = $str) =~ s/\xDF/\\xDF/ if $::IS_ASCII;
1624 ($sstr = $str) =~ s/\x59/\\x59/ if $::IS_EBCDIC;
e425a60b
YO
1625
1626 if ($utf_df || $utf_ss || length ($ss [$ssi]) == 1) {
1627 my $ret = $str =~ /$pat/i;
1628 next if $pat eq '-';
f36cc39d
KW
1629 if ($::IS_ASCII) {
1630 ok $ret, "\"$sstr\" =~ /\\xDF/i " .
1631 "(str is @{[$utf_ss||'latin']}, pat is " .
1632 "@{[$utf_df||'latin']})";
1633 }
1634 else {
1635 ok $ret, "\"$sstr\" =~ /\\x59/i " .
e425a60b
YO
1636 "(str is @{[$utf_ss||'latin']}, pat is " .
1637 "@{[$utf_df||'latin']})";
f36cc39d 1638 }
e425a60b
YO
1639 }
1640 else {
1641 my $ret = $str !~ /$pat/i;
1642 next if $pat eq '-';
f36cc39d
KW
1643 if ($::IS_EBCDIC) {
1644 ok $ret, "\"$sstr\" !~ /\\x59/i " .
e425a60b
YO
1645 "(str is @{[$utf_ss||'latin']}, pat is " .
1646 "@{[$utf_df||'latin']})";
f36cc39d
KW
1647 }
1648 else {
1649 ok $ret, "\"$sstr\" !~ /\\xDF/i " .
1650 "(str is @{[$utf_ss||'latin']}, pat is " .
1651 "@{[$utf_df||'latin']})";
1652 }
e425a60b
YO
1653 }
1654 }
1655 }
1656 }
1657
e425a60b 1658 {
de946258 1659 my $message = "BBC(Bleadperl Breaks CPAN) Today: String::Multibyte";
e425a60b
YO
1660 my $re = qr/(?:[\x00-\xFF]{4})/;
1661 my $hyp = "\0\0\0-";
1662 my $esc = "\0\0\0\\";
1663
1664 my $str = "$esc$hyp$hyp$esc$esc";
1665 my @a = ($str =~ /\G(?:\Q$esc$esc\E|\Q$esc$hyp\E|$re)/g);
1666
de946258 1667 is(@a,3, $message);
e425a60b 1668 local $" = "=";
de946258 1669 is("@a","$esc$hyp=$hyp=$esc$esc", $message);
e425a60b
YO
1670 }
1671
e425a60b
YO
1672 {
1673 # Test for keys in %+ and %-
de946258 1674 my $message = 'Test keys in %+ and %-';
7fba2966
FC
1675 no warnings 'uninitialized';
1676 local $_ = "abcdef";
e425a60b 1677 /(?<foo>a)|(?<foo>b)/;
de946258
NC
1678 is((join ",", sort keys %+), "foo", $message);
1679 is((join ",", sort keys %-), "foo", $message);
1680 is((join ",", sort values %+), "a", $message);
1681 is((join ",", sort map "@$_", values %-), "a ", $message);
e425a60b 1682 /(?<bar>a)(?<bar>b)(?<quux>.)/;
de946258
NC
1683 is((join ",", sort keys %+), "bar,quux", $message);
1684 is((join ",", sort keys %-), "bar,quux", $message);
1685 is((join ",", sort values %+), "a,c", $message); # leftmost
1686 is((join ",", sort map "@$_", values %-), "a b,c", $message);
e425a60b 1687 /(?<un>a)(?<deux>c)?/; # second buffer won't capture
de946258
NC
1688 is((join ",", sort keys %+), "un", $message);
1689 is((join ",", sort keys %-), "deux,un", $message);
1690 is((join ",", sort values %+), "a", $message);
1691 is((join ",", sort map "@$_", values %-), ",a", $message);
e425a60b
YO
1692 }
1693
e425a60b
YO
1694 {
1695 # length() on captures, the numbered ones end up in Perl_magic_len
7fba2966 1696 local $_ = "aoeu " . uni_to_native("\xe6") . "var ook";
e425a60b
YO
1697 /^ \w+ \s (?<eek>\S+)/x;
1698
de26e0cc
NC
1699 is(length $`, 0, q[length $`]);
1700 is(length $', 4, q[length $']);
1701 is(length $&, 9, q[length $&]);
1702 is(length $1, 4, q[length $1]);
1703 is(length $+{eek}, 4, q[length $+{eek} == length $1]);
e425a60b
YO
1704 }
1705
e425a60b
YO
1706 {
1707 my $ok = -1;
1708
1709 $ok = exists ($-{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/;
de26e0cc
NC
1710 is($ok, 1, '$-{x} exists after "bar"=~/(?<x>foo)|bar/');
1711 is(scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/');
1712 is(scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/');
e425a60b
YO
1713
1714 $ok = -1;
1715 $ok = exists ($+{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/;
de26e0cc
NC
1716 is($ok, 0, '$+{x} not exists after "bar"=~/(?<x>foo)|bar/');
1717 is(scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/');
1718 is(scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/');
e425a60b
YO
1719
1720 $ok = -1;
1721 $ok = exists ($-{x}) ? 1 : 0 if 'foo' =~ /(?<x>foo)|bar/;
de26e0cc
NC
1722 is($ok, 1, '$-{x} exists after "foo"=~/(?<x>foo)|bar/');
1723 is(scalar (%+), 1, 'scalar %+ == 1 after "foo"=~/(?<x>foo)|bar/');
1724 is(scalar (%-), 1, 'scalar %- == 1 after "foo"=~/(?<x>foo)|bar/');
e425a60b
YO
1725
1726 $ok = -1;
1727 $ok = exists ($+{x}) ? 1 : 0 if 'foo'=~/(?<x>foo)|bar/;
de26e0cc 1728 is($ok, 1, '$+{x} exists after "foo"=~/(?<x>foo)|bar/');
e425a60b
YO
1729 }
1730
e425a60b
YO
1731 {
1732 local $_;
1733 ($_ = 'abc') =~ /(abc)/g;
0f289c68 1734 $_ = '123';
de26e0cc 1735 is("$1", 'abc', "/g leads to unsafe match vars: $1");
1b474ee3
NC
1736
1737 fresh_perl_is(<<'EOP', ">abc<\n", {}, 'mention $&');
1738$&;
1739my $x;
1740($x='abc')=~/(abc)/g;
1741$x='123';
1742print ">$1<\n";
1743EOP
1744
1b474ee3
NC
1745 fresh_perl_is(<<'EOP', ">abc<\n", {}, 'no mention of $&');
1746my $x;
1747($x='abc')=~/(abc)/g;
1748$x='123';
1749print ">$1<\n";
1750EOP
e425a60b
YO
1751 }
1752
e425a60b 1753 {
de946258 1754 # Message-ID: <20070818091501.7eff4831@r2d2>
e425a60b
YO
1755 my $str = "";
1756 for (0 .. 5) {
1757 my @x;
1758 $str .= "@x"; # this should ALWAYS be the empty string
1759 'a' =~ /(a|)/;
1760 push @x, 1;
1761 }
de26e0cc 1762 is(length $str, 0, "Trie scope error, string should be empty");
e425a60b
YO
1763 $str = "";
1764 my @foo = ('a') x 5;
1765 for (@foo) {
1766 my @bar;
1767 $str .= "@bar";
1768 s/a|/push @bar, 1/e;
1769 }
de26e0cc 1770 is(length $str, 0, "Trie scope error, string should be empty");
e425a60b
YO
1771 }
1772
e425a60b 1773 {
e425a60b 1774# more TRIE/AHOCORASICK problems with mixed utf8 / latin-1 and case folding
f36cc39d
KW
1775 for my $ord (160 .. 255) {
1776 my $chr = utf8::unicode_to_native($ord);
0f289c68
YO
1777 my $chr_byte = chr($chr);
1778 my $chr_utf8 = chr($chr); utf8::upgrade($chr_utf8);
1779 my $rx = qr{$chr_byte|X}i;
b7ad6c3e 1780 like($chr_utf8, $rx, "utf8/latin, codepoint $chr");
0f289c68 1781 }
e425a60b
YO
1782 }
1783
1784 {
e425a60b
YO
1785 our $a = 3; "" =~ /(??{ $a })/;
1786 our $b = $a;
de26e0cc 1787 is($b, $a, "Copy of scalar used for postponed subexpression");
e425a60b
YO
1788 }
1789
e425a60b 1790 {
e425a60b
YO
1791 our @ctl_n = ();
1792 our @plus = ();
1793 our $nested_tags;
1794 $nested_tags = qr{
1795 <
1796 (\w+)
1797 (?{
1798 push @ctl_n,$^N;
1799 push @plus,$+;
1800 })
1801 >
1802 (??{$nested_tags})*
1803 </\s* \w+ \s*>
1804 }x;
1805
1806 my $match = '<bla><blubb></blubb></bla>' =~ m/^$nested_tags$/;
1807 ok $match, 'nested construct matches';
de26e0cc
NC
1808 is("@ctl_n", "bla blubb", '$^N inside of (?{}) works as expected');
1809 is("@plus", "bla blubb", '$+ inside of (?{}) works as expected');
e425a60b
YO
1810 }
1811
e425a60b
YO
1812 SKIP: {
1813 # XXX: This set of tests is essentially broken, POSIX character classes
0f289c68 1814 # should not have differing definitions under Unicode.
e425a60b 1815 # There are property names for that.
ef237063 1816 skip "Tests assume ASCII", 4 unless $::IS_ASCII;
e425a60b
YO
1817
1818 my @notIsPunct = grep {/[[:punct:]]/ and not /\p{IsPunct}/}
1819 map {chr} 0x20 .. 0x7f;
1a3f15c1 1820 is(join ('', @notIsPunct), '$+<=>^`|~',
de26e0cc 1821 '[:punct:] disagrees with IsPunct on Symbols');
e425a60b
YO
1822
1823 my @isPrint = grep {not /[[:print:]]/ and /\p{IsPrint}/}
1824 map {chr} 0 .. 0x1f, 0x7f .. 0x9f;
de26e0cc
NC
1825 is(join ('', @isPrint), "",
1826 'IsPrint agrees with [:print:] on control characters');
e425a60b
YO
1827
1828 my @isPunct = grep {/[[:punct:]]/ != /\p{IsPunct}/}
1829 map {chr} 0x80 .. 0xff;
7620cb10 1830 is(join ('', @isPunct), "\xa1\xa7\xab\xb6\xb7\xbb\xbf", # ¡ « · » ¿
de26e0cc 1831 'IsPunct disagrees with [:punct:] outside ASCII');
e425a60b
YO
1832
1833 my @isPunctLatin1 = eval q {
3fc5553b 1834 grep {/[[:punct:]]/u != /\p{IsPunct}/} map {chr} 0x80 .. 0xff;
e425a60b
YO
1835 };
1836 skip "Eval failed ($@)", 1 if $@;
1837 skip "PERL_LEGACY_UNICODE_CHARCLASS_MAPPINGS set to 0", 1
1838 if !$ENV{PERL_TEST_LEGACY_POSIX_CC};
de26e0cc
NC
1839 is(join ('', @isPunctLatin1), '',
1840 'IsPunct agrees with [:punct:] with explicit Latin1');
0f289c68 1841 }
d1c771f5 1842
d1c771f5
B
1843 {
1844 # Tests for [#perl 71942]
1845 our $count_a;
1846 our $count_b;
1847
1848 my $c = 0;
1849 for my $re (
1850# [
1851# should match?,
1852# input string,
1853# re 1,
1854# re 2,
1855# expected values of count_a and count_b,
1856# ]
1857 [
1858 0,
1859 "xababz",
1860 qr/a+(?{$count_a++})b?(*COMMIT)(*FAIL)/,
1861 qr/a+(?{$count_b++})b?(*COMMIT)z/,
1862 1,
1863 ],
1864 [
1865 0,
1866 "xababz",
1867 qr/a+(?{$count_a++})b?(*COMMIT)\s*(*FAIL)/,
1868 qr/a+(?{$count_b++})b?(*COMMIT)\s*z/,
1869 1,
1870 ],
1871 [
1872 0,
1873 "xababz",
1874 qr/a+(?{$count_a++})(?:b|)?(*COMMIT)(*FAIL)/,
1875 qr/a+(?{$count_b++})(?:b|)?(*COMMIT)z/,
1876 1,
1877 ],
1878 [
1879 0,
1880 "xababz",
1881 qr/a+(?{$count_a++})b{0,6}(*COMMIT)(*FAIL)/,
1882 qr/a+(?{$count_b++})b{0,6}(*COMMIT)z/,
1883 1,
1884 ],
1885 [
1886 0,
1887 "xabcabcz",
1888 qr/a+(?{$count_a++})(bc){0,6}(*COMMIT)(*FAIL)/,
1889 qr/a+(?{$count_b++})(bc){0,6}(*COMMIT)z/,
1890 1,
1891 ],
1892 [
1893 0,
1894 "xabcabcz",
1895 qr/a+(?{$count_a++})(bc*){0,6}(*COMMIT)(*FAIL)/,
1896 qr/a+(?{$count_b++})(bc*){0,6}(*COMMIT)z/,
1897 1,
1898 ],
1899
1900
1901 [
1902 0,
1903 "aaaabtz",
1904 qr/a+(?{$count_a++})b?(*PRUNE)(*FAIL)/,
1905 qr/a+(?{$count_b++})b?(*PRUNE)z/,
1906 4,
1907 ],
1908 [
1909 0,
1910 "aaaabtz",
1911 qr/a+(?{$count_a++})b?(*PRUNE)\s*(*FAIL)/,
1912 qr/a+(?{$count_b++})b?(*PRUNE)\s*z/,
1913 4,
1914 ],
1915 [
1916 0,
1917 "aaaabtz",
1918 qr/a+(?{$count_a++})(?:b|)(*PRUNE)(*FAIL)/,
1919 qr/a+(?{$count_b++})(?:b|)(*PRUNE)z/,
1920 4,
1921 ],
1922 [
1923 0,
1924 "aaaabtz",
1925 qr/a+(?{$count_a++})b{0,6}(*PRUNE)(*FAIL)/,
1926 qr/a+(?{$count_b++})b{0,6}(*PRUNE)z/,
1927 4,
1928 ],
1929 [
1930 0,
1931 "aaaabctz",
1932 qr/a+(?{$count_a++})(bc){0,6}(*PRUNE)(*FAIL)/,
1933 qr/a+(?{$count_b++})(bc){0,6}(*PRUNE)z/,
1934 4,
1935 ],
1936 [
1937 0,
1938 "aaaabctz",
1939 qr/a+(?{$count_a++})(bc*){0,6}(*PRUNE)(*FAIL)/,
1940 qr/a+(?{$count_b++})(bc*){0,6}(*PRUNE)z/,
1941 4,
1942 ],
1943
1944 [
1945 0,
1946 "aaabaaab",
1947 qr/a+(?{$count_a++;})b?(*SKIP)(*FAIL)/,
1948 qr/a+(?{$count_b++;})b?(*SKIP)z/,
1949 2,
1950 ],
1951 [
1952 0,
1953 "aaabaaab",
1954 qr/a+(?{$count_a++;})b?(*SKIP)\s*(*FAIL)/,
1955 qr/a+(?{$count_b++;})b?(*SKIP)\s*z/,
1956 2,
1957 ],
1958 [
1959 0,
1960 "aaabaaab",
1961 qr/a+(?{$count_a++;})(?:b|)(*SKIP)(*FAIL)/,
1962 qr/a+(?{$count_b++;})(?:b|)(*SKIP)z/,
1963 2,
1964 ],
1965 [
1966 0,
1967 "aaabaaab",
1968 qr/a+(?{$count_a++;})b{0,6}(*SKIP)(*FAIL)/,
1969 qr/a+(?{$count_b++;})b{0,6}(*SKIP)z/,
1970 2,
1971 ],
1972 [
1973 0,
1974 "aaabcaaabc",
1975 qr/a+(?{$count_a++;})(bc){0,6}(*SKIP)(*FAIL)/,
1976 qr/a+(?{$count_b++;})(bc){0,6}(*SKIP)z/,
1977 2,
1978 ],
1979 [
1980 0,
1981 "aaabcaaabc",
1982 qr/a+(?{$count_a++;})(bc*){0,6}(*SKIP)(*FAIL)/,
1983 qr/a+(?{$count_b++;})(bc*){0,6}(*SKIP)z/,
1984 2,
1985 ],
1986
1987
1988 [
1989 0,
1990 "aaddbdaabyzc",
1991 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) (*FAIL) \s* c \1 /x,
1992 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) z \s* c \1 /x,
1993 4,
1994 ],
1995 [
1996 0,
1997 "aaddbdaabyzc",
1998 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) \s* (*FAIL) \s* c \1 /x,
1999 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) \s* z \s* c \1 /x,
2000 4,
2001 ],
2002 [
2003 0,
2004 "aaddbdaabyzc",
2005 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? (?:b|) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2006 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? (?:b|) (*SKIP:T1) z \s* c \1 /x,
2007 4,
2008 ],
2009 [
2010 0,
2011 "aaddbdaabyzc",
2012 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? b{0,6} (*SKIP:T1) (*FAIL) \s* c \1 /x,
2013 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? b{0,6} (*SKIP:T1) z \s* c \1 /x,
2014 4,
2015 ],
2016 [
2017 0,
2018 "aaddbcdaabcyzc",
2019 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? (bc){0,6} (*SKIP:T1) (*FAIL) \s* c \1 /x,
2020 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? (bc){0,6} (*SKIP:T1) z \s* c \1 /x,
2021 4,
2022 ],
2023 [
2024 0,
2025 "aaddbcdaabcyzc",
2026 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? (bc*){0,6} (*SKIP:T1) (*FAIL) \s* c \1 /x,
2027 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? (bc*){0,6} (*SKIP:T1) z \s* c \1 /x,
2028 4,
2029 ],
2030
2031
2032 [
2033 0,
2034 "aaaaddbdaabyzc",
2035 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2036 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2037 2,
2038 ],
2039 [
2040 0,
2041 "aaaaddbdaabyzc",
2042 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) \s* (*FAIL) \s* c \1 /x,
2043 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) \s* z \s* c \1 /x,
2044 2,
2045 ],
2046 [
2047 0,
2048 "aaaaddbdaabyzc",
2049 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? (?:b|) (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2050 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? (?:b|) (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2051 2,
2052 ],
2053 [
2054 0,
2055 "aaaaddbdaabyzc",
2056 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? b{0,6} (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2057 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? b{0,6} (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2058 2,
2059 ],
2060 [
2061 0,
2062 "aaaaddbcdaabcyzc",
2063 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? (bc){0,6} (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2064 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? (bc){0,6} (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2065 2,
2066 ],
2067 [
2068 0,
2069 "aaaaddbcdaabcyzc",
2070 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? (bc*){0,6} (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x,
2071 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? (bc*){0,6} (*MARK:T1) (*SKIP:T1) z \s* c \1 /x,
2072 2,
2073 ],
2074
2075
2076 [
2077 0,
2078 "AbcdCBefgBhiBqz",
2079 qr/(A (.*) (?{ $count_a++ }) C? (*THEN) | A D) (*FAIL)/x,
2080 qr/(A (.*) (?{ $count_b++ }) C? (*THEN) | A D) z/x,
2081 1,
2082 ],
2083 [
2084 0,
2085 "AbcdCBefgBhiBqz",
2086 qr/(A (.*) (?{ $count_a++ }) C? (*THEN) | A D) \s* (*FAIL)/x,
2087 qr/(A (.*) (?{ $count_b++ }) C? (*THEN) | A D) \s* z/x,
2088 1,
2089 ],
2090 [
2091 0,
2092 "AbcdCBefgBhiBqz",
2093 qr/(A (.*) (?{ $count_a++ }) (?:C|) (*THEN) | A D) (*FAIL)/x,
2094 qr/(A (.*) (?{ $count_b++ }) (?:C|) (*THEN) | A D) z/x,
2095 1,
2096 ],
2097 [
2098 0,
2099 "AbcdCBefgBhiBqz",
2100 qr/(A (.*) (?{ $count_a++ }) C{0,6} (*THEN) | A D) (*FAIL)/x,
2101 qr/(A (.*) (?{ $count_b++ }) C{0,6} (*THEN) | A D) z/x,
2102 1,
2103 ],
2104 [
2105 0,
2106 "AbcdCEBefgBhiBqz",
2107 qr/(A (.*) (?{ $count_a++ }) (CE){0,6} (*THEN) | A D) (*FAIL)/x,
2108 qr/(A (.*) (?{ $count_b++ }) (CE){0,6} (*THEN) | A D) z/x,
2109 1,
2110 ],
2111 [
2112 0,
2113 "AbcdCBefgBhiBqz",
2114 qr/(A (.*) (?{ $count_a++ }) (CE*){0,6} (*THEN) | A D) (*FAIL)/x,
2115 qr/(A (.*) (?{ $count_b++ }) (CE*){0,6} (*THEN) | A D) z/x,
2116 1,
2117 ],
2118 ) {
2119 $c++;
2120 $count_a = 0;
2121 $count_b = 0;
2122
2123 my $match_a = ($re->[1] =~ $re->[2]) || 0;
2124 my $match_b = ($re->[1] =~ $re->[3]) || 0;
2125
de26e0cc
NC
2126 is($match_a, $re->[0], "match a " . ($re->[0] ? "succeeded" : "failed") . " ($c)");
2127 is($match_b, $re->[0], "match b " . ($re->[0] ? "succeeded" : "failed") . " ($c)");
2128 is($count_a, $re->[4], "count a ($c)");
2129 is($count_b, $re->[4], "count b ($c)");
d1c771f5
B
2130 }
2131 }
e425a60b 2132
b57e4118
KW
2133 { # Bleadperl v5.13.8-292-gf56b639 breaks NEZUMI/Unicode-LineBreak-1.011
2134 # \xdf in lookbehind failed to compile as is multi-char fold
14358a41
NC
2135 my $message = "Lookbehind with \\xdf matchable compiles";
2136 my $r = eval 'qr{
b57e4118
KW
2137 (?u: (?<=^url:) |
2138 (?<=[/]) (?=[^/]) |
2139 (?<=[^-.]) (?=[-~.,_?\#%=&]) |
2140 (?<=[=&]) (?=.)
14358a41
NC
2141 )}iox';
2142 is($@, '', $message);
bbce3ca6 2143 object_ok($r, 'Regexp', $message);
b57e4118
KW
2144 }
2145
84193928 2146 # RT #82610
8f46dbea 2147 like 'foo/file.fob', qr,^(?=[^\.])[^/]*/(?=[^\.])[^/]*\.fo[^/]$,;
84193928 2148
295c2f7d 2149 { # This was failing unless an explicit /d was added
f36cc39d 2150 my $E0 = uni_to_native("\xE0");
b6990aaa 2151 utf8::upgrade($E0);
f36cc39d 2152 my $p = qr/[_$E0]/i;
f36cc39d 2153 like(uni_to_native("\xC0"), qr/$p/, "Verify \"\\xC0\" =~ /[\\xE0_]/i; pattern in utf8");
295c2f7d
KW
2154 }
2155
b7ad6c3e 2156 like "x", qr/\A(?>(?:(?:)A|B|C?x))\z/,
a40630bf 2157 "Check TRIE does not overwrite EXACT following NOTHING at start - RT #111842";
c221a219 2158
26faadbd 2159 {
9e3a0e9b 2160 my $single = "z";
26faadbd
KW
2161 my $upper = "\x{390}"; # Fold is 3 chars.
2162 my $multi = CORE::fc($upper);
2163
2164 my $failed = 0;
2165
2166 # Try forcing a node to be split, with a multi-char fold at the
2167 # boundary
2168 for my $repeat (1 .. 300) {
2169 my $string = $single x $repeat;
2170 my $lhs = $string . $upper;
2171 if ($lhs !~ m/$string$multi/i) {
2172 $failed = $repeat;
2173 last;
2174 }
2175 }
2176 ok(! $failed, "Matched multi-char fold across EXACTFish node boundaries; if failed, was at count $failed");
2177
b9c48b5b
KW
2178 $failed = 0;
2179 for my $repeat (1 .. 300) {
2180 my $string = $single x $repeat;
2181 my $lhs = $string . "\N{LATIN SMALL LIGATURE FFI}";
2182 if ($lhs !~ m/${string}ff\N{LATIN SMALL LETTER I}/i) {
2183 $failed = $repeat;
2184 last;
2185 }
2186 }
2187 ok(! $failed, "Matched multi-char fold across EXACTFish node boundaries; if failed, was at count $failed");
2188
2189 $failed = 0;
2190 for my $repeat (1 .. 300) {
2191 my $string = $single x $repeat;
2192 my $lhs = $string . "\N{LATIN SMALL LIGATURE FFL}";
2193 if ($lhs !~ m/${string}ff\N{U+6c}/i) {
2194 $failed = $repeat;
2195 last;
2196 }
2197 }
2198 ok(! $failed, "Matched multi-char fold across EXACTFish node boundaries; if failed, was at count $failed");
88b3a463
KW
2199
2200 # This tests that under /d matching that an 'ss' split across two
2201 # parts of a node doesn't end up turning into something that matches
2202 # \xDF unless it is in utf8.
2203 $failed = 0;
2204 $single = 'a'; # Is non-terminal multi-char fold char
2205 for my $repeat (1 .. 300) {
2206 my $string = $single x $repeat;
2207 my $lhs = "$string\N{LATIN SMALL LETTER SHARP S}";
2208 utf8::downgrade($lhs);
2209 $string .= "s";
2210 if ($lhs =~ m/${string}s/di) {
2211 $failed = $repeat;
2212 last;
2213 }
2214 }
2215 ok(! $failed, "Matched multi-char fold 'ss' across EXACTF node boundaries; if failed, was at count $failed");
73976260
KW
2216
2217 for my $non_finals ("t", "ft", "ift", "sift") {
2218 my $base_pat = $non_finals . "enKalt"; # (The tail is taken from
2219 # the trouble ticket, is
2220 # arbitrary)
2221 for my $utf8 ("non-UTF-8", "UTF-8") {
2222
2223 # Try at different lengths to be sure to get a node boundary
2224 for my $repeat (120 .. 270) { # [perl #133756]
2225 my $head = ("b" x $repeat) . "\xDC";
2226 my $pat = $base_pat;
2227 utf8::upgrade($pat) if $utf8 eq "UTF-8";
2228 $pat = $head . $pat;
2229 my $text = $head . $base_pat;
2230
2231 if ($text !~ /$pat/i) {
2232 $failed = $repeat;
2233 last;
2234 }
2235 }
2236
2237 ok(! $failed, "A non-final fold character "
2238 . (length($non_finals) - 1)
2239 . " characters from the end of an EXACTFish"
2240 . " $utf8 pattern works; if failed, was at count $failed");
2241 }
2242 }
26faadbd
KW
2243 }
2244
2b233a8f 2245 {
2b233a8f
KW
2246 fresh_perl_is('print eval "\"\x{101}\" =~ /[[:lower:]]/", "\n"; print eval "\"\x{100}\" =~ /[[:lower:]]/i", "\n";',
2247 "1\n1", # Both re's should match
20e5bab4 2248 {},
2b233a8f
KW
2249 "get [:lower:] swash in first eval; test under /i in second");
2250 }
2251
c5de0829 2252 {
3553f4fa
DM
2253 fresh_perl_is(<<'EOF',
2254 my $s = "\x{41c}";
2255 $s =~ /(.*)/ or die;
2256 $ls = lc $1;
2257 print $ls eq lc $s ? "good\n" : "bad: [$ls]\n";
2258EOF
2259 "good\n",
2260 {},
2261 "swash triggered by lc() doesn't corrupt \$1"
2262 );
2263 }
2264
2265 {
c5de0829 2266 #' RT #119075
fd2268bc 2267 no warnings 'regexp'; # Silence "has useless greediness modifier"
c5de0829
JK
2268 local $@;
2269 eval { /a{0}?/; };
2270 ok(! $@,
2271 "PCRE regression test: No 'Quantifier follows nothing in regex' warning");
2272
2273 }
2274
709d08c2
KW
2275 {
2276 unlike("\xB5", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
2277 like("\xB6", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
2278 unlike("\xB7", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
2279 like("\xB5", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
2280 unlike("\xB6", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
2281 like("\xB7", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
2282
2283 unlike("_\xB5", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
2284 like("_\xB6", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
2285 unlike("_\xB7", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
2286 like("_\xB5", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
2287 unlike("_\xB6", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
2288 like("_\xB7", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
2289 }
2290
2291 # These are defined later, so won't be known at regex compile time above
2292 sub IsMyRuntimeProperty {
2293 return "B6\n";
2294 }
2295
2296 sub IsntMyRuntimeProperty {
2297 return "!B6\n";
2298 }
2299
80836a6e
KW
2300 { # [perl 121777]
2301 my $regex;
2302 { package Some;
2303 # define a Unicode propertyIs_q
2304 sub Is_q
2305 {
2306 sprintf '%x', ord 'q'
2307 }
2308 $regex = qr/\p{Is_q}/;
2309
2310 # If we uncomment the following line, prior to the patch that
de68ac66
KW
2311 # fixed this, everything would work because we would have expanded
2312 # the property by the time the regex in the 'like' below got
2313 # compiled.
80836a6e
KW
2314 #'q' =~ $regex;
2315 }
2316
2317 like('q', $regex, 'User-defined property matches outside package');
c0611711
KW
2318
2319 package Some {
2320 main::like('abcq', qr/abc$regex/, 'Run-time compiled in-package user-defined property matches');
2321 }
80836a6e
KW
2322 }
2323
bc031a7d
KW
2324 { # From Lingua::Stem::UniNE; no ticket filed but related to #121778
2325 use utf8;
2326 my $word = 'рабта';
2327 $word =~ s{ (?:
2328 ия # definite articles for nouns:
2329 | ът # ∙ masculine
2330 | та # ∙ feminine
2331 | то # ∙ neutral
2332 | те # ∙ plural
2333 ) $ }{}x;
2334 is($word, 'раб', "Handles UTF8 trie correctly");
2335 }
2336
842a9d21
KW
2337 { # [perl #122460]
2338 my $a = "rdvark";
2339 $a =~ /(?{})(?=[A-Za-z0-9_])a*?/g;
2340 is (pos $a, 0, "optimizer correctly thinks (?=...) is 0-length");
2341 }
2342
4cbd7e22
FC
2343 { # [perl #123417] multi-char \N{...} tripping roundly
2344 use Cname;
2345 my $qr = qr$(\N{foo})$;
2346 "afoot" =~ eval "qr/$qr/";
2347 is "$1" || $@, "foo", 'multichar \N{...} stringified and retoked';
2348 }
2349
7195e5da
KW
2350 is (scalar split(/\b{sb}/, "Don't think twice. It's all right."),
2351 2, '\b{wb} splits sentences correctly');
2352
39ce401c
KW
2353 ok "my/dir/audio_07.mp3" =~
2354 qr/(.*)\/(.*)\/(.*)\.(?<=(?=(?:\.(?!\d+\b)\w{1,4}$)$)\.)(.*)$()/,
2355 "[perl #133948]";
2356
4cbd7e22 2357
de085464
KW
2358 # !!! NOTE! Keep the following tests last -- they may crash perl
2359
e425a60b 2360 print "# Tests that follow may crash perl\n";
e425a60b
YO
2361 {
2362 eval '/\k/';
b7ad6c3e 2363 like $@, qr/\QSequence \k... not terminated in regex;\E/,
e425a60b
YO
2364 'Lone \k not allowed';
2365 }
2366
e425a60b 2367 {
de946258 2368 my $message = "Substitution with lookahead (possible segv)";
e425a60b
YO
2369 $_ = "ns1ns1ns1";
2370 s/ns(?=\d)/ns_/g;
de946258 2371 is($_, "ns_1ns_1ns_1", $message);
e425a60b
YO
2372 $_ = "ns1";
2373 s/ns(?=\d)/ns_/;
de946258 2374 is($_, "ns_1", $message);
e425a60b
YO
2375 $_ = "123";
2376 s/(?=\d+)|(?<=\d)/!Bang!/g;
de946258 2377 is($_, "!Bang!1!Bang!2!Bang!3!Bang!", $message);
e425a60b
YO
2378 }
2379
6182169b
KW
2380 {
2381 # Earlier versions of Perl said this was fatal.
de946258 2382 my $message = "U+0FFFF shouldn't crash the regex engine";
6182169b
KW
2383 no warnings 'utf8';
2384 my $a = eval "chr(65535)";
2385 use warnings;
2386 my $warning_message;
2387 local $SIG{__WARN__} = sub { $warning_message = $_[0] };
2388 eval $a =~ /[a-z]/;
de946258 2389 ok(1, $message); # If it didn't crash, it worked.
6182169b 2390 }
b57e4118 2391
91d110e0 2392 { # Was looping
ec8902ce 2393 watchdog(10);
6438af90 2394 like("\x{00DF}", qr/[\x{1E9E}_]*/i, "\"\\x{00DF}\" =~ /[\\x{1E9E}_]*/i was looping");
d44172c6 2395 watchdog(0);
6438af90
KW
2396 }
2397
f9126265
KW
2398 { # Bug #90536, caused failed assertion
2399 unlike("s\N{U+DF}", qr/^\x{00DF}/i, "\"s\\N{U+DF}\", qr/^\\x{00DF}/i");
2400 }
2401
361ee0fe 2402 # User-defined Unicode properties to match above-Unicode code points
56a85032 2403 sub Is_31_Bit_Super { return "110000\t7FFFFFFF\n" }
361ee0fe 2404 sub Is_Portable_Super { return '!utf8::Any' } # Matches beyond 32 bits
45d91b83
KW
2405
2406 { # Assertion was failing on on 64-bit platforms; just didn't work on 32.
2407 no warnings qw(non_unicode portable);
2408 use Config;
2409
2410 # We use 'ok' instead of 'like' because the warnings are lexically
2411 # scoped, and want to turn them off, so have to do the match in this
c0236afe 2412 # scope.
76513bdc 2413 if ($Config{uvsize} < 8) {
8f46dbea 2414 like(chr(0x7FFF_FFFE), qr/\p{Is_31_Bit_Super}/,
56a85032 2415 "chr(0x7FFF_FFFE) can match a Unicode property");
8f46dbea 2416 like(chr(0x7FFF_FFFF), qr/\p{Is_31_Bit_Super}/,
56a85032
KW
2417 "chr(0x7FFF_FFFF) can match a Unicode property");
2418 my $p = qr/^[\x{7FFF_FFFF}]$/;
8f46dbea 2419 like(chr(0x7FFF_FFFF), qr/$p/,
56a85032 2420 "chr(0x7FFF_FFFF) can match itself in a [class]");
8f46dbea 2421 like(chr(0x7FFF_FFFF), qr/$p/, # Tests any caching
56a85032 2422 "chr(0x7FFF_FFFF) can match itself in a [class] subsequently");
84ea5ef6 2423 }
76513bdc
KW
2424 else {
2425 no warnings 'overflow';
8f46dbea 2426 like(chr(0x7FFF_FFFF_FFFF_FFFE), qr/\p{Is_Portable_Super}/,
56a85032 2427 "chr(0x7FFF_FFFF_FFFF_FFFE) can match a Unicode property");
8f46dbea 2428 like(chr(0x7FFF_FFFF_FFFF_FFFF), qr/^\p{Is_Portable_Super}$/,
56a85032 2429 "chr(0x7FFF_FFFF_FFFF_FFFF) can match a Unicode property");
76513bdc 2430
1a9f5e2a 2431 my $p = eval 'qr/^\x{7FFF_FFFF_FFFF_FFFF}$/';
8f46dbea 2432 like(chr(0x7FFF_FFFF_FFFF_FFFF), qr/$p/,
56a85032 2433 "chr(0x7FFF_FFFF_FFFF_FFFF) can match itself in a [class]");
8f46dbea 2434 like(chr(0x7FFF_FFFF_FFFF_FFFF), qr/$p/, # Tests any caching
56a85032 2435 "chr(0x7FFF_FFFF_FFFF_FFFF) can match itself in a [class] subsequently");
76513bdc
KW
2436
2437 # This test is because something was declared as 32 bits, but
2438 # should have been cast to 64; only a problem where
2439 # sizeof(STRLEN) != sizeof(UV)
8f46dbea
KW
2440 unlike(chr(0x7FFF_FFFF_FFFF_FFFE), qr/\p{Is_31_Bit_Super}/,
2441 "chr(0x7FFF_FFFF_FFFF_FFFE) shouldn't match a range ending in 0x7FFF_FFFF");
76513bdc 2442 }
45d91b83
KW
2443 }
2444
9d501133
KW
2445 { # [perl #112530], the code below caused a panic
2446 sub InFoo { "a\tb\n9\ta\n" }
f36cc39d 2447 like(chr(0xA), qr/\p{InFoo}/,
9d501133
KW
2448 "Overlapping ranges in user-defined properties");
2449 }
2450
512c0f5a
KW
2451 { # [perl #125990], the final 2 tests below each caused a panic.
2452 # The \0's are not necessary; it could be a printable character
2453 # instead, but were in the ticket, so using them.
2454 my $sharp_s = chr utf8::unicode_to_native(0xdf);
2455 my $string = ("\0" x 8)
2456 . ($sharp_s x 3)
2457 . ("\0" x 42)
2458 . "ý";
2459 my $folded_string = ("\0" x 8)
2460 . ("ss" x 3)
2461 . ("\0" x 42)
2462 . "ý";
2463 utf8::downgrade($string);
2464 utf8::downgrade($folded_string);
2465
37ee5518 2466 use Cname;
512c0f5a
KW
2467 like($string, qr/$string/i, "LATIN SMALL SHARP S matches itself under /id");
2468 unlike($folded_string, qr/$string/i, "LATIN SMALL SHARP S doesn't match 'ss' under /di");
37ee5518
KW
2469 like($folded_string, qr/\N{EMPTY-STR}$string/i, "\\N{} earlier than LATIN SMALL SHARP S transforms /di into /ui, matches 'ss'");
2470 like($folded_string, qr/$string\N{EMPTY-STR}/i, "\\N{} after LATIN SMALL SHARP S transforms /di into /ui, matches 'ss'");
512c0f5a
KW
2471 }
2472
90c17285 2473 { # [perl #126606 crashed the interpreter
37ee5518
KW
2474 use Cname;
2475 like("sS", qr/\N{EMPTY-STR}Ss|/i, '\N{} with empty branch alternation works');
945961fd 2476 like("sS", qr'\N{EMPTY-STR}Ss|'i, '\N{} with empty branch alternation works');
90c17285
KW
2477 }
2478
2e3a23da
KW
2479 { # Regexp:Grammars was broken:
2480 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2013-06/msg01290.html
2481 fresh_perl_like('use warnings; "abc" =~ qr{(?&foo){0}abc(?<foo>)}',
aaa63dae 2482 qr/Quantifier unexpected on zero-length expression/,
20e5bab4 2483 {},
2e3a23da
KW
2484 'No segfault on qr{(?&foo){0}abc(?<foo>)}');
2485 }
2486
668fcfea
TC
2487 SKIP:
2488 { # [perl #125826] buffer overflow in TRIE_STORE_REVCHAR
2489 # (during compilation, so use a fresh perl)
2490 $Config{uvsize} == 8
2491 or skip("need large code-points for this test", 1);
760c7c2f 2492
d22ec717 2493 fresh_perl_is('/\x{E000000000}|/ and print qq(ok\n)', "ok\n", {},
668fcfea
TC
2494 "buffer overflow in TRIE_STORE_REVCHAR");
2495 }
2496
8571c4b0
KW
2497 {
2498 fresh_perl_like('use warnings; s\00(?(?!00000000000000000000000000·000000)\500000000\00000000000000000000000000000000000000000000000000000·00000000000000000000000000000000\00',
2499 qr/Switch \(\?\(condition\)\.\.\. not terminated/,
2500 {},
2501 'No segfault [perl #126886]');
2502 }
2503
553fa53c
JK
2504 {
2505 # [perl 130010] Downstream application texinfo started to report panics
2506 # as of commit a5540cf.
2507
2508 runperl( prog => 'A::xx(); package A; sub InFullwidth{ return qq|\n| } sub xx { split /[^\s\p{InFullwidth}]/, q|x| }' );
2509 ok(! $?, "User-defined pattern did not cause panic [perl 130010]");
2510 }
2511
b92b2705
KW
2512 { # [perl #133999] Previously assertion failure
2513 fresh_perl_like('0 =~ /\p{nv:(\B(*COMMIT)C+)}/',
2514 qr/No Unicode property value wildcard matches/,
2515 {},
2516 "Assertion failure with *COMMIT and wildcard property");
2517 }
2518
11b48e76
KW
2519 { # [perl #134029] Previously assertion failure
2520 fresh_perl_like('qr/\p{upper:]}|\337(?|ss)|)(?0/',
2521 qr/Unicode property wildcard not terminated/,
2522 {},
2523 "Assertion failure with single character wildcard");
2524 }
2525
8c9c2723
KW
2526 { # [perl #134034] Previously assertion failure
2527 fresh_perl_is('use utf8; q!Ȧिम한글💣΢ყაოსაა!=~/(?li)\b{wb}\B(*COMMIT)0/;',
2528 "", {}, "*COMMIT caused positioning beyond EOS");
2529 }
2530
d013a11f
KW
2531 { # [GH #17486] Previously assertion failure
2532 fresh_perl_is('0=~/(?iaa)ss\337(?0)|/',
2533 "", {}, "EXACTFUP node isn't changed into something else");
2534 }
2535
daa74010
KW
2536 { # [GH #17593]
2537 fresh_perl_is('qr/((?+2147483647))/',
2538 "Invalid reference to group in regex; marked by <--"
2539 . " HERE in m/((?+2147483647) <-- HERE )/ at - line 1.",
2540 {}, "integer overflow, undefined behavior in ASAN");
99d2ace5
KW
2541 fresh_perl_is('qr/((?-2147483647))/',
2542 "Reference to nonexistent group in regex; marked by <--"
2543 . " HERE in m/((?-2147483647) <-- HERE )/ at - line 1.",
2544 {}, "Large negative relative capture group");
5c1c42cb
KW
2545 fresh_perl_is('qr/((?+18446744073709551615))/',
2546 "Invalid reference to group in regex; marked by <--"
2547 . " HERE in m/((?+18446744073709551615 <-- HERE ))/ at -"
2548 . " line 1.",
2549 {}, "Too large relative group number");
2550 fresh_perl_is('qr/((?-18446744073709551615))/',
2551 "Invalid reference to group in regex; marked by <--"
2552 . " HERE in m/((?-18446744073709551615 <-- HERE ))/ at -"
2553 . " line 1.",
2554 {}, "Too large negative relative group number");
99d2ace5
KW
2555 }
2556
07b23240
KW
2557 { # GH #17734, ASAN use after free
2558 fresh_perl_like('no warnings "experimental::uniprop_wildcards";
2559 my $re = q<[[\p{name=/[Y-]+Z/}]]>;
2560 eval { "\N{BYZANTINE MUSICAL SYMBOL PSILI}"
2561 =~ /$re/ }; print $@ if $@; print "Done\n";',
2562 qr/Done/,
2563 {}, "GH #17734");
2564 }
2565
bb58640a
KW
2566 { # GH $17278 assertion fails
2567 fresh_perl_is('use locale;
2568 my $A_grave = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";
bb58640a 2569 my $a_grave = "\N{LATIN SMALL LETTER A WITH GRAVE}";
bb58640a
KW
2570
2571 my $z="q!$a_grave! =~ m!(?^i)[$A_grave]!";
bb58640a
KW
2572 print eval $z, "\n";',
2573 1,
2574 {}, "GH #17278");
2575 }
33fc7377
YO
2576
2577 for my $try ( 1 .. 10 ) {
2578 # GH $19350 assertion fails - run 10 times as this bug is a heisenbug
2579 # and does not always fail, but should fail at least once in 10 tries.
2580 fresh_perl_is('use re Debug=>"ALL";qr{(?{a})(?<b>\g{c}})',
2581 <<'EOF_DEBUG_OUT',
2582Assembling pattern from 2 elements
2583Compiling REx "(?{a})(?<b>\g{c}"
2584Starting parse and generation
2585<(?{a})(?<b>>...| 1| reg
2586 | | brnc
2587 | | piec
2588 | | atom
2589<?{a})(?<b>\>...| | reg
2590<(?<b>\g{c}> | 4| piec
2591 | | atom
2592<?<b>\g{c}> | | reg
2593 | | Setting open paren #1 to 4
2594<\g{c}> | 6| brnc
2595 | | piec
2596 | | atom
d78630f1
YO
2597<> | 9| tail~ OPEN1 'b' (4) -> REFN
2598 | | Setting close paren #1 to 9
2599 | 11| lsbr~ tying lastbr REFN <1> (6) to ender CLOSE1 'b' (9) offset 3
2600 | | tail~ REFN <1> (6) -> CLOSE
33fc7377
YO
2601Unmatched ( in regex; marked by <-- HERE in m/(?{a})( <-- HERE ?<b>\g{c}/ at - line 1.
2602Freeing REx: "(?{a})(?<b>\g{c}"
2603EOF_DEBUG_OUT
fe5492d9
YO
2604 {rtrim_result=>1},
2605 "Github Issue #19350, assert fail in "
33fc7377
YO
2606 . "Debug => 'ALL' from malformed qr// (heisenbug try $try)");
2607 }
2608 { # Related to GH $19350 but segfaults instead of asserts, and does so reliably, not randomly.
2609 # use re Debug => "PARSE" is similar to "ALL", but does not include the optimize info, so we
2610 # do not need to deal with normlazing memory addresses in the output.
2611 fresh_perl_is(
2612 'use re Debug=>"PARSE";qr{(?<b>\g{c})(?<c>x)(?&b)}',
2613 <<'EOF_DEBUG_OUT',
2614Assembling pattern from 1 elements
2615Compiling REx "(?<b>\g{c})(?<c>x)(?&b)"
2616Starting parse and generation
2617<(?<b>\g{c})>...| 1| reg
2618 | | brnc
2619 | | piec
2620 | | atom
2621<?<b>\g{c})(>...| | reg
2622<\g{c})(?<c>>...| 3| brnc
2623 | | piec
2624 | | atom
d78630f1
YO
2625<)(?<c>x)(?&b)> | 6| tail~ OPEN1 'b' (1) -> REFN
2626 | 8| lsbr~ tying lastbr REFN <1> (3) to ender CLOSE1 'b' (6) offset 3
2627 | | tail~ REFN <1> (3) -> CLOSE
33fc7377
YO
2628<(?<c>x)(?&b)> | | piec
2629 | | atom
2630<?<c>x)(?&b)> | | reg
d78630f1 2631<x)(?&b)> | 10| brnc
33fc7377
YO
2632 | | piec
2633 | | atom
d78630f1
YO
2634<)(?&b)> | 12| tail~ OPEN2 'c' (8) -> EXACT
2635 | 14| lsbr~ tying lastbr EXACT <x> (10) to ender CLOSE2 'c' (12) offset 2
2636 | | tail~ EXACT <x> (10) -> CLOSE
33fc7377 2637<(?&b)> | | tail~ OPEN1 'b' (1)
d78630f1
YO
2638 | | ~ REFN <1> (3)
2639 | | ~ CLOSE1 'b' (6) -> OPEN
33fc7377
YO
2640 | | piec
2641 | | atom
2642<?&b)> | | reg
d78630f1
YO
2643<> | 17| tail~ OPEN2 'c' (8)
2644 | | ~ EXACT <x> (10)
2645 | | ~ CLOSE2 'c' (12) -> GOSUB
2646 | 18| lsbr~ tying lastbr OPEN1 'b' (1) to ender END (17) offset 16
33fc7377 2647 | | tail~ OPEN1 'b' (1)
d78630f1
YO
2648 | | ~ REFN <1> (3)
2649 | | ~ CLOSE1 'b' (6)
2650 | | ~ OPEN2 'c' (8)
2651 | | ~ EXACT <x> (10)
2652 | | ~ CLOSE2 'c' (12)
2653 | | ~ GOSUB1[+0:14] 'b' (14) -> END
33fc7377
YO
2654Need to redo parse
2655Freeing REx: "(?<b>\g{c})(?<c>x)(?&b)"
2656Starting parse and generation
2657<(?<b>\g{c})>...| 1| reg
2658 | | brnc
2659 | | piec
2660 | | atom
2661<?<b>\g{c})(>...| | reg
2662<\g{c})(?<c>>...| 3| brnc
2663 | | piec
2664 | | atom
d78630f1
YO
2665<)(?<c>x)(?&b)> | 6| tail~ OPEN1 'b' (1) -> REFN
2666 | 8| lsbr~ tying lastbr REFN2 'c' <1> (3) to ender CLOSE1 'b' (6) offset 3
2667 | | tail~ REFN2 'c' <1> (3) -> CLOSE
33fc7377
YO
2668<(?<c>x)(?&b)> | | piec
2669 | | atom
2670<?<c>x)(?&b)> | | reg
d78630f1 2671<x)(?&b)> | 10| brnc
33fc7377
YO
2672 | | piec
2673 | | atom
d78630f1
YO
2674<)(?&b)> | 12| tail~ OPEN2 'c' (8) -> EXACT
2675 | 14| lsbr~ tying lastbr EXACT <x> (10) to ender CLOSE2 'c' (12) offset 2
2676 | | tail~ EXACT <x> (10) -> CLOSE
33fc7377 2677<(?&b)> | | tail~ OPEN1 'b' (1)
d78630f1
YO
2678 | | ~ REFN2 'c' <1> (3)
2679 | | ~ CLOSE1 'b' (6) -> OPEN
33fc7377
YO
2680 | | piec
2681 | | atom
2682<?&b)> | | reg
d78630f1
YO
2683<> | 17| tail~ OPEN2 'c' (8)
2684 | | ~ EXACT <x> (10)
2685 | | ~ CLOSE2 'c' (12) -> GOSUB
2686 | 18| lsbr~ tying lastbr OPEN1 'b' (1) to ender END (17) offset 16
33fc7377 2687 | | tail~ OPEN1 'b' (1)
d78630f1
YO
2688 | | ~ REFN2 'c' <1> (3)
2689 | | ~ CLOSE1 'b' (6)
2690 | | ~ OPEN2 'c' (8)
2691 | | ~ EXACT <x> (10)
2692 | | ~ CLOSE2 'c' (12)
2693 | | ~ GOSUB1[+0:14] 'b' (14) -> END
2694Required size 17 nodes
33fc7377
YO
2695first at 3
2696Freeing REx: "(?<b>\g{c})(?<c>x)(?&b)"
2697EOF_DEBUG_OUT
fe5492d9
YO
2698 {rtrim_result=>1},
2699 "Related to Github Issue #19350, forward \\g{x} pattern segv under use re Debug => 'PARSE'");
33fc7377 2700 }
bb58640a 2701
ff1f9f59
KW
2702 { # perl-security#140, read/write past buffer end
2703 fresh_perl_like('qr/\p{utf8::perl x}/',
2704 qr/Illegal user-defined property name "utf8::perl x" in regex/,
2705 {}, "perl-security#140");
2706 fresh_perl_is('qr/\p{utf8::_perl_surrogate}/', "",
2707 {}, "perl-security#140");
2708 }
2709
8fbe3f6f
KW
2710 { # GH 20009
2711 my $x = "awesome quotes";
2712 utf8::upgrade($x);
2713 $x =~ s/^[\x{0301}\x{030C}]+//;
2714 }
2715
553fa53c 2716
b57e4118 2717 # !!! NOTE that tests that aren't at all likely to crash perl should go
de085464
KW
2718 # a ways above, above these last ones. There's a comment there that, like
2719 # this comment, contains the word 'NOTE'
f4554ed5
NC
2720
2721 done_testing();
e425a60b
YO
2722} # End of sub run_tests
2723
27241;