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