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