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