3 # This is a home for regular expression tests that don't fit into
4 # the format supported by re/regexp.t. If you want to add a test
5 # that does fit that format, add it to re/re_tests, not here.
18 @INC = ('../lib','.','../ext/re');
19 require Config; import Config;
21 skip_all('no re module') unless defined &DynaLoader::boot_DynaLoader;
22 skip_all_without_unicode_tables();
25 plan tests => 770; # Update this when adding/deleting tests.
27 run_tests() unless caller;
36 (my $x_pretty = $x) =~ s/\n/\\n/g;
38 ok $x =~ /^abc/, qq ["$x_pretty" =~ /^abc/];
39 ok $x !~ /^def/, qq ["$x_pretty" !~ /^def/];
41 # used to be a test for $*
42 ok $x =~ /^def/m, qq ["$x_pretty" =~ /^def/m];
44 ok(!($x =~ /^xxx/), qq ["$x_pretty" =~ /^xxx/]);
45 ok(!($x !~ /^abc/), qq ["$x_pretty" !~ /^abc/]);
47 ok $x =~ /def/, qq ["$x_pretty" =~ /def/];
48 ok(!($x !~ /def/), qq ["$x_pretty" !~ /def/]);
50 ok $x !~ /.def/, qq ["$x_pretty" !~ /.def/];
51 ok(!($x =~ /.def/), qq ["$x_pretty" =~ /.def/]);
53 ok $x =~ /\ndef/, qq ["$x_pretty" =~ /\\ndef/];
54 ok(!($x !~ /\ndef/), qq ["$x_pretty" !~ /\\ndef/]);
59 ok /^([0-9][0-9]*)/, qq [\$_ = '$_'; /^([0-9][0-9]*)/];
64 ok /(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc',
65 qq [\$_ = '$_'; /(a*b*)(c*)/];
66 ok /(a+b+c+)/ && $1 eq 'aaabbbccc', qq [\$_ = '$_'; /(a+b+c+)/];
67 unlike($_, qr/a+b?c+/, qq [\$_ = '$_'; /a+b?c+/]);
70 ok /a+b?c+/, qq [\$_ = '$_'; /a+b?c+/];
71 ok /a*b?c*/, qq [\$_ = '$_'; /a*b?c*/];
74 ok /a*b?c*/, qq [\$_ = '$_'; /a*b?c*/];
75 unlike($_, qr/a*b+c*/, qq [\$_ = '$_'; /a*b+c*/]);
78 ok /bcd|xyz/, qq [\$_ = '$_'; /bcd|xyz/];
79 ok /xyz|bcd/, qq [\$_ = '$_'; /xyz|bcd/];
80 ok m|bc/*d|, qq [\$_ = '$_'; m|bc/*d|];
81 ok /^$_$/, qq [\$_ = '$_'; /^\$_\$/];
85 # used to be a test for $*
86 ok "ab\ncd\n" =~ /^cd/m, q ["ab\ncd\n" =~ /^cd/m];
90 our %XXX = map {($_ => $_)} 123, 234, 345;
92 our @XXX = ('ok 1','not ok 1', 'ok 2','not ok 2','not ok 3');
93 while ($_ = shift(@XXX)) {
94 my $e = index ($_, 'not') >= 0 ? '' : 1;
112 ok !keys %XXX, "%XXX is empty";
118 my $message = "Test empty pattern";
124 is($&, $xyz, $message);
129 is($&, $xyz, $message);
133 no warnings 'uninitialized';
135 is($&, $xyz, $message);
139 is($&, $xyz, $message);
143 my $message = q !Check $`, $&, $'!;
145 /def/; # optimized up to cmd
146 is("$`:$&:$'", 'abc:def:ghi', $message);
149 /cde/ + 0; # optimized only to spat
150 is("$`:$&:$'", 'ab:cde:fghi', $message);
152 /[d][e][f]/; # not optimized
153 is("$`:$&:$'", 'abc:def:ghi', $message);
157 $_ = 'now is the {time for all} good men to come to.';
159 is($1, 'time for all', "Match braces");
163 my $message = "{N,M} quantifier";
164 $_ = 'xxx {3,4} yyy zzz';
165 ok(/( {3,4})/, $message);
166 is($1, ' ', $message);
167 unlike($_, qr/( {4,})/, $message);
168 ok(/( {2,3}.)/, $message);
169 is($1, ' y', $message);
170 ok(/(y{2,3}.)/, $message);
171 is($1, 'yyy ', $message);
172 unlike($_, qr/x {3,4}/, $message);
173 unlike($_, qr/^xxx {3,4}/, $message);
177 my $message = "Test /g";
179 $_ = "now is the time for all good men to come to.";
180 my @words = /(\w+)/g;
181 my $exp = "now:is:the:time:for:all:good:men:to:come:to";
183 is("@words", $exp, $message);
189 is("@words", $exp, $message);
196 is("@words", "to:to", $message);
200 is("@words", "to:to", $message);
216 my $t1 = my $t2 = my $t3 = my $t4 = my $t5 =
217 my $t6 = my $t7 = my $t8 = my $t9 = 0;
219 for my $iter (1 .. 5) {
230 my $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
231 is($x, '505550555', "Test /o");
236 ok "abc" =~ /^abc$|$xyz/, "| after \$";
238 # perl 4.009 says "unmatched ()"
239 my $message = '$ inside ()';
242 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
243 is($@, "", $message);
244 is($result, "abc:bc", $message);
248 my $message = "Scalar /g";
251 ok( /abc/g && $` eq "", $message);
252 ok( /abc/g && $` eq "abcfoo", $message);
253 ok(!/abc/g, $message);
255 $message = "Scalar /gi";
257 ok( /ABC/gi && $` eq "", $message);
258 ok( /ABC/gi && $` eq "abcfoo", $message);
259 ok(!/ABC/gi, $message);
261 $message = "Scalar /g";
263 ok( /abc/g && $' eq "fooabcbar", $message);
264 ok( /abc/g && $' eq "bar", $message);
268 is(@x, 2, "/g reset after assignment");
272 my $message = '/g, \G and pos';
276 is(pos $_, 2, $message);
278 is(pos $_, undef, $message);
282 my $message = '(?{ })';
284 'abc' =~ m'a(?{ $out = 2 })b';
285 is($out, 2, $message);
288 'abc' =~ m'a(?{ $out = 3 })c';
289 is($out, 1, $message);
293 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
294 my @out = /(?<!foo)bar./g;
295 is("@out", 'bar2 barf', "Negative lookbehind");
299 my $message = "REG_INFTY tests";
300 # Tests which depend on REG_INFTY
302 # Defaults assumed if this fails
303 eval { require Config; };
304 $::reg_infty = $Config::Config{reg_infty} // 32767;
305 $::reg_infty_m = $::reg_infty - 1;
306 $::reg_infty_p = $::reg_infty + 1;
307 $::reg_infty_m = $::reg_infty_m; # Suppress warning.
309 # As well as failing if the pattern matches do unexpected things, the
310 # next three tests will fail if you should have picked up a lower-than-
311 # default value for $reg_infty from Config.pm, but have not.
313 is(eval q{('aaa' =~ /(a{1,$::reg_infty_m})/)[0]}, 'aaa', $message);
314 is($@, '', $message);
315 is(eval q{('a' x $::reg_infty_m) =~ /a{$::reg_infty_m}/}, 1, $message);
316 is($@, '', $message);
317 isnt(q{('a' x ($::reg_infty_m - 1)) !~ /a{$::reg_infty_m}/}, 1, $message);
318 is($@, '', $message);
320 eval "'aaa' =~ /a{1,$::reg_infty}/";
321 like($@, qr/^\QQuantifier in {,} bigger than/, $message);
322 eval "'aaa' =~ /a{1,$::reg_infty_p}/";
323 like($@, qr/^\QQuantifier in {,} bigger than/, $message);
327 # Poke a couple more parse failures
328 my $context = 'x' x 256;
329 eval qq("${context}y" =~ /(?<=$context)y/);
330 ok $@ =~ /^\QLookbehind longer than 255 not/, "Lookbehind limit";
335 for my $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
337 my $message = "Long monster, length = $l";
338 like("ba$a=", qr/a$a=/, $message);
339 unlike("b$a=", qr/a$a=/, $message);
340 like("b$a=", qr/ba+=/, $message);
342 like("ba$a=", qr/b(?:a|b)+=/, $message);
347 # 20000 nodes, each taking 3 words per string, and 1 per branch
348 my $long_constant_len = join '|', 12120 .. 32645;
349 my $long_var_len = join '|', 8120 .. 28645;
350 my %ans = ( 'ax13876y25677lbc' => 1,
351 'ax13876y25677mcb' => 0, # not b.
352 'ax13876y35677nbc' => 0, # Num too big
353 'ax13876y25677y21378obc' => 1,
354 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
355 'ax13876y25677y21378y21378kbc' => 1,
356 'ax13876y25677y21378y21378kcb' => 0, # Not b.
357 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
361 my $message = "20000 nodes, const-len '$_'";
362 ok !($ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o), $message;
364 $message = "20000 nodes, var-len '$_'";
365 ok !($ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o,), $message;
370 my $message = "Complicated backtracking";
371 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
372 my $expect = "(bla()) ((l)u((e))) (l(e)e)";
379 (?{ $c = 1 }) # Initialize
381 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
383 ) # Fail: will unwind one iteration back
386 [^()]+ # Match a big chunk
389 ) # Do not try to match subchunks
397 )+ # This may not match with different subblocks
402 ) # Otherwise the chunk 1 may succeed with $c>0
408 push @ans, $res while $res = matchit;
409 is("@ans", "1 1 1", $message);
412 is("@ans", $expect, $message);
414 $message = "Recursion with (??{ })";
416 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
418 @ans = my @ans1 = ();
419 push (@ans, $res), push (@ans1, $&) while $res = m/$matched/g;
421 is("@ans", "1 1 1", $message);
422 is("@ans1", $expect, $message);
425 is("@ans", $expect, $message);
430 ok "abc" =~ /^(??{"a"})b/, '"abc" =~ /^(??{"a"})b/';
434 my @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
435 is("@ans", 'a/ b', "Stack may be bad");
439 my $message = "Eval-group not allowed at runtime";
440 my $code = '{$blah = 45}';
443 ok($@ && $@ =~ /not allowed at runtime/ && $blah == 12, $message);
446 my $res = eval { "xx" =~ /(?$code)/o };
448 no warnings 'uninitialized';
449 chomp $@; my $message = "$message '$@', '$res', '$blah'";
450 ok($@ && $@ =~ /not allowed at runtime/ && $blah == 12, $message);
455 $res = eval { "xx" =~ /(?$code)/o };
457 no warnings 'uninitialized';
458 my $message = "$message '$@', '$res', '$blah'";
459 ok(!$@ && $res, $message);
462 $code = '{$blah = 45}';
465 is($blah, 45, $message);
469 is($blah, 45, $message);
473 my $message = "Pos checks";
476 is(pos $x, 2, $message);
479 is(pos $x, 2, $message);
487 is(f (pos $x), 4, $message);
491 my $message = 'Checking $^R';
493 'foot' =~ /foo(?{$x = 12; 75})[t]/;
494 is($^R, 75, $message);
497 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
498 ok($^R eq '67' && $x eq '12', $message);
501 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
502 ok($^R eq '79' && $x eq '12', $message);
506 is(qr/\b\v$/i, '(?^i:\b\v$)', 'qr/\b\v$/i');
507 is(qr/\b\v$/s, '(?^s:\b\v$)', 'qr/\b\v$/s');
508 is(qr/\b\v$/m, '(?^m:\b\v$)', 'qr/\b\v$/m');
509 is(qr/\b\v$/x, '(?^x:\b\v$)', 'qr/\b\v$/x');
510 is(qr/\b\v$/xism, '(?^msix:\b\v$)', 'qr/\b\v$/xism');
511 is(qr/\b\v$/, '(?^:\b\v$)', 'qr/\b\v$/');
514 { # Test that charset modifier work, and are interpolated
515 is(qr/\b\v$/, '(?^:\b\v$)', 'Verify no locale, no unicode_strings gives default modifier');
516 is(qr/(?l:\b\v$)/, '(?^:(?l:\b\v$))', 'Verify infix l modifier compiles');
517 is(qr/(?u:\b\v$)/, '(?^:(?u:\b\v$))', 'Verify infix u modifier compiles');
518 is(qr/(?l)\b\v$/, '(?^:(?l)\b\v$)', 'Verify (?l) compiles');
519 is(qr/(?u)\b\v$/, '(?^:(?u)\b\v$)', 'Verify (?u) compiles');
521 my $dual = qr/\b\v$/;
525 skip 'No locale testing without d_setlocale', 1 if(!$Config{d_setlocale});
529 is($locale, '(?^l:\b\v$)', 'Verify has l modifier when compiled under use locale');
533 use feature 'unicode_strings';
534 my $unicode = qr/\b\v$/;
535 is($unicode, '(?^u:\b\v$)', 'Verify has u modifier when compiled under unicode_strings');
536 is(qr/abc$dual/, '(?^u:abc(?^:\b\v$))', 'Verify retains d meaning when interpolated under locale');
539 skip 'No locale testing without d_setlocale', 1 if(!$Config{d_setlocale});
541 is(qr/abc$locale/, '(?^u:abc(?^l:\b\v$))', 'Verify retains l when interpolated under unicode_strings');
544 no feature 'unicode_strings';
546 skip 'No locale testing without d_setlocale', 1 if(!$Config{d_setlocale});
548 is(qr/abc$locale/, '(?^:abc(?^l:\b\v$))', 'Verify retains l when interpolated outside locale and unicode strings');
551 is(qr/def$unicode/, '(?^:def(?^u:\b\v$))', 'Verify retains u when interpolated outside locale and unicode strings');
554 skip 'No locale testing without d_setlocale', 2 if(!$Config{d_setlocale});
557 is(qr/abc$dual/, '(?^l:abc(?^:\b\v$))', 'Verify retains d meaning when interpolated under locale');
558 is(qr/abc$unicode/, '(?^l:abc(?^u:\b\v$))', 'Verify retains u when interpolated under locale');
563 my $message = "Look around";
565 foreach my $ans ('', 'c') {
566 ok(/(?<=(?=a)..)((?=c)|.)/g, $message);
567 is($1, $ans, $message);
572 my $message = "Empty clause";
574 foreach my $ans ('', 'a', '') {
575 ok(/^|a|$/g, $message);
576 is($&, $ans, $message);
582 my $message = "Prefixify";
584 my ($v, $a, $b, $res) = @_;
585 ok($v =~ s/\Q$a\E/$b/, $message);
586 is($v, $res, $message);
590 prefixify ('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
591 prefixify ('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
597 ok $1 && /$1/, "Capture a quote";
601 no warnings 'closure';
602 my $message = '(?{ $var } refers to package vars';
606 '' =~ /(?{ $c = 4 })/;
607 main::is($c, 4, $message);
608 main::is($::c, 3, $message);
612 is(eval 'q(a:[b]:) =~ /[x[:foo:]]/', undef);
613 like ($@, qr/POSIX class \[:[^:]+:\] unknown in regex/,
614 'POSIX class [: :] must have valid name');
616 for my $d (qw [= .]) {
617 is(eval "/[[${d}foo${d}]]/", undef);
618 like ($@, qr/\QPOSIX syntax [$d $d] is reserved for future extensions/,
619 "POSIX syntax [[$d $d]] is an error");
624 # test if failure of patterns returns empty list
625 my $message = "Failed pattern returns empty list";
628 is("@_", "", $message);
631 is("@_", "", $message);
634 is("@_", "", $message);
637 is("@_", "", $message);
641 my $message = '@- and @+ tests';
644 is($#+, 0, $message);
645 is($#-, 0, $message);
646 is($+ [0], 2, $message);
647 is($- [0], 1, $message);
648 ok(!defined $+ [1] && !defined $- [1] &&
649 !defined $+ [2] && !defined $- [2], $message);
652 is($#+, 2, $message);
653 is($#-, 2, $message);
654 is($+ [0], 3, $message);
655 is($- [0], 0, $message);
656 is($+ [1], 2, $message);
657 is($- [1], 1, $message);
658 is($+ [2], 3, $message);
659 is($- [2], 2, $message);
660 ok(!defined $+ [3] && !defined $- [3] &&
661 !defined $+ [4] && !defined $- [4], $message);
663 # Exists has a special check for @-/@+ - bug 45147
664 ok(exists $-[0], $message);
665 ok(exists $+[0], $message);
666 ok(exists $-[2], $message);
667 ok(exists $+[2], $message);
668 ok(!exists $-[3], $message);
669 ok(!exists $+[3], $message);
670 ok(exists $-[-1], $message);
671 ok(exists $+[-1], $message);
672 ok(exists $-[-3], $message);
673 ok(exists $+[-3], $message);
674 ok(!exists $-[-4], $message);
675 ok(!exists $+[-4], $message);
678 is($#+, 3, $message);
679 is($#-, 3, $message);
680 is($+ [1], 2, $message);
681 is($- [1], 1, $message);
682 is($+ [3], 3, $message);
683 is($- [3], 2, $message);
684 ok(!defined $+ [2] && !defined $- [2] &&
685 !defined $+ [4] && !defined $- [4], $message);
688 is($#+, 1, $message);
689 is($#-, 1, $message);
690 is($+ [0], 2, $message);
691 is($- [0], 0, $message);
692 is($+ [1], 2, $message);
693 is($- [1], 1, $message);
694 ok(!defined $+ [2] && !defined $- [2] &&
695 !defined $+ [3] && !defined $- [3], $message);
698 is($#+, 2, $message);
699 is($#-, 1, $message);
701 # Check that values don’t stick
702 " "=~/()()()(.)(..)/;
703 my($m,$p) = (\$-[5], \$+[5]);
704 () = "$$_" for $m, $p; # FETCH (or eqv.)
706 is $$m, undef, 'values do not stick to @- elements';
707 is $$p, undef, 'values do not stick to @+ elements';
710 foreach ('$+[0] = 13', '$-[0] = 13', '@+ = (7, 6, 5)',
711 '@- = qw (foo bar)', '$^N = 42') {
713 like($@, qr/^Modification of a read-only value attempted/,
714 '$^N, @- and @+ are read-only');
718 my $message = '\G testing';
722 is("@a", "a a", $message);
726 unlike($str, qr/^\G/, $message);
727 unlike($str, qr/^.\G/, $message);
728 like($str, qr/^..\G/, $message);
729 unlike($str, qr/^...\G/, $message);
730 ok($str =~ /\G../ && $& eq 'cd', $message);
731 ok($str =~ /.\G./ && $& eq 'bc', $message);
736 my $message = '\G and intuit and anchoring';
739 ok($_ =~ /\Gabc/, $message);
740 ok($_ =~ /^\Gabc/, $message);
743 ok($_ =~ /\Gdef/, $message);
745 ok($_ =~ /\Gdef$/, $message);
747 ok($_ =~ /abc\Gdef$/, $message);
749 ok($_ =~ /^abc\Gdef$/, $message);
751 ok($_ =~ /c\Gd/, $message);
753 ok($_ =~ /..\GX?def/, $message);
759 my @a = $s =~ /(\d)\G/g; # this infinitely looped up till 5.19.1
760 is("@a", "1", '\G looping');
765 my $message = 'pos inside (?{ })';
768 like($str, qr/b(?{$foo = $_; $bar = pos})c/, $message);
769 is($foo, $str, $message);
770 is($bar, 2, $message);
771 is(pos $str, undef, $message);
776 ok($str =~ /b(?{$foo = $_; $bar = pos})c/g, $message);
777 is($foo, $str, $message);
778 is($bar, 2, $message);
779 is(pos $str, 3, $message);
784 like($_, qr/b(?{$foo = $_; $bar = pos})c/, $message);
785 is($foo, $str, $message);
786 is($bar, 2, $message);
790 ok(/b(?{$foo = $_; $bar = pos})c/g, $message);
791 is($foo, $str, $message);
792 is($bar, 2, $message);
793 is(pos, 3, $message);
798 1 while /b(?{$foo = $_; $bar = pos})c/g;
799 is($foo, $str, $message);
800 is($bar, 2, $message);
801 is(pos, undef, $message);
806 ok(s/b(?{$foo = $_; $bar = pos})c/x/g, $message);
807 is($foo, 'abcde|abcde', $message);
808 is($bar, 8, $message);
809 is($_, 'axde|axde', $message);
814 () = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
815 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
816 is("@res", "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'", $message);
819 () = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
820 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
821 is("@res", "'' 'ab' 'cde|abcde' " .
822 "'' 'abc' 'de|abcde' " .
823 "'abcd' 'e|' 'abcde' " .
824 "'abcde|' 'ab' 'cde' " .
825 "'abcde|' 'abc' 'de'", $message);
829 my $message = '\G anchor checks';
830 my $foo = 'aabbccddeeffgg';
833 ok($foo =~ /.\G(..)/g, $message);
834 is($1, 'ab', $message);
837 ok($foo =~ /.\G(..)/g, $message);
838 is($1, 'cc', $message);
841 ok($foo =~ /.\G(..)/g, $message);
842 is($1, 'de', $message);
844 ok($foo =~ /\Gef/g, $message);
847 ok($foo =~ /\G(..)/g, $message);
848 is($1, 'aa', $message);
850 ok($foo =~ /\G(..)/g, $message);
851 is($1, 'bb', $message);
854 ok($foo =~ /\G(..)/g, $message);
855 is($1, 'cd', $message);
859 my $message = 'basic \G floating checks';
860 my $foo = 'aabbccddeeffgg';
863 ok($foo =~ /a+\G(..)/g, "$message: a+\\G");
864 is($1, 'ab', "$message: ab");
867 ok($foo =~ /b+\G(..)/g, "$message: b+\\G");
868 is($1, 'cc', "$message: cc");
871 ok($foo =~ /d+\G(..)/g, "$message: d+\\G");
872 is($1, 'de', "$message: de");
874 ok($foo =~ /\Gef/g, "$message: \\Gef");
878 ok($foo =~ /(?=a+\G)(..)/g, "$message: (?a+\\G)");
879 is($1, 'aa', "$message: aa");
883 ok($foo =~ /a(?=a+\G)(..)/g, "$message: a(?=a+\\G)");
884 is($1, 'ab', "$message: ab");
890 my @res = /(\d*|x)/g;
892 is("@res", "123||x|123|", "0 match in alternation");
896 my $message = "Match against temporaries (created via pp_helem())" .
898 ok({foo => "bar\n" . $^X} -> {foo} =~ /^(.*)\n/g, $message);
899 is($1, "bar", $message);
903 my $message = 'package $i inside (?{ }), ' .
904 'saved substrings and changing $_';
905 our @a = qw [foo bar];
907 s/(\w)(?{push @b, $1})/,$1,/g for @a;
908 is("@b", "f o o b a r", $message);
909 is("@a", ",f,,o,,o, ,b,,a,,r,", $message);
911 $message = 'lexical $i inside (?{ }), ' .
912 'saved substrings and changing $_';
913 no warnings 'closure';
914 my @c = qw [foo bar];
916 s/(\w)(?{push @d, $1})/,$1,/g for @c;
917 is("@d", "f o o b a r", $message);
918 is("@c", ",f,,o,,o, ,b,,a,,r,", $message);
922 my $message = 'Brackets';
925 { (?> [^{}]+ | (??{ $brackets }) )* }
928 ok("{{}" =~ $brackets, $message);
929 is($&, "{}", $message);
930 ok("something { long { and } hairy" =~ $brackets, $message);
931 is($&, "{ and }", $message);
932 ok("something { long { and } hairy" =~ m/((??{ $brackets }))/, $message);
933 is($&, "{ and }", $message);
939 ok(!m/^-.*bb/mg, '$_ = "a-a\nxbb"; m/^-.*bb/mg');
943 my $message = '\G anchor checks';
944 my $text = "aaXbXcc";
946 ok($text !~ /\GXb*X/g, $message);
951 unlike($_, qr/^\s*A/m, '$_ = "xA\n" x 500; /^\s*A/m"');
953 my $text = "abc dbf";
954 my @res = ($text =~ /.*?(b).*?\b/g);
955 is("@res", "b b", '\b is not special');
959 my $message = '\S, [\S], \s, [\s]';
960 my @a = map chr, 0 .. 255;
961 my @b = grep m/\S/, @a;
962 my @c = grep m/[^\s]/, @a;
963 is("@b", "@c", $message);
966 @c = grep /[\S]/, @a;
967 is("@b", "@c", $message);
970 @c = grep /[^\S]/, @a;
971 is("@b", "@c", $message);
974 @c = grep /[\s]/, @a;
975 is("@b", "@c", $message);
978 my $message = '\D, [\D], \d, [\d]';
979 my @a = map chr, 0 .. 255;
980 my @b = grep /\D/, @a;
981 my @c = grep /[^\d]/, @a;
982 is("@b", "@c", $message);
985 @c = grep /[\D]/, @a;
986 is("@b", "@c", $message);
989 @c = grep /[^\D]/, @a;
990 is("@b", "@c", $message);
993 @c = grep /[\d]/, @a;
994 is("@b", "@c", $message);
997 my $message = '\W, [\W], \w, [\w]';
998 my @a = map chr, 0 .. 255;
999 my @b = grep /\W/, @a;
1000 my @c = grep /[^\w]/, @a;
1001 is("@b", "@c", $message);
1004 @c = grep /[\W]/, @a;
1005 is("@b", "@c", $message);
1008 @c = grep /[^\W]/, @a;
1009 is("@b", "@c", $message);
1012 @c = grep /[\w]/, @a;
1013 is("@b", "@c", $message);
1017 # see if backtracking optimization works correctly
1018 my $message = 'Backtrack optimization';
1019 like("\n\n", qr/\n $ \n/x, $message);
1020 like("\n\n", qr/\n* $ \n/x, $message);
1021 like("\n\n", qr/\n+ $ \n/x, $message);
1022 like("\n\n", qr/\n? $ \n/x, $message);
1023 like("\n\n", qr/\n*? $ \n/x, $message);
1024 like("\n\n", qr/\n+? $ \n/x, $message);
1025 like("\n\n", qr/\n?? $ \n/x, $message);
1026 unlike("\n\n", qr/\n*+ $ \n/x, $message);
1027 unlike("\n\n", qr/\n++ $ \n/x, $message);
1028 like("\n\n", qr/\n?+ $ \n/x, $message);
1033 use overload '""' => sub {'Object S'};
1036 my $message = "Ref stringification";
1037 ::ok(do { \my $v} =~ /^SCALAR/, "Scalar ref stringification") or diag($message);
1038 ::ok(do {\\my $v} =~ /^REF/, "Ref ref stringification") or diag($message);
1039 ::ok([] =~ /^ARRAY/, "Array ref stringification") or diag($message);
1040 ::ok({} =~ /^HASH/, "Hash ref stringification") or diag($message);
1041 ::ok('S' -> new =~ /^Object S/, "Object stringification") or diag($message);
1045 my $message = "Test result of match used as match";
1046 ok('a1b' =~ ('xyz' =~ /y/), $message);
1047 is($`, 'a', $message);
1048 ok('a1b' =~ ('xyz' =~ /t/), $message);
1049 is($`, 'a', $message);
1053 my $message = '"1" is not \s';
1054 warning_is(sub {unlike("1\n" x 102, qr/^\s*\n/m, $message)},
1055 undef, "$message (did not warn)");
1059 my $message = '\s, [[:space:]] and [[:blank:]]';
1060 my %space = (spc => " ",
1065 # There's no \v but the vertical tabulator seems miraculously
1066 # be 11 both in ASCII and EBCDIC.
1070 my @space0 = sort grep {$space {$_} =~ /\s/ } keys %space;
1071 my @space1 = sort grep {$space {$_} =~ /[[:space:]]/} keys %space;
1072 my @space2 = sort grep {$space {$_} =~ /[[:blank:]]/} keys %space;
1074 is("@space0", "cr ff lf spc tab vt", $message);
1075 is("@space1", "cr ff lf spc tab vt", $message);
1076 is("@space2", "spc tab", $message);
1081 # this must be a high number and go from 0 to N, as the bug we are looking for doesn't
1082 # seem to be predictable. Slight changes to the test make it fail earlier or later.
1083 foreach my $i (0 .. $n)
1086 ok $str=~/.*\z/, "implicit MBOL check string disable does not break things length=$i";
1090 # we are actually testing that we dont die when executing these patterns
1093 ok(utf8::is_utf8($e),"got a unicode string - rt75680");
1095 ok($e !~ m/.*?[x]$/, "unicode string against /.*?[x]\$/ - rt75680");
1096 ok($e !~ m/.*?\p{Space}$/i, "unicode string against /.*?\\p{space}\$/i - rt75680");
1097 ok($e !~ m/.*?[xyz]$/, "unicode string against /.*?[xyz]\$/ - rt75680");
1098 ok($e !~ m/(.*?)[,\p{isSpace}]+((?:\p{isAlpha}[\p{isSpace}\.]{1,2})+)\p{isSpace}*$/, "unicode string against big pattern - rt75680");
1101 # we are actually testing that we dont die when executing these patterns
1102 my $e = "B\x{f6}ck";
1103 ok(!utf8::is_utf8($e), "got a latin string - rt75680");
1105 ok($e !~ m/.*?[x]$/, "latin string against /.*?[x]\$/ - rt75680");
1106 ok($e !~ m/.*?\p{Space}$/i, "latin string against /.*?\\p{space}\$/i - rt75680");
1107 ok($e !~ m/.*?[xyz]$/,"latin string against /.*?[xyz]\$/ - rt75680");
1108 ok($e !~ m/(.*?)[,\p{isSpace}]+((?:\p{isAlpha}[\p{isSpace}\.]{1,2})+)\p{isSpace}*$/,"latin string against big pattern - rt75680");
1113 # Tests for bug 77414.
1116 my $message = '\p property after empty * match';
1118 like("1", qr/\s*\pN/, $message);
1119 like("-", qr/\s*\p{Dash}/, $message);
1120 like(" ", qr/\w*\p{Blank}/, $message);
1123 like("1", qr/\s*\pN+/, $message);
1124 like("-", qr/\s*\p{Dash}{1}/, $message);
1125 like(" ", qr/\w*\p{Blank}{1,4}/, $message);
1129 SKIP: { # Some constructs with Latin1 characters cause a utf8 string not
1130 # to match itself in non-utf8
1132 skip "Needs to be customized to run on EBCDIC", 6;
1135 my $pattern = my $utf8_pattern = qr/((\xc0)+,?)/;
1136 utf8::upgrade($utf8_pattern);
1137 ok $c =~ $pattern, "\\xc0 =~ $pattern; Neither pattern nor target utf8";
1138 ok $c =~ /$pattern/i, "\\xc0 =~ /$pattern/i; Neither pattern nor target utf8";
1139 ok $c =~ $utf8_pattern, "\\xc0 =~ $pattern; pattern utf8, target not";
1140 ok $c =~ /$utf8_pattern/i, "\\xc0 =~ /$pattern/i; pattern utf8, target not";
1142 ok $c =~ $pattern, "\\xc0 =~ $pattern; target utf8, pattern not";
1143 ok $c =~ /$pattern/i, "\\xc0 =~ /$pattern/i; target utf8, pattern not";
1144 ok $c =~ $utf8_pattern, "\\xc0 =~ $pattern; Both target and pattern utf8";
1145 ok $c =~ /$utf8_pattern/i, "\\xc0 =~ /$pattern/i; Both target and pattern utf8";
1148 SKIP: { # Make sure can override the formatting
1150 skip "Needs to be customized to run on EBCDIC", 2;
1152 use feature 'unicode_strings';
1153 ok "\xc0" =~ /\w/, 'Under unicode_strings: "\xc0" =~ /\w/';
1154 ok "\xc0" !~ /(?d:\w)/, 'Under unicode_strings: "\xc0" !~ /(?d:\w)/';
1161 is("$qr", "(?^:)", "Empty pattern qr// stringifies to (?^:) with unicode flag enabled - Bug #80212");
1164 is("$qr", "(?^:)", "Empty pattern qr// stringifies to (?^:) with unicode flag disabled - Bug #80212");
1169 local $::TODO = "[perl #38133]";
1171 "A" =~ /(((?:A))?)+/;
1177 is($first, $second);
1181 # RT #3516: \G in a m//g expression causes problems
1183 while ("abc" =~ m/(\G[ac])?/g) {
1184 last if $count++ > 10;
1186 ok($count < 10, 'RT #3516 A');
1189 while ("abc" =~ m/(\G|.)[ac]/g) {
1190 last if $count++ > 10;
1192 ok($count < 10, 'RT #3516 B');
1195 while ("abc" =~ m/(\G?[ac])?/g) {
1196 last if $count++ > 10;
1198 ok($count < 10, 'RT #3516 C');
1201 # RT #84294: Is this a bug in the simple Perl regex?
1202 # : Nested buffers and (?{...}) dont play nicely on partial matches
1204 ok("ab" =~ /((\w+)(?{ push @got, $2 })){2}/,"RT #84294: Pattern should match");
1205 my $want= "'ab', 'a', 'b'";
1206 my $got= join(", ", map { defined($_) ? "'$_'" : "undef" } @got);
1207 is($got,$want,'RT #84294: check that "ab" =~ /((\w+)(?{ push @got, $2 })){2}/ leaves @got in the correct state');
1211 # Suppress warnings, as the non-unicode one comes out even if turn off
1212 # warnings here (because the execution is done in another scope).
1213 local $SIG{__WARN__} = sub {};
1214 my $str = "\x{110000}";
1216 unlike($str, qr/\p{ASCII_Hex_Digit=True}/, "Non-Unicode doesn't match \\p{AHEX=True}");
1217 like($str, qr/\p{ASCII_Hex_Digit=False}/, "Non-Unicode matches \\p{AHEX=False}");
1218 like($str, qr/\P{ASCII_Hex_Digit=True}/, "Non-Unicode matches \\P{AHEX=True}");
1219 unlike($str, qr/\P{ASCII_Hex_Digit=False}/, "Non-Unicode matches \\P{AHEX=FALSE}");
1223 # Test that IDstart works, but because the author (khw) knows
1224 # regexes much better than the rest of the core, it is being done here
1225 # in the context of a regex which relies on buffer names beginng with
1229 like($str, qr/(?<a>abc)/, "'a' is legal IDStart");
1230 like($str, qr/(?<_>abc)/, "'_' is legal IDStart");
1231 like($str, qr/(?<ß>abc)/, "U+00DF is legal IDStart");
1232 like($str, qr/(?<ℕ>abc)/, "U+2115' is legal IDStart");
1234 # This test works on Unicode 6.0 in which U+2118 and U+212E are legal
1235 # IDStarts there, but are not Word characters, and therefore Perl
1236 # doesn't allow them to be IDStarts. But there is no guarantee that
1237 # Unicode won't change things around in the future so that at some
1238 # future Unicode revision these tests would need to be revised.
1239 foreach my $char ("%", "×", chr(0x2118), chr(0x212E)) {
1242 "abc" =~ qr/(?<$char>abc)/;
1244 utf8::encode($prog);
1245 fresh_perl_like($prog, qr!Group name must start with a non-digit word character!, {},
1246 sprintf("'U+%04X not legal IDFirst'", ord($char)));
1252 utf8::upgrade($pat);
1253 like("\xffb", qr/$pat/i, "/i: utf8 pattern, non-utf8 string, latin1-char preceding matching char in string");
1256 { # Crash with @a =~ // warning
1257 local $SIG{__WARN__} = sub {
1258 pass 'no crash for @a =~ // warning'
1260 eval ' sub { my @a =~ // } ';
1263 { # Concat overloading and qr// thingies
1269 '""' => sub { ${$_[0]} },
1271 push @refs, ref $_[1] if ref $_[1];
1272 bless $_[2] ? \"$_[1]${$_[0]}" : \"${$_[0]}$_[1]"
1277 my $o = bless \$s, Cat::;
1279 is "@refs", "Regexp", '/$o$qr/ passes qr ref to cat overload meth';
1285 $count++ while $str=~/.*/g;
1286 is $count, 2, 'test that ANCH_MBOL works properly. We should get 2 from $count++ while "\n"=~/.*/g';
1288 $class_count++ while $str=~/[^\n]*/g;
1289 is $class_count, $count, 'while "\n"=~/.*/g and while "\n"=~/[^\n]*/g should behave the same';
1291 $anch_count++ while $str=~/^.*/mg;
1292 is $anch_count, 1, 'while "\n"=~/^.*/mg should match only once';
1297 like "\xe0", qr/(?i:\xc0)/, "(?i: shouldn't lose the passed in /u";
1299 unlike "\x{100}", qr/(?i:\w)/, "(?i: shouldn't lose the passed in /a";
1301 unlike 'k', qr/(?i:\N{KELVIN SIGN})/, "(?i: shouldn't lose the passed in /aa";
1305 # the test for whether the pattern should be re-compiled should
1306 # consider the UTF8ness of the previous and current pattern
1307 # string, as well as the physical bytes of the pattern string
1309 for my $s ("\xc4\x80", "\x{100}") {
1310 ok($s =~ /^$s$/, "re-compile check is UTF8-aware");
1314 # #113682 more overloading and qr//
1315 # when doing /foo$overloaded/, if $overloaded returns
1316 # a qr/(?{})/ via qr or "" overloading, then 'use re 'eval'
1317 # shouldn't be required. Via '.', it still is.
1320 use overload 'qr' => sub { qr/(??{50})/ };
1323 use overload '""' => sub { qr/(??{51})/ };
1326 use overload '.' => sub { $_[1] . qr/(??{52})/ };
1329 use overload '""' => sub { qr/(??{7})/ },
1330 '.' => sub { $_[1] . qr/(??{53})/ };
1332 package Qr_indirect;
1333 use overload '""' => sub { $_[0][0] };
1338 my $o = bless [], "Qr$i";
1339 if ((0,0,1,1)[$i]) {
1340 eval { "A5$i" =~ /^A$o$/ };
1341 like($@, qr/Eval-group not allowed/, "Qr$i");
1342 eval { "5$i" =~ /$o/ };
1343 like($@, ($i == 3 ? qr/^$/ : qr/no method found,/),
1347 ok("A5$i" =~ /^A$o$/, "Qr$i - with use re eval");
1348 eval { "5$i" =~ /$o/ };
1349 like($@, ($i == 3 ? qr/^$/ : qr/no method found,/),
1350 "Qr$i bare - with use re eval");
1354 ok("A5$i" =~ /^A$o$/, "Qr$i");
1355 ok("5$i" =~ /$o/, "Qr$i bare");
1359 my $o = bless [ bless [], "Qr1" ], 'Qr_indirect';
1360 ok("A51" =~ /^A$o/, "Qr_indirect");
1361 ok("51" =~ /$o/, "Qr_indirect bare");
1364 { # Various flags weren't being set when a [] is optimized into an
1368 ok("\x{017F}\x{017F}" =~ qr/^[\x{00DF}]?$/i, "[] to EXACTish optimization");
1372 for my $char (":", "\x{f7}", "\x{2010}") {
1373 my $utf8_char = $char;
1374 utf8::upgrade($utf8_char);
1375 my $display = $char;
1376 $display = display($display);
1377 my $utf8_display = "utf8::upgrade(\"$display\")";
1379 like($char, qr/^$char?$/, "\"$display\" =~ /^$display?\$/");
1380 like($char, qr/^$utf8_char?$/, "my \$p = \"$display\"; utf8::upgrade(\$p); \"$display\" =~ /^\$p?\$/");
1381 like($utf8_char, qr/^$char?$/, "my \$c = \"$display\"; utf8::upgrade(\$c); \"\$c\" =~ /^$display?\$/");
1382 like($utf8_char, qr/^$utf8_char?$/, "my \$c = \"$display\"; utf8::upgrade(\$c); my \$p = \"$display\"; utf8::upgrade(\$p); \"\$c\" =~ /^\$p?\$/");
1387 # #116148: Pattern utf8ness sticks around globally
1388 # the utf8 in the first match was sticking around for the second
1391 use feature 'unicode_strings';
1397 ok("Perl" =~ /P.*$/i, '#116148');
1400 { # 118297: Mixing up- and down-graded strings in regex
1401 utf8::upgrade(my $u = "\x{e5}");
1402 utf8::downgrade(my $d = "\x{e5}");
1404 local $SIG{__WARN__} = sub { $warned++ if $_[0] =~ /\AMalformed UTF-8/ };
1406 ok(!$warned, "no warnings when interpolating mixed up-/downgraded strings in pattern");
1407 my $c = "\x{e5}\x{e5}";
1408 utf8::downgrade($c);
1409 like($c, $re, "mixed up-/downgraded pattern matches downgraded string");
1411 like($c, $re, "mixed up-/downgraded pattern matches upgraded string");
1415 # if we have 87 capture buffers defined then \87 should refer to the 87th.
1416 # test that this is true for 1..100
1417 # Note that this test causes the engine to recurse at runtime, and
1418 # hence use a lot of C stack.
1419 for my $i (1..100) {
1421 $capture= "($capture)" for 1 .. $i;
1422 for my $mid ("","b") {
1423 my $str= "a${mid}a";
1424 my $backref= "\\$i";
1426 ok($str=~/$capture$mid$backref/,"\\$i works with $i buffers '$str'=~/...$mid$backref/");
1429 is("$@","","\\$i works with $i buffers works with $i buffers '$str'=~/...$mid$backref/");
1435 # this mixture of readonly (not COWable) and COWable strings
1436 # messed up the capture buffers under COW. The actual test results
1437 # are incidental; the issue is was an AddressSanitizer failure
1441 for ($c, 'C', $c, 'DE') {
1442 ok(/(.)/, "COWable match");
1451 # /[#$x]/x didn't interpolate the var $x.
1454 $s =~ s/[a#$b%]/X/g;
1455 is ($s, 'XbXX$XX&', 'RT #45667 without /x');
1457 $s =~ s/[a#$b%]/X/gx;
1458 is ($s, 'XbXX$XX&', 'RT #45667 with /x');
1462 no warnings "uninitialized";
1466 pass('no crash with /@a/ when array has nonexistent elems');
1470 is runperl(prog => 'delete $::{qq-\cR-}; //; print qq-ok\n-'),
1472 'deleting *^R does not result in crashes';
1474 *^R = *caretRglobwithnoscalar;
1476 is $^R, 42, 'assigning to *^R does not result in a crash';
1480 .' q-..- =~ /(??{undef *^R;q--})(?{42})/; '
1485 'undefining *^R within (??{}) does not result in a crash';
1488 SKIP: { # Test literal range end point special handling
1489 unless ($::IS_EBCDIC) {
1490 skip "Valid only for EBCDIC", 24;
1493 like("\x89", qr/[i-j]/, '"\x89" should match [i-j]');
1494 unlike("\x8A", qr/[i-j]/, '"\x8A" shouldnt match [i-j]');
1495 unlike("\x90", qr/[i-j]/, '"\x90" shouldnt match [i-j]');
1496 like("\x91", qr/[i-j]/, '"\x91" should match [i-j]');
1498 like("\x89", qr/[i-\N{LATIN SMALL LETTER J}]/, '"\x89" should match [i-\N{LATIN SMALL LETTER J}]');
1499 unlike("\x8A", qr/[i-\N{LATIN SMALL LETTER J}]/, '"\x8A" shouldnt match [i-\N{LATIN SMALL LETTER J}]');
1500 unlike("\x90", qr/[i-\N{LATIN SMALL LETTER J}]/, '"\x90" shouldnt match [i-\N{LATIN SMALL LETTER J}]');
1501 like("\x91", qr/[i-\N{LATIN SMALL LETTER J}]/, '"\x91" should match [i-\N{LATIN SMALL LETTER J}]');
1503 like("\x89", qr/[i-\N{U+6A}]/, '"\x89" should match [i-\N{U+6A}]');
1504 unlike("\x8A", qr/[i-\N{U+6A}]/, '"\x8A" shouldnt match [i-\N{U+6A}]');
1505 unlike("\x90", qr/[i-\N{U+6A}]/, '"\x90" shouldnt match [i-\N{U+6A}]');
1506 like("\x91", qr/[i-\N{U+6A}]/, '"\x91" should match [i-\N{U+6A}]');
1508 like("\x89", qr/[\N{U+69}-\N{U+6A}]/, '"\x89" should match [\N{U+69}-\N{U+6A}]');
1509 unlike("\x8A", qr/[\N{U+69}-\N{U+6A}]/, '"\x8A" shouldnt match [\N{U+69}-\N{U+6A}]');
1510 unlike("\x90", qr/[\N{U+69}-\N{U+6A}]/, '"\x90" shouldnt match [\N{U+69}-\N{U+6A}]');
1511 like("\x91", qr/[\N{U+69}-\N{U+6A}]/, '"\x91" should match [\N{U+69}-\N{U+6A}]');
1513 like("\x89", qr/[i-\x{91}]/, '"\x89" should match [i-\x{91}]');
1514 like("\x8A", qr/[i-\x{91}]/, '"\x8A" should match [i-\x{91}]');
1515 like("\x90", qr/[i-\x{91}]/, '"\x90" should match [i-\x{91}]');
1516 like("\x91", qr/[i-\x{91}]/, '"\x91" should match [i-\x{91}]');
1518 # Need to use eval, because tries to compile on ASCII platforms even
1519 # though the tests are skipped, and fails because 0x89-j is an illegal
1521 like("\x89", eval "qr/[\x{89}-j]/", '"\x89" should match [\x{89}-j]');
1522 like("\x8A", eval "qr/[\x{89}-j]/", '"\x8A" should match [\x{89}-j]');
1523 like("\x90", eval "qr/[\x{89}-j]/", '"\x90" should match [\x{89}-j]');
1524 like("\x91", eval "qr/[\x{89}-j]/", '"\x91" should match [\x{89}-j]');
1527 # These are based on looking at the code in regcomp.c
1528 # We don't look for specific code, just the existence of an SSC
1529 foreach my $re (qw( qr/a?c/
1539 skip "no re-debug under miniperl" if is_miniperl;
1541 use re qw(Debug COMPILE);
1544 fresh_perl_like($prog, qr/synthetic stclass/, { stderr=>1 }, "$re generates a synthetic start class");
1549 like "\x{AA}", qr/a?[\W_]/d, "\\W with /d synthetic start class works";
1553 # Verify that the very last Latin-1 U+00FF
1554 # (LATIN SMALL LETTER Y WITH DIAERESIS)
1555 # and its UPPER counterpart (U+0178 which is pure Unicode),
1556 # and likewise for the very first pure Unicode
1557 # (LATIN CAPITAL LETTER A WITH MACRON) fold-match properly,
1558 # and there are no off-by-one logic errors in the transition zone.
1560 ok("\xFF" =~ /\xFF/i, "Y WITH DIAERESIS l =~ l");
1561 ok("\xFF" =~ /\x{178}/i, "Y WITH DIAERESIS l =~ u");
1562 ok("\x{178}" =~ /\xFF/i, "Y WITH DIAERESIS u =~ l");
1563 ok("\x{178}" =~ /\x{178}/i, "Y WITH DIAERESIS u =~ u");
1565 # U+00FF with U+05D0 (non-casing Hebrew letter).
1566 ok("\xFF\x{5D0}" =~ /\xFF\x{5D0}/i, "Y WITH DIAERESIS l =~ l");
1567 ok("\xFF\x{5D0}" =~ /\x{178}\x{5D0}/i, "Y WITH DIAERESIS l =~ u");
1568 ok("\x{178}\x{5D0}" =~ /\xFF\x{5D0}/i, "Y WITH DIAERESIS u =~ l");
1569 ok("\x{178}\x{5D0}" =~ /\x{178}\x{5D0}/i, "Y WITH DIAERESIS u =~ u");
1572 ok("\x{100}" =~ /\x{100}/i, "A WITH MACRON u =~ u");
1573 ok("\x{100}" =~ /\x{101}/i, "A WITH MACRON u =~ l");
1574 ok("\x{101}" =~ /\x{100}/i, "A WITH MACRON l =~ u");
1575 ok("\x{101}" =~ /\x{101}/i, "A WITH MACRON l =~ l");
1580 ok("abc" =~ /a
\85b
\85c/x, "NEL is white-space under /x");
1584 ok('a(b)c' =~ qr(a\(b\)c), "'\\(' is a literal in qr(...)");
1585 ok('a[b]c' =~ qr[a\[b\]c], "'\\[' is a literal in qr[...]");
1586 ok('a{3}c' =~ qr{a\{3\}c}, # Only failed when { could be a meta
1587 "'\\{' is a literal in qr{...}, where it could be a quantifier");
1589 # This one is for completeness
1590 ok('a<b>c' =~ qr<a\<b\>c>, "'\\<' is a literal in qr<...>)");
1593 { # Was getting optimized into EXACT (non-folding node)
1596 like("X", qr/$x/, "UTF-8 of /[x]/i matches upper case");
1599 { # make sure we get an error when \p{} cannot load Unicode tables
1600 fresh_perl_like(<<' prog that cannot load uni tables',
1603 require utf8; require 'utf8_heavy.pl';
1607 if ($name =~ /(\p{IsUpper}) (\p{IsUpper})/){
1608 print "It's good! >$1< >$2<\n";
1610 print "It's not good...\n";
1612 prog that cannot load uni tables
1613 qr/^Can't locate unicore\/Heavy\.pl(?x:
1614 )|^Can't find Unicode property definition/,
1616 '\p{} should not fail silently when uni tables evanesce');
1619 { # Special handling of literal-ended ranges in [...] was breaking this
1621 like("ÿ", qr/[ÿ-ÿ]/, "\"ÿ\" should match [ÿ-ÿ]");
1625 like("TffffffffffffTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT5TTTTTTTTTTTTTTTTTTTTTTTTT3TTgTTTTTTTTTTTTTTTTTTTTT2TTTTTTTTTTTTTTTTTTTTTTTHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHiHHHHHHHfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff&ffff", qr/TffffffffffffTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT5TTTTTTTTTTTTTTTTTTTTTTTTT3TTgTTTTTTTTTTTTTTTTTTTTT2TTTTTTTTTTTTTTTTTTTTTTTHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHiHHHHHHHfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff&ffff/il, "");
1626 like("TffffffffffffT\x{100}TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT5TTTTTTTTTTTTTTTTTTTTTTTTT3TTgTTTTTTTTTTTTTTTTTTTTT2TTTTTTTTTTTTTTTTTTTTTTTHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHiHHHHHHHfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff&ffff", qr/TffffffffffffT\x{100}TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT5TTTTTTTTTTTTTTTTTTTTTTTTT3TTgTTTTTTTTTTTTTTTTTTTTT2TTTTTTTTTTTTTTTTTTTTTTTHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHiHHHHHHHfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff&ffff/il, "");
1630 my($s, $x, @x) = ('abc', 'a', 'd');
1631 my $long = 'b' x 2000;
1632 my $eval = q{$s =~ m{$x[bbb]c} ? 1 : 0};
1633 $eval =~ s{bbb}{$long};
1634 my $match = eval $eval;
1635 ok(1, "did not crash");
1636 ok($match, "[bbb...] resolved as character class, not subscript");
1640 for my $pat ('(??', '(?P', '(?i-') {
1641 eval qq{ qr/$pat/ };
1642 ok(1, "qr/$pat/ did not crash");
1643 eval qq{ qr/${pat}\x{123}/ };
1645 like($e, qr{\x{123}},
1646 "qr/${pat}x/ shows x in error even if it's a wide character");
1651 # Expect one of these sizes to cause overflow and wrap to negative
1652 for my $bits (32, 64) {
1653 my $wrapneg = 2 ** ($bits - 2) * 3;
1654 for my $sign ('', '-') {
1655 my $pat = sprintf "qr/(?%s%u)/", $sign, $wrapneg;
1657 ok(1, "big backref $pat did not crash");
1662 # Test that we handle qr/\8888888/ and variants without an infinite loop,
1663 # we use a test within a test so we can todo it, and make sure we don't
1664 # infinite loop our tests.
1665 # NOTE - Do not put quotes in the code!
1666 # NOTE - We have to triple escape the backref in the pattern below.
1668 BEGIN{require q(test.pl);}
1670 for my $len (1 .. 20) {
1671 my $eights= q(8) x $len;
1672 eval qq{ qr/\\\\$eights/ };
1674 print q(No infinite loop here!);
1676 fresh_perl_is($code, "No infinite loop here!", {},
1677 "test that we handle things like m/\\888888888/ without infinite loops" );
1679 } # End of sub run_tests