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.
16 my $EXPECTED_TESTS = 4066; # Update this when adding/deleting tests.
23 our $Message = "Noname test";
29 our $running_as_thread;
31 my $ordA = ord ('A'); # This defines ASCII/UTF-8 vs EBCDIC/UTF-EBCDIC
32 # This defined the platform.
33 my $IS_ASCII = $ordA == 65;
34 my $IS_EBCDIC = $ordA == 193;
37 eval 'use Config'; # Defaults assumed if this fails
41 print "1..$EXPECTED_TESTS\n";
43 run_tests unless caller ();
53 $mess =~ s/([\00-\37\177])/sprintf '\%03o', ord $1/eg;
59 defined($_) and s/#/\\#/g for $BugId, $PatchId, $TODO;
63 my ($ok, $mess, $error) = @_;
65 $mess = pretty ($mess // $Message);
66 $mess .= "; Bug $BugId" if defined $BugId;
67 $mess .= "; Patch $PatchId" if defined $PatchId;
68 $mess .= " # TODO $TODO" if defined $TODO;
70 my $line_nr = (caller(1)) [2];
72 printf "%sok %d - %s\n",
75 "$mess\tLine $line_nr";
78 print "# Failed test at line $line_nr\n" unless defined $TODO;
79 if ($error //= $Error) {
82 $error = join "\n#", map {pretty $_} split /\n\h*#/ => $error;
83 $error = "# $error" unless $error =~ /^\h*#/;
91 # Force scalar context on the pattern match
92 sub ok ($;$$) {_ok $_ [0], $_ [1], $_ [2]}
93 sub nok ($;$$) {_ok !$_ [0], "Failed: " . ($_ [1] // $Message), $_ [2]}
100 $why .= "; Bug $BugId" if defined $BugId;
101 # seems like the new harness code doesnt like todo and skip to be mixed.
102 # which seems like a bug in the harness to me. -- dmq
103 #$why .= " # TODO $TODO" if defined $TODO;
106 my $line_nr = (caller(0)) [2];
109 #print "not " if defined $TODO;
110 print "ok $test # skip $why\tLine $line_nr\n";
112 no warnings "exiting";
117 my ($got, $expect, $name) = @_;
119 $_ = defined ($_) ? "'$_'" : "undef" for $got, $expect;
121 my $ok = $got eq $expect;
122 my $error = "# expected: $expect\n" .
125 _ok $ok, $name, $error;
129 my ($got, $expect, $name) = @_;
130 my $todo = $TODO ? " # TODO $TODO" : '';
132 $_ = defined ($_) ? "'$_'" : "undef" for $got, $expect;
134 my $ok = $got ne $expect;
135 my $error = "# results are equal ($got)";
137 _ok $ok, $name, $error;
142 my ($code, $name) = @_;
145 _ok eval {&$code} && !$@, $name;
148 _ok eval ($code) && !$@, $name;
153 my ($code, $pattern, $name) = @_;
154 $pattern //= $DiePattern;
156 ref $code ? &$code : eval $code;
157 my $r = $@ && $@ =~ /$pattern/;
158 _ok $r, $name // $Message // "\$\@ =~ /$pattern/";
162 my ($code, $pattern, $name) = @_;
163 $pattern //= $WarnPattern;
165 local $SIG {__WARN__} = sub {$w .= join "" => @_};
167 ref $code ? &$code : eval $code;
168 my $r = $w && $w =~ /$pattern/;
170 _ok $r, $name // $Message // "Got warning /$pattern/",
171 "# expected: /$pattern/\n" .
176 my ($code, $name) = @_;
178 local $SIG {__WARN__} = sub {$w .= join "" => @_};
180 ref $code ? &$code : eval $code;
181 _ok !$w, $name // ($Message ? "$Message (did not warn)"
194 my $x = "abc\ndef\n";
196 ok $x =~ /^abc/, qq ["$x" =~ /^abc/];
197 ok $x !~ /^def/, qq ["$x" !~ /^def/];
199 # used to be a test for $*
200 ok $x =~ /^def/m, qq ["$x" =~ /^def/m];
202 nok $x =~ /^xxx/, qq ["$x" =~ /^xxx/];
203 nok $x !~ /^abc/, qq ["$x" !~ /^abc/];
205 ok $x =~ /def/, qq ["$x" =~ /def/];
206 nok $x !~ /def/, qq ["$x" !~ /def/];
208 ok $x !~ /.def/, qq ["$x" !~ /.def/];
209 nok $x =~ /.def/, qq ["$x" =~ /.def/];
211 ok $x =~ /\ndef/, qq ["$x" =~ /\ndef/];
212 nok $x !~ /\ndef/, qq ["$x" !~ /\ndef/];
217 ok /^([0-9][0-9]*)/, qq [\$_ = '$_'; /^([0-9][0-9]*)/];
222 ok /(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc',
223 qq [\$_ = '$_'; /(a*b*)(c*)/];
224 ok /(a+b+c+)/ && $1 eq 'aaabbbccc', qq [\$_ = '$_'; /(a+b+c+)/];
225 nok /a+b?c+/, qq [\$_ = '$_'; /a+b?c+/];
228 ok /a+b?c+/, qq [\$_ = '$_'; /a+b?c+/];
229 ok /a*b?c*/, qq [\$_ = '$_'; /a*b?c*/];
232 ok /a*b?c*/, qq [\$_ = '$_'; /a*b?c*/];
233 nok /a*b+c*/, qq [\$_ = '$_'; /a*b+c*/];
236 ok /bcd|xyz/, qq [\$_ = '$_'; /bcd|xyz/];
237 ok /xyz|bcd/, qq [\$_ = '$_'; /xyz|bcd/];
238 ok m|bc/*d|, qq [\$_ = '$_'; m|bc/*d|];
239 ok /^$_$/, qq [\$_ = '$_'; /^\$_\$/];
243 # used to be a test for $*
244 ok "ab\ncd\n" =~ /^cd/m, qq ["ab\ncd\n" =~ /^cd/m];
248 our %XXX = map {($_ => $_)} 123, 234, 345;
250 our @XXX = ('ok 1','not ok 1', 'ok 2','not ok 2','not ok 3');
251 while ($_ = shift(@XXX)) {
252 my $f = index ($_, 'not') >= 0 ? \&nok : \&ok;
270 ok !keys %XXX, "%XXX is empty";
276 local $Message = "Test empty pattern";
291 no warnings 'uninitialized';
301 local $Message = q !Check $`, $&, $'!;
303 /def/; # optimized up to cmd
304 iseq "$`:$&:$'", 'abc:def:ghi';
307 /cde/ + 0; # optimized only to spat
308 iseq "$`:$&:$'", 'ab:cde:fghi';
310 /[d][e][f]/; # not optimized
311 iseq "$`:$&:$'", 'abc:def:ghi';
315 $_ = 'now is the {time for all} good men to come to.';
317 iseq $1, 'time for all', "Match braces";
321 local $Message = "{N,M} quantifier";
322 $_ = 'xxx {3,4} yyy zzz';
335 local $Message = "Test /g";
337 $_ = "now is the time for all good men to come to.";
338 my @words = /(\w+)/g;
339 my $exp = "now:is:the:time:for:all:good:men:to:come:to";
354 iseq "@words", "to:to";
358 iseq "@words", "to:to";
374 my $t1 = my $t2 = my $t3 = my $t4 = my $t5 =
375 my $t6 = my $t7 = my $t8 = my $t9 = 0;
377 for my $iter (1 .. 5) {
388 my $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
389 iseq $x, '505550555', "Test /o";
395 ok "abc" =~ /^abc$|$xyz/, "| after \$";
397 # perl 4.009 says "unmatched ()"
398 local $Message = '$ inside ()';
401 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
402 iseq $@, "" or skip "eval failed", 1;
403 iseq $result, "abc:bc";
408 local $Message = "Scalar /g";
411 ok /abc/g && $` eq "";
412 ok /abc/g && $` eq "abcfoo";
415 local $Message = "Scalar /gi";
417 ok /ABC/gi && $` eq "";
418 ok /ABC/gi && $` eq "abcfoo";
421 local $Message = "Scalar /g";
423 ok /abc/g && $' eq "fooabcbar";
424 ok /abc/g && $' eq "bar";
428 iseq @x, 2, "/g reset after assignment";
432 local $Message = '/g, \G and pos';
442 local $Message = '(?{ })';
444 'abc' =~ m'a(?{ $out = 2 })b';
448 'abc' =~ m'a(?{ $out = 3 })c';
454 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
455 my @out = /(?<!foo)bar./g;
456 iseq "@out", 'bar2 barf', "Negative lookbehind";
460 local $Message = "REG_INFTY tests";
461 # Tests which depend on REG_INFTY
462 $::reg_infty = $Config {reg_infty} // 32767;
463 $::reg_infty_m = $::reg_infty - 1;
464 $::reg_infty_p = $::reg_infty + 1;
465 $::reg_infty_m = $::reg_infty_m; # Surpress warning.
467 # As well as failing if the pattern matches do unexpected things, the
468 # next three tests will fail if you should have picked up a lower-than-
469 # default value for $reg_infty from Config.pm, but have not.
471 eval_ok q (('aaa' =~ /(a{1,$::reg_infty_m})/)[0] eq 'aaa');
472 eval_ok q (('a' x $::reg_infty_m) =~ /a{$::reg_infty_m}/);
473 eval_ok q (('a' x ($::reg_infty_m - 1)) !~ /a{$::reg_infty_m}/);
474 eval "'aaa' =~ /a{1,$::reg_infty}/";
475 ok $@ =~ /^\QQuantifier in {,} bigger than/;
476 eval "'aaa' =~ /a{1,$::reg_infty_p}/";
477 ok $@ =~ /^\QQuantifier in {,} bigger than/;
481 # Poke a couple more parse failures
482 my $context = 'x' x 256;
483 eval qq("${context}y" =~ /(?<=$context)y/);
484 ok $@ =~ /^\QLookbehind longer than 255 not/, "Lookbehind limit";
489 local $Message = "Long monster";
490 for my $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
492 local $Error = "length = $l";
493 ok "ba$a=" =~ /a$a=/;
494 nok "b$a=" =~ /a$a=/;
497 ok "ba$a=" =~ /b(?:a|b)+=/;
503 # 20000 nodes, each taking 3 words per string, and 1 per branch
504 my $long_constant_len = join '|', 12120 .. 32645;
505 my $long_var_len = join '|', 8120 .. 28645;
506 my %ans = ( 'ax13876y25677lbc' => 1,
507 'ax13876y25677mcb' => 0, # not b.
508 'ax13876y35677nbc' => 0, # Num too big
509 'ax13876y25677y21378obc' => 1,
510 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
511 'ax13876y25677y21378y21378kbc' => 1,
512 'ax13876y25677y21378y21378kcb' => 0, # Not b.
513 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
516 local $Message = "20000 nodes";
518 local $Error = "const-len '$_'";
519 ok !($ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o);
521 local $Error = "var-len '$_'";
522 ok !($ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o);
527 local $Message = "Complicated backtracking";
528 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
529 my $expect = "(bla()) ((l)u((e))) (l(e)e)";
536 (?{ $c = 1 }) # Initialize
538 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
540 ) # Fail: will unwind one iteration back
543 [^()]+ # Match a big chunk
546 ) # Do not try to match subchunks
554 )+ # This may not match with different subblocks
559 ) # Otherwise the chunk 1 may succeed with $c>0
565 push @ans, $res while $res = matchit;
566 iseq "@ans", "1 1 1";
569 iseq "@ans", $expect;
571 local $Message = "Recursion with (??{ })";
573 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
575 @ans = my @ans1 = ();
576 push (@ans, $res), push (@ans1, $&) while $res = m/$matched/g;
578 iseq "@ans", "1 1 1";
579 iseq "@ans1", $expect;
582 iseq "@ans", $expect;
587 ok "abc" =~ /^(??{"a"})b/, '"abc" =~ /^(??{"a"})b/';
591 my @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
592 iseq "@ans", 'a/ b', "Stack may be bad";
596 local $Message = "Eval-group not allowed at runtime";
597 my $code = '{$blah = 45}';
600 ok $@ && $@ =~ /not allowed at runtime/ && $blah == 12;
602 for $code ('{$blah = 45}','=xx') {
604 my $res = eval { "xx" =~ /(?$code)/o };
605 no warnings 'uninitialized';
606 local $Error = "'$@', '$res', '$blah'";
607 if ($code eq '=xx') {
611 ok $@ && $@ =~ /not allowed at runtime/ && $blah == 12;
615 $code = '{$blah = 45}';
626 local $Message = "Pos checks";
640 iseq f (pos ($x)), 4;
644 local $Message = 'Checking $^R';
646 'foot' =~ /foo(?{$x = 12; 75})[t]/;
650 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
651 ok $^R eq '67' && $x eq '12';
654 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
655 ok $^R eq '79' && $x eq '12';
659 iseq qr/\b\v$/i, '(?i-xsm:\b\v$)', 'qr/\b\v$/i';
660 iseq qr/\b\v$/s, '(?s-xim:\b\v$)', 'qr/\b\v$/s';
661 iseq qr/\b\v$/m, '(?m-xis:\b\v$)', 'qr/\b\v$/m';
662 iseq qr/\b\v$/x, '(?x-ism:\b\v$)', 'qr/\b\v$/x';
663 iseq qr/\b\v$/xism, '(?msix:\b\v$)', 'qr/\b\v$/xism';
664 iseq qr/\b\v$/, '(?-xism:\b\v$)', 'qr/\b\v$/';
669 local $Message = "Look around";
672 foreach my $ans ('', 'c') {
673 ok /(?<=(?=a)..)((?=c)|.)/g or skip "Match failed", 1;
679 local $Message = "Empty clause";
681 foreach my $ans ('', 'a', '') {
682 ok /^|a|$/g or skip "Match failed", 1;
688 local $Message = "Prefixify";
691 my ($v, $a, $b, $res) = @_;
692 ok $v =~ s/\Q$a\E/$b/ or skip "Match failed", 1;
697 prefixify ('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
698 prefixify ('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
704 ok $1 && /$1/, "Capture a quote";
708 local $Message = "Call code from qr //";
711 ok /$a$a/ && $b eq '9';
714 ok /$a$a/ && $b eq '11';
718 ok $@ && $@ =~ /not allowed at runtime/;
727 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
735 my $match = eval { /$a$c$a/ };
736 ok $@ && $@ =~ /Eval-group not allowed/ && !$match;
743 $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
753 no warnings 'closure';
754 local $Message = '(?{ $var } refers to package vars';
758 '' =~ /(?{ $c = 4 })/;
765 must_die 'q(a:[b]:) =~ /[x[:foo:]]/',
766 'POSIX class \[:[^:]+:\] unknown in regex',
767 'POSIX class [: :] must have valid name';
769 for my $d (qw [= .]) {
770 must_die "/[[${d}foo${d}]]/",
771 "\QPOSIX syntax [$d $d] is reserved for future extensions",
772 "POSIX syntax [[$d $d]] is an error";
778 # test if failure of patterns returns empty list
779 local $Message = "Failed pattern returns empty list";
796 local $Message = '@- and @+ tests';
803 ok !defined $+ [1] && !defined $- [1] &&
804 !defined $+ [2] && !defined $- [2];
815 ok !defined $+ [3] && !defined $- [3] &&
816 !defined $+ [4] && !defined $- [4];
826 ok !defined $+ [2] && !defined $- [2] &&
827 !defined $+ [4] && !defined $- [4];
837 ok !defined $+ [2] && !defined $- [2] &&
838 !defined $+ [3] && !defined $- [3];
847 local $DiePattern = '^Modification of a read-only value attempted';
848 local $Message = 'Elements of @- and @+ are read-only';
849 must_die '$+[0] = 13';
850 must_die '$-[0] = 13';
851 must_die '@+ = (7, 6, 5)';
852 must_die '@- = qw (foo bar)';
857 local $Message = '\G testing';
869 ok $str =~ /\G../ && $& eq 'cd';
871 local $TODO = $running_as_thread;
872 ok $str =~ /.\G./ && $& eq 'bc';
877 local $Message = 'pos inside (?{ })';
880 ok $str =~ /b(?{$foo = $_; $bar = pos})c/;
883 ok !defined pos ($str);
888 ok $str =~ /b(?{$foo = $_; $bar = pos})c/g;
896 ok /b(?{$foo = $_; $bar = pos})c/;
902 ok /b(?{$foo = $_; $bar = pos})c/g;
910 1 while /b(?{$foo = $_; $bar = pos})c/g;
918 ok s/b(?{$foo = $_; $bar = pos})c/x/g;
919 iseq $foo, 'abcde|abcde';
921 iseq $_, 'axde|axde';
926 () = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
927 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
928 iseq "@res", "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
931 () = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
932 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
933 iseq "@res", "'' 'ab' 'cde|abcde' " .
934 "'' 'abc' 'de|abcde' " .
935 "'abcd' 'e|' 'abcde' " .
936 "'abcde|' 'ab' 'cde' " .
937 "'abcde|' 'abc' 'de'" ;
942 local $Message = '\G anchor checks';
943 my $foo = 'aabbccddeeffgg';
946 local $TODO = $running_as_thread;
947 no warnings 'uninitialized';
948 ok $foo =~ /.\G(..)/g;
952 ok $foo =~ /.\G(..)/g;
956 ok $foo =~ /.\G(..)/g;
963 ok $foo =~ /\G(..)/g;
966 ok $foo =~ /\G(..)/g;
970 ok $foo =~ /\G(..)/g;
977 my @res = /(\d*|x)/g;
979 iseq "@res", "123||x|123|", "0 match in alternation";
984 local $Message = "Match against temporaries (created via pp_helem())" .
986 ok {foo => "bar\n" . $^X} -> {foo} =~ /^(.*)\n/g;
992 local $Message = 'package $i inside (?{ }), ' .
993 'saved substrings and changing $_';
994 our @a = qw [foo bar];
996 s/(\w)(?{push @b, $1})/,$1,/g for @a;
997 iseq "@b", "f o o b a r";
998 iseq "@a", ",f,,o,,o, ,b,,a,,r,";
1000 local $Message = 'lexical $i inside (?{ }), ' .
1001 'saved substrings and changing $_';
1002 no warnings 'closure';
1003 my @c = qw [foo bar];
1005 s/(\w)(?{push @d, $1})/,$1,/g for @c;
1006 iseq "@d", "f o o b a r";
1007 iseq "@c", ",f,,o,,o, ,b,,a,,r,";
1012 local $Message = 'Brackets';
1015 { (?> [^{}]+ | (??{ $brackets }) )* }
1018 ok "{{}" =~ $brackets;
1020 ok "something { long { and } hairy" =~ $brackets;
1022 ok "something { long { and } hairy" =~ m/((??{ $brackets }))/;
1030 nok m/^-.*bb/mg, '$_ = "a-a\nxbb"; m/^-.*bb/mg';
1035 local $Message = '\G anchor checks';
1036 my $text = "aaXbXcc";
1038 ok $text !~ /\GXb*X/g;
1044 nok /^\s*A/m, '$_ = "xA\n" x 500; /^\s*A/m"';
1046 my $text = "abc dbf";
1047 my @res = ($text =~ /.*?(b).*?\b/g);
1048 iseq "@res", "b b", '\b is not special';
1053 local $Message = '\S, [\S], \s, [\s]';
1054 my @a = map chr, 0 .. 255;
1055 my @b = grep /\S/, @a;
1056 my @c = grep /[^\s]/, @a;
1060 @c = grep /[\S]/, @a;
1064 @c = grep /[^\S]/, @a;
1068 @c = grep /[\s]/, @a;
1072 local $Message = '\D, [\D], \d, [\d]';
1073 my @a = map chr, 0 .. 255;
1074 my @b = grep /\D/, @a;
1075 my @c = grep /[^\d]/, @a;
1079 @c = grep /[\D]/, @a;
1083 @c = grep /[^\D]/, @a;
1087 @c = grep /[\d]/, @a;
1091 local $Message = '\W, [\W], \w, [\w]';
1092 my @a = map chr, 0 .. 255;
1093 my @b = grep /\W/, @a;
1094 my @c = grep /[^\w]/, @a;
1098 @c = grep /[\W]/, @a;
1102 @c = grep /[^\W]/, @a;
1106 @c = grep /[\w]/, @a;
1112 # see if backtracking optimization works correctly
1113 local $Message = 'Backtrack optimization';
1114 ok "\n\n" =~ /\n $ \n/x;
1115 ok "\n\n" =~ /\n* $ \n/x;
1116 ok "\n\n" =~ /\n+ $ \n/x;
1117 ok "\n\n" =~ /\n? $ \n/x;
1118 ok "\n\n" =~ /\n*? $ \n/x;
1119 ok "\n\n" =~ /\n+? $ \n/x;
1120 ok "\n\n" =~ /\n?? $ \n/x;
1121 ok "\n\n" !~ /\n*+ $ \n/x;
1122 ok "\n\n" !~ /\n++ $ \n/x;
1123 ok "\n\n" =~ /\n?+ $ \n/x;
1129 use overload '""' => sub {'Object S'};
1132 local $Message = "Ref stringification";
1133 ::ok do { \my $v} =~ /^SCALAR/, "Scalar ref stringification";
1134 ::ok do {\\my $v} =~ /^REF/, "Ref ref stringification";
1135 ::ok [] =~ /^ARRAY/, "Array ref stringification";
1136 ::ok {} =~ /^HASH/, "Hash ref stringification";
1137 ::ok 'S' -> new =~ /^Object S/, "Object stringification";
1142 local $Message = "Test result of match used as match";
1143 ok 'a1b' =~ ('xyz' =~ /y/);
1145 ok 'a1b' =~ ('xyz' =~ /t/);
1151 local $Message = '"1" is not \s';
1152 may_not_warn sub {ok ("1\n" x 102) !~ /^\s*\n/m};
1157 local $Message = '\s, [[:space:]] and [[:blank:]]';
1158 my %space = (spc => " ",
1163 # There's no \v but the vertical tabulator seems miraculously
1164 # be 11 both in ASCII and EBCDIC.
1168 my @space0 = sort grep {$space {$_} =~ /\s/ } keys %space;
1169 my @space1 = sort grep {$space {$_} =~ /[[:space:]]/} keys %space;
1170 my @space2 = sort grep {$space {$_} =~ /[[:blank:]]/} keys %space;
1172 iseq "@space0", "cr ff lf spc tab";
1173 iseq "@space1", "cr ff lf spc tab vt";
1174 iseq "@space2", "spc tab";
1179 local $BugId = '20000731.001';
1180 ok "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/,
1181 "Match UTF-8 char in presense of (??{ })";
1186 local $BugId = '20001021.005';
1187 no warnings 'uninitialized';
1188 ok undef =~ /^([^\/]*)(.*)$/, "Used to cause a SEGV";
1194 local $Message = '\C matches octet';
1196 ok /(.)(\C)(\C)(.)/ or skip q [\C doesn't match], 4;
1198 if ($IS_ASCII) { # ASCII (or equivalent), should be UTF-8
1202 elsif ($IS_EBCDIC) { # EBCDIC (or equivalent), should be UTF-EBCDIC
1208 ok 0, "Unexpected platform", "ord ('A') = $ordA";
1209 skip "Unexpected platform";
1218 local $Message = '\C matches octet';
1220 ok /(\C)/g or skip q [\C doesn't match], 2;
1224 elsif ($IS_EBCDIC) {
1228 ok 0, "Unexpected platform", "ord ('A') = $ordA";
1230 ok /(\C)/g or skip q [\C doesn't match];
1234 elsif ($IS_EBCDIC) {
1238 ok 0, "Unexpected platform", "ord ('A') = $ordA";
1244 # Japhy -- added 03/03/2001
1245 () = (my $str = "abc") =~ /(...)/;
1247 iseq $1, "abc", 'Changing subject does not modify $1';
1253 # The trick is that in EBCDIC the explicit numeric range should
1254 # match (as also in non-EBCDIC) but the explicit alphabetic range
1256 ok "\x8e" =~ /[\x89-\x91]/, '"\x8e" =~ /[\x89-\x91]/';
1257 ok "\xce" =~ /[\xc9-\xd1]/, '"\xce" =~ /[\xc9-\xd1]/';
1259 skip "Not an EBCDIC platform", 2 unless ord ('i') == 0x89 &&
1262 # In most places these tests would succeed since \x8e does not
1263 # in most character sets match 'i' or 'j' nor would \xce match
1264 # 'I' or 'J', but strictly speaking these tests are here for
1265 # the good of EBCDIC, so let's test these only there.
1266 nok "\x8e" !~ /[i-j]/, '"\x8e" !~ /[i-j]/';
1267 nok "\xce" !~ /[I-J]/, '"\xce" !~ /[I-J]/';
1272 ok "\x{ab}" =~ /\x{ab}/, '"\x{ab}" =~ /\x{ab}/ ';
1273 ok "\x{abcd}" =~ /\x{abcd}/, '"\x{abcd}" =~ /\x{abcd}/';
1278 local $Message = 'bug id 20001008.001';
1280 my @x = ("stra\337e 138", "stra\337e 138");
1282 ok s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1283 ok my ($latin) = /^(.+)(?:\s+\d)/;
1284 iseq $latin, "stra\337e";
1285 ok $latin =~ s/stra\337e/straße/;
1287 # Previous code follows, but outcommented - there were no tests.
1289 # $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1290 # use utf8; # needed for the raw UTF-8
1291 # $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1297 local $Message = 'Test \x escapes';
1298 ok "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1299 ok "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1300 ok "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1301 ok "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1302 ok "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1303 ok "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1304 ok "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1305 ok "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1310 local $BugId = '20001028.003';
1312 # Fist half of the bug.
1313 local $Message = 'HEBREW ACCENT QADMA matched by .*';
1315 ok my ($Y) = $X =~ /(.*)/;
1317 iseq length ($Y), 1;
1319 # Second half of the bug.
1320 $Message = 'HEBREW ACCENT QADMA in replacement';
1322 $X =~ s/^/chr(1488)/e;
1324 iseq ord ($X), 1488;
1329 local $BugId = '20001108.001';
1330 local $Message = 'Repeated s///';
1331 my $X = "Szab\x{f3},Bal\x{e1}zs";
1333 $Y =~ s/(B)/$1/ for 0 .. 3;
1335 iseq $X, "Szab\x{f3},Bal\x{e1}zs";
1340 local $BugId = '20000517.001';
1341 local $Message = 's/// on UTF-8 string';
1344 iseq $x, "\x{100}B";
1350 local $BugId = '20001230.002';
1351 local $Message = '\C and É';
1352 ok "École" =~ /^\C\C(.)/ && $1 eq 'c';
1353 ok "École" =~ /^\C\C(c)/;
1359 local $Message = 'Match code points > 255';
1360 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1361 ok /(.\x{300})./ or skip "No match", 4;
1362 ok $` eq "abc\x{100}" && length ($`) == 4;
1363 ok $& eq "\x{200}\x{300}\x{380}" && length ($&) == 3;
1364 ok $' eq "\x{400}defg" && length ($') == 5;
1365 ok $1 eq "\x{200}\x{300}" && length ($1) == 2;
1370 # The original bug report had 'no utf8' here but that was irrelevant.
1371 local $BugId = '20010306.008';
1372 local $Message = "Don't dump core";
1373 my $a = "a\x{1234}";
1374 ok $a =~ m/\w/; # used to core dump.
1379 local $BugId = '20010410.006';
1380 local $Message = '/g in scalar context';
1381 for my $rx ('/(.*?)\{(.*?)\}/csg',
1382 '/(.*?)\{(.*?)\}/cg',
1383 '/(.*?)\{(.*?)\}/sg',
1384 '/(.*?)\{(.*?)\}/g',
1385 '/(.+?)\{(.+?)\}/csg',) {
1387 my $input = "a{b}c{d}";
1389 while (eval \$input =~ $rx) {
1399 my $x = "\x{10FFFD}";
1401 ok ord($x) == 0x10FFFD && length($x) == 1, "From Robin Houston";
1413 while (my ($code, $match) = each %d) {
1414 local $Message = "Properties of \\x$code";
1415 my $char = eval qq ["\\x{$code}"];
1417 ok (($char =~ /[\x80-\xff]/) xor !$$match [$i ++]);
1418 ok (($char =~ /[\x80-\x{100}]/) xor !$$match [$i ++]);
1419 ok (($char =~ /[\x{100}]/) xor !$$match [$i ++]);
1427 must_warn 'qr/(?c)/', '^Useless \(\?c\)';
1428 must_warn 'qr/(?-c)/', '^Useless \(\?-c\)';
1429 must_warn 'qr/(?g)/', '^Useless \(\?g\)';
1430 must_warn 'qr/(?-g)/', '^Useless \(\?-g\)';
1431 must_warn 'qr/(?o)/', '^Useless \(\?o\)';
1432 must_warn 'qr/(?-o)/', '^Useless \(\?-o\)';
1434 # Now test multi-error regexes
1435 must_warn 'qr/(?g-o)/', '^Useless \(\?g\).*\nUseless \(\?-o\)';
1436 must_warn 'qr/(?g-c)/', '^Useless \(\?g\).*\nUseless \(\?-c\)';
1437 # (?c) means (?g) error won't be thrown
1438 must_warn 'qr/(?o-cg)/', '^Useless \(\?o\).*\nUseless \(\?-c\)';
1439 must_warn 'qr/(?ogc)/', '^Useless \(\?o\).*\nUseless \(\?g\).*\n' .
1445 local $Message = "/x tests";
1465 local $Message = "/o feature";
1466 sub test_o {$_ [0] =~ /$_[1]/o; return $1}
1467 iseq test_o ('abc', '(.)..'), 'a';
1468 iseq test_o ('abc', '..(.)'), 'a';
1473 local $BugId = "20010619.003";
1474 # Amazingly vertical tabulator is the same in ASCII and EBCDIC.
1475 for ("\n", "\t", "\014", "\r") {
1476 ok !/[[:print:]]/, "'$_' not in [[:print:]]";
1479 ok /[[:print:]]/, "'$_' in [[:print:]]";
1485 # Test basic $^N usage outside of a regex
1486 local $Message = '$^N usage outside of a regex';
1488 ok ($x =~ /cde/ and !defined $^N);
1489 ok ($x =~ /(cde)/ and $^N eq "cde");
1490 ok ($x =~ /(c)(d)(e)/ and $^N eq "e");
1491 ok ($x =~ /(c(d)e)/ and $^N eq "cde");
1492 ok ($x =~ /(foo)|(c(d)e)/ and $^N eq "cde");
1493 ok ($x =~ /(c(d)e)|(foo)/ and $^N eq "cde");
1494 ok ($x =~ /(c(d)e)|(abc)/ and $^N eq "abc");
1495 ok ($x =~ /(c(d)e)|(abc)x/ and $^N eq "cde");
1496 ok ($x =~ /(c(d)e)(abc)?/ and $^N eq "cde");
1497 ok ($x =~ /(?:c(d)e)/ and $^N eq "d");
1498 ok ($x =~ /(?:c(d)e)(?:f)/ and $^N eq "d");
1499 ok ($x =~ /(?:([abc])|([def]))*/ and $^N eq "f");
1500 ok ($x =~ /(?:([ace])|([bdf]))*/ and $^N eq "f");
1501 ok ($x =~ /(([ace])|([bd]))*/ and $^N eq "e");
1502 {ok ($x =~ /(([ace])|([bdf]))*/ and $^N eq "f");}
1503 ## Test to see if $^N is automatically localized -- it should now
1504 ## have the value set in the previous test.
1505 iseq $^N, "e", '$^N is automatically localized';
1507 # Now test inside (?{ ... })
1508 local $Message = '$^N usage inside (?{ ... })';
1510 ok ($x =~ /a([abc])(?{$y=$^N})c/ and $y eq "b");
1511 ok ($x =~ /a([abc]+)(?{$y=$^N})d/ and $y eq "bc");
1512 ok ($x =~ /a([abcdefg]+)(?{$y=$^N})d/ and $y eq "bc");
1513 ok ($x =~ /(a([abcdefg]+)(?{$y=$^N})d)(?{$z=$^N})e/ and $y eq "bc"
1515 ok ($x =~ /(a([abcdefg]+)(?{$y=$^N})de)(?{$z=$^N})/ and $y eq "bc"
1523 ## Should probably put in tests for all the POSIX stuff,
1524 ## but not sure how to guarantee a specific locale......
1526 skip "Not an ASCII platform", 2 unless $IS_ASCII;
1527 local $Message = 'Test [[:cntrl:]]';
1528 my $AllBytes = join "" => map {chr} 0 .. 255;
1529 (my $x = $AllBytes) =~ s/[[:cntrl:]]//g;
1530 iseq $x, join "", map {chr} 0x20 .. 0x7E, 0x80 .. 0xFF;
1532 ($x = $AllBytes) =~ s/[^[:cntrl:]]//g;
1533 iseq $x, join "", map {chr} 0x00 .. 0x1F, 0x7F;
1538 # With /s modifier UTF8 chars were interpreted as bytes
1539 local $Message = "UTF-8 chars aren't bytes";
1540 my $a = "Hello \x{263A} World";
1541 my @a = ($a =~ /./gs);
1547 local $Message = '. matches \n with /s';
1548 my $str1 = "foo\nbar";
1549 my $str2 = "foo\n\x{100}bar";
1550 my ($a, $b) = map {chr} $IS_ASCII ? (0xc4, 0x80) : (0x8c, 0x41);
1552 @a = $str1 =~ /./g; iseq @a, 6; iseq "@a", "f o o b a r";
1553 @a = $str1 =~ /./gs; iseq @a, 7; iseq "@a", "f o o \n b a r";
1554 @a = $str1 =~ /\C/g; iseq @a, 7; iseq "@a", "f o o \n b a r";
1555 @a = $str1 =~ /\C/gs; iseq @a, 7; iseq "@a", "f o o \n b a r";
1556 @a = $str2 =~ /./g; iseq @a, 7; iseq "@a", "f o o \x{100} b a r";
1557 @a = $str2 =~ /./gs; iseq @a, 8; iseq "@a", "f o o \n \x{100} b a r";
1558 @a = $str2 =~ /\C/g; iseq @a, 9; iseq "@a", "f o o \n $a $b b a r";
1559 @a = $str2 =~ /\C/gs; iseq @a, 9; iseq "@a", "f o o \n $a $b b a r";
1564 # [ID 20010814.004] pos() doesn't work when using =~m// in list context
1565 local $BugId = '20010814.004';
1567 my $a = join ":", /b./gc;
1568 my $b = join ":", /a./gc;
1570 iseq "$a $b $c", 'ba:ba ad:ae 10', "pos() works with () = m//";
1575 # [ID 20010407.006] matching utf8 return values from
1576 # functions does not work
1577 local $BugId = '20010407.006';
1578 local $Message = 'UTF-8 return values from functions';
1579 package ID_20010407_006;
1585 ::ok length ($y) == 2 && $y eq $x;
1588 ::ok length ($y) == 2 && $y eq $x;
1593 no warnings 'digit';
1594 # Check that \x## works. 5.6.1 and 5.005_03 fail some of these.
1597 ok ($x =~ /^\x4EE$/, "Check only 2 bytes of hex are matched.");
1600 ok ($x =~ /^\x4Ei$/, "Check that invalid hex digit stops it (2)");
1603 ok ($x =~ /^\x4j$/, "Check that invalid hex digit stops it (1)");
1606 ok ($x =~ /^\xk$/, "Check that invalid hex digit stops it (0)");
1609 ok ($x =~ /^\xx$/, "\\xx isn't to be treated as \\0");
1612 ok ($x =~ /^\xxa$/, "\\xxa isn't to be treated as \\xa");
1615 ok ($x =~ /^\x9_b$/, "\\x9_b isn't to be treated as \\x9b");
1617 # and now again in [] ranges
1620 ok ($x =~ /^[\x4EE]{2}$/, "Check only 2 bytes of hex are matched.");
1623 ok ($x =~ /^[\x4Ei]{2}$/, "Check that invalid hex digit stops it (2)");
1626 ok ($x =~ /^[\x4j]{2}$/, "Check that invalid hex digit stops it (1)");
1629 ok ($x =~ /^[\xk]{2}$/, "Check that invalid hex digit stops it (0)");
1632 ok ($x =~ /^[\xx]{2}$/, "\\xx isn't to be treated as \\0");
1635 ok ($x =~ /^[\xxa]{3}$/, "\\xxa isn't to be treated as \\xa");
1638 ok ($x =~ /^[\x9_b]{3}$/, "\\x9_b isn't to be treated as \\x9b");
1640 # Check that \x{##} works. 5.6.1 fails quite a few of these.
1643 ok ($x =~ /^\x{9_b}$/, "\\x{9_b} is to be treated as \\x9b");
1646 ok ($x =~ /^\x{9_b}y$/, "\\x{9_b} is to be treated as \\x9b (again)");
1649 ok ($x =~ /^\x{9b_}y$/, "\\x{9b_} is to be treated as \\x9b");
1652 ok ($x =~ /^\x{9_bq}y$/, "\\x{9_bc} is to be treated as \\x9b");
1655 ok ($x =~ /^\x{x9b}y$/, "\\x{x9b} is to be treated as \\x0");
1658 ok ($x =~ /^\x{0x9b}y$/, "\\x{0x9b} is to be treated as \\x0");
1661 ok ($x =~ /^\x{09b}y$/, "\\x{09b} is to be treated as \\x9b");
1664 ok ($x =~ /^[\x{9_b}]$/, "\\x{9_b} is to be treated as \\x9b");
1667 ok ($x =~ /^[\x{9_b}y]{2}$/,
1668 "\\x{9_b} is to be treated as \\x9b (again)");
1671 ok ($x =~ /^[\x{9b_}y]{2}$/, "\\x{9b_} is to be treated as \\x9b");
1674 ok ($x =~ /^[\x{9_bq}y]{2}$/, "\\x{9_bc} is to be treated as \\x9b");
1677 ok ($x =~ /^[\x{x9b}y]{2}$/, "\\x{x9b} is to be treated as \\x0");
1680 ok ($x =~ /^[\x{0x9b}y]{2}$/, "\\x{0x9b} is to be treated as \\x0");
1683 ok ($x =~ /^[\x{09b}y]{2}$/, "\\x{09b} is to be treated as \\x9b");
1689 # High bit bug -- japhy
1691 ok $x =~ /.*?\200/, "High bit fine";
1696 # The basic character classes and Unicode
1697 ok "\x{0100}" =~ /\w/, 'LATIN CAPITAL LETTER A WITH MACRON in /\w/';
1698 ok "\x{0660}" =~ /\d/, 'ARABIC-INDIC DIGIT ZERO in /\d/';
1699 ok "\x{1680}" =~ /\s/, 'OGHAM SPACE MARK in /\s/';
1704 local $Message = "Folding matches and Unicode";
1705 ok "a\x{100}" =~ /A/i;
1706 ok "A\x{100}" =~ /a/i;
1707 ok "a\x{100}" =~ /a/i;
1708 ok "A\x{100}" =~ /A/i;
1709 ok "\x{101}a" =~ /\x{100}/i;
1710 ok "\x{100}a" =~ /\x{100}/i;
1711 ok "\x{101}a" =~ /\x{101}/i;
1712 ok "\x{100}a" =~ /\x{101}/i;
1713 ok "a\x{100}" =~ /A\x{100}/i;
1714 ok "A\x{100}" =~ /a\x{100}/i;
1715 ok "a\x{100}" =~ /a\x{100}/i;
1716 ok "A\x{100}" =~ /A\x{100}/i;
1717 ok "a\x{100}" =~ /[A]/i;
1718 ok "A\x{100}" =~ /[a]/i;
1719 ok "a\x{100}" =~ /[a]/i;
1720 ok "A\x{100}" =~ /[A]/i;
1721 ok "\x{101}a" =~ /[\x{100}]/i;
1722 ok "\x{100}a" =~ /[\x{100}]/i;
1723 ok "\x{101}a" =~ /[\x{101}]/i;
1724 ok "\x{100}a" =~ /[\x{101}]/i;
1729 use charnames ':full';
1730 local $Message = "Folding 'LATIN LETTER A WITH GRAVE'";
1732 my $lower = "\N{LATIN SMALL LETTER A WITH GRAVE}";
1733 my $UPPER = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";
1735 ok $lower =~ m/$UPPER/i;
1736 ok $UPPER =~ m/$lower/i;
1737 ok $lower =~ m/[$UPPER]/i;
1738 ok $UPPER =~ m/[$lower]/i;
1740 local $Message = "Folding 'GREEK LETTER ALPHA WITH VRACHY'";
1742 $lower = "\N{GREEK CAPITAL LETTER ALPHA WITH VRACHY}";
1743 $UPPER = "\N{GREEK SMALL LETTER ALPHA WITH VRACHY}";
1745 ok $lower =~ m/$UPPER/i;
1746 ok $UPPER =~ m/$lower/i;
1747 ok $lower =~ m/[$UPPER]/i;
1748 ok $UPPER =~ m/[$lower]/i;
1750 local $Message = "Folding 'LATIN LETTER Y WITH DIAERESIS'";
1752 $lower = "\N{LATIN SMALL LETTER Y WITH DIAERESIS}";
1753 $UPPER = "\N{LATIN CAPITAL LETTER Y WITH DIAERESIS}";
1755 ok $lower =~ m/$UPPER/i;
1756 ok $UPPER =~ m/$lower/i;
1757 ok $lower =~ m/[$UPPER]/i;
1758 ok $UPPER =~ m/[$lower]/i;
1763 use charnames ':full';
1764 local $PatchId = "13843";
1765 local $Message = "GREEK CAPITAL LETTER SIGMA vs " .
1766 "COMBINING GREEK PERISPOMENI";
1768 my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}";
1769 my $char = "\N{COMBINING GREEK PERISPOMENI}";
1771 may_not_warn sub {ok "_:$char:_" !~ m/_:$SIGMA:_/i};
1776 local $Message = '\X';
1777 use charnames ':full';
1779 ok "a!" =~ /^(\X)!/ && $1 eq "a";
1780 ok "\xDF!" =~ /^(\X)!/ && $1 eq "\xDF";
1781 ok "\x{100}!" =~ /^(\X)!/ && $1 eq "\x{100}";
1782 ok "\x{100}\x{300}!" =~ /^(\X)!/ && $1 eq "\x{100}\x{300}";
1783 ok "\N{LATIN CAPITAL LETTER E}!" =~ /^(\X)!/ &&
1784 $1 eq "\N{LATIN CAPITAL LETTER E}";
1785 ok "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}!"
1787 $1 eq "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}";
1789 local $Message = '\C and \X';
1790 ok "!abc!" =~ /a\Cc/;
1791 ok "!abc!" =~ /a\Xc/;
1796 local $Message = "Final Sigma";
1798 my $SIGMA = "\x{03A3}"; # CAPITAL
1799 my $Sigma = "\x{03C2}"; # SMALL FINAL
1800 my $sigma = "\x{03C3}"; # SMALL
1802 ok $SIGMA =~ /$SIGMA/i;
1803 ok $SIGMA =~ /$Sigma/i;
1804 ok $SIGMA =~ /$sigma/i;
1806 ok $Sigma =~ /$SIGMA/i;
1807 ok $Sigma =~ /$Sigma/i;
1808 ok $Sigma =~ /$sigma/i;
1810 ok $sigma =~ /$SIGMA/i;
1811 ok $sigma =~ /$Sigma/i;
1812 ok $sigma =~ /$sigma/i;
1814 ok $SIGMA =~ /[$SIGMA]/i;
1815 ok $SIGMA =~ /[$Sigma]/i;
1816 ok $SIGMA =~ /[$sigma]/i;
1818 ok $Sigma =~ /[$SIGMA]/i;
1819 ok $Sigma =~ /[$Sigma]/i;
1820 ok $Sigma =~ /[$sigma]/i;
1822 ok $sigma =~ /[$SIGMA]/i;
1823 ok $sigma =~ /[$Sigma]/i;
1824 ok $sigma =~ /[$sigma]/i;
1826 local $Message = "More final Sigma";
1828 my $S3 = "$SIGMA$Sigma$sigma";
1830 ok ":$S3:" =~ /:(($SIGMA)+):/i && $1 eq $S3 && $2 eq $sigma;
1831 ok ":$S3:" =~ /:(($Sigma)+):/i && $1 eq $S3 && $2 eq $sigma;
1832 ok ":$S3:" =~ /:(($sigma)+):/i && $1 eq $S3 && $2 eq $sigma;
1834 ok ":$S3:" =~ /:(([$SIGMA])+):/i && $1 eq $S3 && $2 eq $sigma;
1835 ok ":$S3:" =~ /:(([$Sigma])+):/i && $1 eq $S3 && $2 eq $sigma;
1836 ok ":$S3:" =~ /:(([$sigma])+):/i && $1 eq $S3 && $2 eq $sigma;
1841 use charnames ':full';
1842 local $Message = "Parlez-Vous " .
1843 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais?";
1845 ok "Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran.ais/ &&
1847 ok "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran.ais/ &&
1848 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais";
1849 ok "Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran\Cais/ &&
1851 # COMBINING CEDILLA is two bytes when encoded
1852 ok "Franc\N{COMBINING CEDILLA}ais" =~ /Franc\C\Cais/;
1853 ok "Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran\Xais/ &&
1855 ok "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran\Xais/ &&
1856 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais";
1857 ok "Franc\N{COMBINING CEDILLA}ais" =~ /Fran\Xais/ &&
1858 $& eq "Franc\N{COMBINING CEDILLA}ais";
1859 ok "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
1860 /Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais/ &&
1861 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais";
1862 ok "Franc\N{COMBINING CEDILLA}ais" =~ /Franc\N{COMBINING CEDILLA}ais/ &&
1863 $& eq "Franc\N{COMBINING CEDILLA}ais";
1866 ["Fran\N{LATIN SMALL LETTER C}ais", "Francais"],
1867 ["Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais",
1868 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais"],
1869 ["Franc\N{COMBINING CEDILLA}ais", "Franc\N{COMBINING CEDILLA}ais"],
1871 foreach my $entry (@f) {
1872 my ($subject, $match) = @$entry;
1873 ok $subject =~ /Fran(?:c\N{COMBINING CEDILLA}?|
1874 \N{LATIN SMALL LETTER C WITH CEDILLA})ais/x &&
1881 local $Message = "Lingering (and useless) UTF8 flag doesn't mess up /i";
1883 my $str = "abcDE\x{100}";
1887 $pat = "ABcde\x{100}";
1892 $pat = "ABcde\x{100}";
1893 $str = "abcDE\x{100}";
1901 use charnames ':full';
1902 local $Message = "LATIN SMALL LETTER SHARP S " .
1903 "(\N{LATIN SMALL LETTER SHARP S})";
1905 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1906 /\N{LATIN SMALL LETTER SHARP S}/;
1907 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1908 /\N{LATIN SMALL LETTER SHARP S}/i;
1909 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1910 /[\N{LATIN SMALL LETTER SHARP S}]/;
1911 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1912 /[\N{LATIN SMALL LETTER SHARP S}]/i;
1914 ok "ss" =~ /\N{LATIN SMALL LETTER SHARP S}/i;
1915 ok "SS" =~ /\N{LATIN SMALL LETTER SHARP S}/i;
1916 ok "ss" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i;
1917 ok "SS" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i;
1919 ok "\N{LATIN SMALL LETTER SHARP S}" =~ /ss/i;
1920 ok "\N{LATIN SMALL LETTER SHARP S}" =~ /SS/i;
1922 local $Message = "Unoptimized named sequence in class";
1923 ok "ss" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i;
1924 ok "SS" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i;
1925 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1926 /[\N{LATIN SMALL LETTER SHARP S}x]/;
1927 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1928 /[\N{LATIN SMALL LETTER SHARP S}x]/i;
1933 # More whitespace: U+0085, U+2028, U+2029\n";
1935 # U+0085, U+00A0 need to be forced to be Unicode, the \x{100} does that.
1937 skip "EBCDIC platform", 4 if $IS_EBCDIC;
1938 # Do \x{0015} and \x{0041} match \s in EBCDIC?
1939 ok "<\x{100}\x{0085}>" =~ /<\x{100}\s>/, '\x{0085} in \s';
1940 ok "<\x{0085}>" =~ /<\v>/, '\x{0085} in \v';
1941 ok "<\x{100}\x{00A0}>" =~ /<\x{100}\s>/, '\x{00A0} in \s';
1942 ok "<\x{00A0}>" =~ /<\h>/, '\x{00A0} in \h';
1944 my @h = map {sprintf "%05x" => $_} 0x01680, 0x0180E, 0x02000 .. 0x0200A,
1945 0x0202F, 0x0205F, 0x03000;
1946 my @v = map {sprintf "%05x" => $_} 0x02028, 0x02029;
1948 my @H = map {sprintf "%05x" => $_} 0x01361, 0x0200B, 0x02408, 0x02420,
1950 my @V = map {sprintf "%05x" => $_} 0x0008A .. 0x0008D, 0x00348, 0x10100,
1954 my $str = eval qq ["<\\x{$hex}>"];
1955 ok $str =~ /<\s>/, "\\x{$hex} in \\s";
1956 ok $str =~ /<\h>/, "\\x{$hex} in \\h";
1957 ok $str !~ /<\v>/, "\\x{$hex} not in \\v";
1961 my $str = eval qq ["<\\x{$hex}>"];
1962 ok $str =~ /<\s>/, "\\x{$hex} in \\s";
1963 ok $str =~ /<\v>/, "\\x{$hex} in \\v";
1964 ok $str !~ /<\h>/, "\\x{$hex} not in \\h";
1968 my $str = eval qq ["<\\x{$hex}>"];
1969 ok $str =~ /<\S>/, "\\x{$hex} in \\S";
1970 ok $str =~ /<\H>/, "\\x{$hex} in \\H";
1974 my $str = eval qq ["<\\x{$hex}>"];
1975 ok $str =~ /<\S>/, "\\x{$hex} in \\S";
1976 ok $str =~ /<\V>/, "\\x{$hex} in \\V";
1982 # . with /s should work on characters, as opposed to bytes
1983 local $Message = ". with /s works on characters, not bytes";
1985 my $s = "\x{e4}\x{100}";
1986 # This is not expected to match: the point is that
1987 # neither should we get "Malformed UTF-8" warnings.
1988 may_not_warn sub {$s =~ /\G(.+?)\n/gcs}, "No 'Malformed UTF-8' warning";
1991 push @c => $1 while $s =~ /\G(.)/gs;
1996 # Test only chars < 256
1997 my $t1 = "Q003\n\n\x{e4}\x{f6}\n\nQ004\n\n\x{e7}";
1999 while ($t1 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2003 my $t2 = $t1 . "\x{100}"; # Repeat with a larger char
2005 while ($t2 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2015 local $Message = "Unicode lookbehind";
2016 ok "A\x{100}B" =~ /(?<=A.)B/;
2017 ok "A\x{200}\x{300}B" =~ /(?<=A..)B/;
2018 ok "\x{400}AB" =~ /(?<=\x{400}.)B/;
2019 ok "\x{500}\x{600}B" =~ /(?<=\x{500}.)B/;
2021 # Original code also contained:
2022 # ok "\x{500\x{600}}B" =~ /(?<=\x{500}.)B/;
2023 # but that looks like a typo.
2028 local $Message = 'UTF-8 hash keys and /$/';
2029 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters
2030 # /2002-01/msg01327.html
2033 my $v = substr ($u, 0, 1);
2034 my $w = substr ($u, 1, 1);
2035 my %u = ($u => $u, $v => $v, $w => $w);
2037 my $m1 = /^\w*$/ ? 1 : 0;
2038 my $m2 = $u {$_} =~ /^\w*$/ ? 1 : 0;
2045 local $BugId = "20020124.005";
2046 local $PatchId = "14795";
2047 local $Message = "s///eg";
2049 for my $char ("a", "\x{df}", "\x{100}") {
2050 my $x = "$char b $char";
2055 iseq substr ($x, 0, 1), substr ($x, -1, 1);
2061 local $Message = "No SEGV in s/// and UTF-8";
2062 my $s = "s#\x{100}" x 4;
2063 ok $s =~ s/[^\w]/ /g;
2064 if ( $ENV{PERL_TEST_LEGACY_POSIX_CC} ) {
2065 iseq $s, "s \x{100}" x 4;
2074 local $Message = "UTF-8 bug (maybe already known?)";
2076 $u =~ s/./\x{100}/g;
2077 iseq $u, "\x{100}\x{100}\x{100}";
2080 $u =~ s/[ao]/\x{100}/g;
2081 iseq $u, "f\x{100}\x{100}b\x{100}r";
2083 $u =~ s/\x{100}/e/g;
2089 local $Message = "UTF-8 bug with s///";
2090 # check utf8/non-utf8 mixtures
2091 # try to force all float/anchored check combinations
2095 for my $re ("xx.*$c", "x.*$c$c", "$c.*xx", "$c$c.*x",
2096 "xx.*(?=$c)", "(?=$c).*xx",) {
2098 ok +($subst = "xxx") !~ s/$re//;
2100 for my $re ("xx.*$c*", "$c*.*xx") {
2102 ok +($subst = "xxx") =~ s/$re//;
2105 for my $re ("xxy*", "y*xx") {
2107 ok +($subst = "xx$c") =~ s/$re//;
2110 ok +($subst = "xy$c") !~ s/$re//;
2112 for my $re ("xy$c*z", "x$c*yz") {
2114 ok +($subst = "xyz") =~ s/$re//;
2121 local $Message = "qr /.../x";
2122 my $R = qr / A B C # D E/x;
2123 ok "ABCDE" =~ $R && $& eq "ABC";
2124 ok "ABCDE" =~ /$R/ && $& eq "ABC";
2125 ok "ABCDE" =~ m/$R/ && $& eq "ABC";
2126 ok "ABCDE" =~ /($R)/ && $1 eq "ABC";
2127 ok "ABCDE" =~ m/($R)/ && $1 eq "ABC";
2132 local $BugId = "20020412.005";
2133 local $Message = "Correct pmop flags checked when empty pattern";
2135 # Requires reuse of last successful pattern.
2140 ok $match != $_, $Message,
2141 sprintf "'match one' %s on %s iteration" =>
2142 $match ? 'succeeded' : 'failed',
2143 $_ ? 'second' : 'first';
2146 my $result = join "" => $num =~ //g;
2152 local $BugId = '20020630.002';
2153 local $Message = 'UTF-8 regex matches above 32k';
2154 for (['byte', "\x{ff}"], ['utf8', "\x{1ff}"]) {
2155 my ($type, $char) = @$_;
2156 for my $len (32000, 32768, 33000) {
2157 my $s = $char . "f" x $len;
2158 my $r = $s =~ /$char([f]*)/gc;
2159 ok $r, $Message, "<$type x $len>";
2160 ok !$r || pos ($s) == $len + 1, $Message,
2161 "<$type x $len>; pos = @{[pos $s]}";
2168 our $a = bless qr /foo/ => 'Foo';
2169 ok 'goodfood' =~ $a, "Reblessed qr // matches";
2170 iseq $a, '(?-xism:foo)', "Reblessed qr // stringifies";
2172 my $z = my $y = "\317\276"; # Byte representation of $x
2174 ok $x =~ $a, "UTF-8 interpolation in qr //";
2175 ok "a$a" =~ $x, "Stringified qr // preserves UTF-8";
2176 ok "a$x" =~ /^a$a\z/, "Interpolated qr // preserves UTF-8";
2177 ok "a$x" =~ /^a(??{$a})\z/,
2178 "Postponed interpolation of qr // preserves UTF-8";
2180 local $BugId = '17776';
2181 iseq length qr /##/x, 12, "## in qr // doesn't corrupt memory";
2185 ok "$x$x" =~ /^$x(??{$x})\z/,
2186 "Postponed UTF-8 string in UTF-8 re matches UTF-8";
2187 ok "$y$x" =~ /^$y(??{$x})\z/,
2188 "Postponed UTF-8 string in non-UTF-8 re matches UTF-8";
2189 ok "$y$x" !~ /^$y(??{$y})\z/,
2190 "Postponed non-UTF-8 string in non-UTF-8 re doesn't match UTF-8";
2191 ok "$x$x" !~ /^$x(??{$y})\z/,
2192 "Postponed non-UTF-8 string in UTF-8 re doesn't match UTF-8";
2193 ok "$y$y" =~ /^$y(??{$y})\z/,
2194 "Postponed non-UTF-8 string in non-UTF-8 re matches non-UTF8";
2195 ok "$x$y" =~ /^$x(??{$y})\z/,
2196 "Postponed non-UTF-8 string in UTF-8 re matches non-UTF8";
2198 $y = $z; # Reset $y after upgrade.
2199 ok "$x$y" !~ /^$x(??{$x})\z/,
2200 "Postponed UTF-8 string in UTF-8 re doesn't match non-UTF-8";
2201 ok "$y$y" !~ /^$y(??{$x})\z/,
2202 "Postponed UTF-8 string in non-UTF-8 re doesn't match non-UTF-8";
2208 local $PatchId = '18179';
2209 my $s = "\x{100}" x 5;
2210 my $ok = $s =~ /(\x{100}{4})/;
2211 my ($ord, $len) = (ord $1, length $1);
2212 ok $ok && $ord == 0x100 && $len == 4, "No panic: end_shift";
2217 local $BugId = '15763';
2218 our $a = "x\x{100}";
2219 chop $a; # Leaves the UTF-8 flag
2220 $a .= "y"; # 1 byte before 'y'.
2222 ok $a =~ /^\C/, 'match one \C on 1-byte UTF-8';
2223 ok $a =~ /^\C{1}/, 'match \C{1}';
2225 ok $a =~ /^\Cy/, 'match \Cy';
2226 ok $a =~ /^\C{1}y/, 'match \C{1}y';
2228 ok $a !~ /^\C\Cy/, q {don't match two \Cy};
2229 ok $a !~ /^\C{2}y/, q {don't match \C{2}y};
2231 $a = "\x{100}y"; # 2 bytes before "y"
2233 ok $a =~ /^\C/, 'match one \C on 2-byte UTF-8';
2234 ok $a =~ /^\C{1}/, 'match \C{1}';
2235 ok $a =~ /^\C\C/, 'match two \C';
2236 ok $a =~ /^\C{2}/, 'match \C{2}';
2238 ok $a =~ /^\C\C\C/, 'match three \C on 2-byte UTF-8 and a byte';
2239 ok $a =~ /^\C{3}/, 'match \C{3}';
2241 ok $a =~ /^\C\Cy/, 'match two \C';
2242 ok $a =~ /^\C{2}y/, 'match \C{2}';
2244 ok $a !~ /^\C\C\Cy/, q {don't match three \Cy};
2245 ok $a !~ /^\C{2}\Cy/, q {don't match \C{2}\Cy};
2246 ok $a !~ /^\C{3}y/, q {don't match \C{3}y};
2248 $a = "\x{1000}y"; # 3 bytes before "y"
2250 ok $a =~ /^\C/, 'match one \C on three-byte UTF-8';
2251 ok $a =~ /^\C{1}/, 'match \C{1}';
2252 ok $a =~ /^\C\C/, 'match two \C';
2253 ok $a =~ /^\C{2}/, 'match \C{2}';
2254 ok $a =~ /^\C\C\C/, 'match three \C';
2255 ok $a =~ /^\C{3}/, 'match \C{3}';
2257 ok $a =~ /^\C\C\C\C/, 'match four \C on three-byte UTF-8 and a byte';
2258 ok $a =~ /^\C{4}/, 'match \C{4}';
2260 ok $a =~ /^\C\C\Cy/, 'match three \Cy';
2261 ok $a =~ /^\C{3}y/, 'match \C{3}y';
2263 ok $a !~ /^\C\C\C\Cy/, q {don't match four \Cy};
2264 ok $a !~ /^\C{4}y/, q {don't match \C{4}y};
2271 utf8::upgrade($_); chop $_; $\="\n";
2272 ok /[^\s]+/, 'm/[^\s]/ utf8';
2273 ok /[^\d]+/, 'm/[^\d]/ utf8';
2274 ok +($a = $_, $_ =~ s/[^\s]+/./g), 's/[^\s]/ utf8';
2275 ok +($a = $_, $a =~ s/[^\d]+/./g), 's/[^\s]/ utf8';
2280 local $BugId = '15397';
2281 local $Message = 'UTF-8 matching';
2282 ok "\x{100}" =~ /\x{100}/;
2283 ok "\x{100}" =~ /(\x{100})/;
2284 ok "\x{100}" =~ /(\x{100}){1}/;
2285 ok "\x{100}\x{100}" =~ /(\x{100}){2}/;
2286 ok "\x{100}\x{100}" =~ /(\x{100})(\x{100})/;
2291 local $BugId = '7471';
2292 local $Message = 'Neither ()* nor ()*? sets $1 when matched 0 times';
2294 ok /(AB)*?CD/ && !defined $1;
2295 ok /(AB)*CD/ && !defined $1;
2300 local $BugId = '3547';
2301 local $Message = "Caching shouldn't prevent match";
2302 my $pattern = "^(b+?|a){1,2}c";
2303 ok "bac" =~ /$pattern/ && $1 eq 'a';
2304 ok "bbac" =~ /$pattern/ && $1 eq 'a';
2305 ok "bbbac" =~ /$pattern/ && $1 eq 'a';
2306 ok "bbbbac" =~ /$pattern/ && $1 eq 'a';
2312 local $BugId = '18232';
2313 local $Message = '$1 should keep UTF-8 ness';
2314 ok "\x{100}" =~ /(.)/;
2315 iseq $1, "\x{100}", '$1 is UTF-8';
2317 iseq $1, "\x{100}", '$1 is still UTF-8';
2318 isneq $1, "\xC4\x80", '$1 is not non-UTF-8';
2323 local $BugId = '19767';
2324 local $Message = "Optimizer doesn't prematurely reject match";
2327 my $attr = 'Name-1';
2328 my $NormalChar = qr /[\p{IsDigit}\p{IsLower}\p{IsUpper}]/;
2329 my $NormalWord = qr /${NormalChar}+?/;
2330 my $PredNameHyphen = qr /^${NormalWord}(\-${NormalWord})*?$/;
2333 ok $attr =~ $PredNameHyphen; # Original test.
2336 ok "0" =~ /\p{N}+\z/; # Variant.
2341 local $BugId = '20683';
2342 local $Message = "(??{ }) doesn't return stale values";
2344 foreach (1, 2, 3, 4) {
2345 $p ++ if /(??{ $p })/
2352 sub TIESCALAR {bless []}
2356 foreach (1, 2, 3, 4) {
2364 # Subject: Odd regexp behavior
2365 # From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
2366 # Date: Wed, 26 Feb 2003 16:53:12 +0000
2367 # Message-Id: <E18o4nw-0008Ly-00@wisbech.cl.cam.ac.uk>
2368 # To: perl-unicode@perl.org
2370 local $Message = 'Markus Kuhn 2003-02-26';
2372 my $x = "\x{2019}\nk";
2373 ok $x =~ s/(\S)\n(\S)/$1 $2/sg;
2374 ok $x eq "\x{2019} k";
2377 ok $x =~ s/(\S)\n(\S)/$1 $2/sg;
2380 ok "\x{2019}" =~ /\S/;
2385 local $BugId = '21411';
2386 local $Message = "(??{ .. }) in split doesn't corrupt its stack";
2388 ok '-1-3-5-' eq join '', split /((??{$i++}))/, '-1-3-5-';
2389 no warnings 'syntax';
2390 @_ = split /(?{'WOW'})/, 'abc';
2397 # XXX DAPM 13-Apr-06. Recursive split is still broken. It's only luck it
2398 # hasn't been crashing. Disable this test until it is fixed properly.
2399 # XXX also check what it returns rather than just doing ok(1,...)
2400 # split /(?{ split "" })/, "abc";
2401 local $TODO = "Recursive split is still broken";
2402 ok 0, 'cache_re & "(?{": it dumps core in 5.6.1 & 5.8.0';
2407 ok "\x{100}\n" =~ /\x{100}\n$/, "UTF-8 length cache and fbm_compile";
2413 use overload q /""/ => sub {${$_ [0]};};
2414 sub new {my ($c, $v) = @_; bless \$v, $c;}
2417 $_ = Str -> new ("a\x{100}/\x{100}b");
2418 ok join (":", /\b(.)\x{100}/g) eq "a:/", "re_intuit_start and PL_bostr";
2423 local $BugId = '17757';
2424 $_ = "code: 'x' { '...' }\n"; study;
2425 my @x; push @x, $& while m/'[^\']*'/gx;
2427 iseq "@x", "'x':'...'", "Parse::RecDescent triggered infinite loop";
2432 my $re = qq /^([^X]*)X/;
2433 utf8::upgrade ($re);
2434 ok "\x{100}X" =~ /$re/, "S_cl_and ANYOF_UNICODE & ANYOF_INVERTED";
2439 local $BugId = '22354';
2441 ok "a\nb" !~ /^b/, "Propagated modifier; $_[0]";
2442 ok "a\nb" =~ /^b/m, "Propagated modifier; $_[0] - with /m";
2445 $_ = "x"; s/x/func "in subst"/e;
2446 $_ = "x"; s/x/func "in multiline subst"/em;
2449 # Next two give 'panic: malloc'.
2450 # Outcommented, using two TODOs.
2452 local $TODO = 'panic: malloc';
2453 local $Message = 'Postponed regexp and propaged modifier';
2456 skip "panic: malloc", 2;
2457 $_ = "x"; /x(?{func "in regexp"})/;
2458 $_ = "x"; /x(?{func "in multiline regexp"})/m;
2464 local $BugId = '19049';
2467 iseq "abcde", $`, 'Global match sets $`';
2472 ok "123\x{100}" =~ /^.*1.*23\x{100}$/,
2473 'UTF-8 + multiple floating substr';
2478 local $Message = '<20030808193656.5109.1@llama.ni-s.u-net.com>';
2480 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
2481 ok " \x{101}" =~ qr/\x{100}/i;
2483 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
2484 ok " \x{1E01}" =~ qr/\x{1E00}/i;
2486 # DESERET SMALL/CAPITAL LETTER LONG I
2487 ok " \x{10428}" =~ qr/\x{10400}/i;
2489 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
2490 ok " \x{1E01}x" =~ qr/\x{1E00}X/i;
2495 # [perl #23769] Unicode regex broken on simple example
2496 # regrepeat() didn't handle UTF-8 EXACT case right.
2497 local $BugId = '23769';
2498 my $Mess = 'regrepeat() handles UTF-8 EXACT case right';
2499 local $Message = $Mess;
2501 my $s = "\x{a0}\x{a0}\x{a0}\x{100}"; chop $s;
2505 ok $s =~ /\x{a0}\x{a0}/;
2507 $Message = "$Mess (easy variant)";
2508 ok "aaa\x{100}" =~ /(a+)/;
2511 $Message = "$Mess (easy invariant)";
2512 ok "aaa\x{100} " =~ /(a+?)/;
2515 $Message = "$Mess (regrepeat variant)";
2516 ok "\xa0\xa0\xa0\x{100} " =~ /(\xa0+?)/;
2519 $Message = "$Mess (regrepeat invariant)";
2520 ok "\xa0\xa0\xa0\x{100}" =~ /(\xa0+)/;
2521 iseq $1, "\xa0\xa0\xa0";
2523 $Message = "$Mess (hard variant)";
2524 ok "\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+?)/;
2525 iseq $1, "\xa0\xa1";
2527 $Message = "$Mess (hard invariant)";
2528 ok "ababab\x{100} " =~ /((?:ab)+)/;
2531 ok "\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+)/;
2532 iseq $1, "\xa0\xa1\xa0\xa1\xa0\xa1";
2534 ok "ababab\x{100} " =~ /((?:ab)+?)/;
2537 $Message = "Don't match first byte of UTF-8 representation";
2538 ok "\xc4\xc4\xc4" !~ /(\x{100}+)/;
2539 ok "\xc4\xc4\xc4" !~ /(\x{100}+?)/;
2540 ok "\xc4\xc4\xc4" !~ /(\x{100}++)/;
2546 my $head = 'x' x $_;
2547 local $Message = q [Don't misparse \x{...} in regexp ] .
2548 q [near 127 char EXACT limit];
2549 for my $tail ('\x{0061}', '\x{1234}', '\x61') {
2550 eval_ok qq ["$head$tail" =~ /$head$tail/];
2552 local $Message = q [Don't misparse \N{...} in regexp ] .
2553 q [near 127 char EXACT limit];
2554 for my $tail ('\N{SNOWFLAKE}') {
2555 eval_ok qq [use charnames ':full';
2556 "$head$tail" =~ /$head$tail/];
2563 # perl panic: pp_match start/end pointers
2564 local $BugId = '25269';
2565 iseq "a-bc", eval {my ($x, $y) = "bca" =~ /^(?=.*(a)).*(bc)/; "$x-$y"},
2566 'Captures can move backwards in string';
2571 local $BugId = '27940'; # \cA not recognized in character classes
2572 ok "a\cAb" =~ /\cA/, '\cA in pattern';
2573 ok "a\cAb" =~ /[\cA]/, '\cA in character class';
2574 ok "a\cAb" =~ /[\cA-\cB]/, '\cA in character class range';
2575 ok "abc" =~ /[^\cA-\cB]/, '\cA in negated character class range';
2576 ok "a\cBb" =~ /[\cA-\cC]/, '\cB in character class range';
2577 ok "a\cCbc" =~ /[^\cA-\cB]/, '\cC in negated character class range';
2578 ok "a\cAb" =~ /(??{"\cA"})/, '\cA in ??{} pattern';
2579 ok "ab" !~ /a\cIb/x, '\cI in pattern';
2584 # perl #28532: optional zero-width match at end of string is ignored
2585 local $BugId = '28532';
2586 ok "abc" =~ /^abc(\z)?/ && defined($1),
2587 'Optional zero-width match at end of string';
2588 ok "abc" =~ /^abc(\z)??/ && !defined($1),
2589 'Optional zero-width match at end of string';
2596 "words" =~ /(word|word|word)(?{push @got, $1})s$/;
2597 iseq @got, 1, "TRIE optimation";
2600 "words" =~ /(word|word|word)(?{push @got,$1})s$/i;
2601 iseq @got, 1,"TRIEF optimisation";
2603 my @nums = map {int rand 1000} 1 .. 100;
2604 my $re = "(" . (join "|", @nums) . ")";
2608 ok $_ =~ /$re/, "Trie nums";
2611 $_ = join " ", @nums;
2613 push @got, $1 while /$re/g;
2616 $count {$_} ++ for @got;
2619 $ok = 0 if --$count {$_} < 0;
2621 ok $ok, "Trie min count matches";
2627 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
2628 ok "foba \x{101}foo" =~ qr/(foo|\x{100}foo|bar)/i &&
2630 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH MACRON";
2632 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
2633 ok "foba \x{1E01}foo" =~ qr/(foo|\x{1E00}foo|bar)/i &&
2634 $1 eq "\x{1E01}foo",
2635 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW";
2637 # DESERET SMALL/CAPITAL LETTER LONG I
2638 ok "foba \x{10428}foo" =~ qr/(foo|\x{10400}foo|bar)/i &&
2639 $1 eq "\x{10428}foo",
2640 "TRIEF + DESERET SMALL/CAPITAL LETTER LONG I";
2642 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
2643 ok "foba \x{1E01}xfoo" =~ qr/(foo|\x{1E00}Xfoo|bar)/i &&
2644 $1 eq "\x{1E01}xfoo",
2645 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'";
2647 use charnames ':full';
2649 my $s = "\N{LATIN SMALL LETTER SHARP S}";
2650 ok "foba ba$s" =~ qr/(foo|Ba$s|bar)/i && $1 eq "ba$s",
2651 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
2652 ok "foba ba$s" =~ qr/(Ba$s|foo|bar)/i && $1 eq "ba$s",
2653 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
2654 ok "foba ba$s" =~ qr/(foo|bar|Ba$s)/i && $1 eq "ba$s",
2655 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
2657 ok "foba ba$s" =~ qr/(foo|Bass|bar)/i && $1 eq "ba$s",
2658 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
2660 ok "foba ba$s" =~ qr/(foo|BaSS|bar)/i && $1 eq "ba$s",
2661 "TRIEF + LATIN SMALL LETTER SHARP S =~ SS";
2663 ok "foba ba${s}pxySS$s$s" =~ qr/(b(?:a${s}t|a${s}f|a${s}p)[xy]+$s*)/i
2664 && $1 eq "ba${s}pxySS$s$s",
2665 "COMMON PREFIX TRIEF + LATIN SMALL LETTER SHARP S";
2671 print "# Set PERL_SKIP_PSYCHO_TEST to skip this test\n";
2672 my @normal = qw [the are some normal words];
2674 skip "Skipped Psycho", 2 * @normal if $ENV {PERL_SKIP_PSYCHO_TEST};
2678 my @psycho = (@normal, map chr $_, 255 .. 20000);
2679 my $psycho1 = "@psycho";
2680 for (my $i = @psycho; -- $i;) {
2681 my $j = int rand (1 + $i);
2682 @psycho [$i, $j] = @psycho [$j, $i];
2684 my $psycho2 = "@psycho";
2686 foreach my $word (@normal) {
2687 ok $word =~ /($psycho1)/ && $1 eq $word, 'Psycho';
2688 ok $word =~ /($psycho2)/ && $1 eq $word, 'Psycho';
2694 local $BugId = '36207';
2695 my $utf8 = "\xe9\x{100}"; chop $utf8;
2696 my $latin1 = "\xe9";
2698 ok $utf8 =~ /\xe9/i, "utf8/latin";
2699 ok $utf8 =~ /$latin1/i, "utf8/latin runtime";
2700 ok $utf8 =~ /(abc|\xe9)/i, "utf8/latin trie";
2701 ok $utf8 =~ /(abc|$latin1)/i, "utf8/latin trie runtime";
2703 ok "\xe9" =~ /$utf8/i, "latin/utf8";
2704 ok "\xe9" =~ /(abc|$utf8)/i, "latin/utf8 trie";
2705 ok $latin1 =~ /$utf8/i, "latin/utf8 runtime";
2706 ok $latin1 =~ /(abc|$utf8)/i, "latin/utf8 trie runtime";
2711 local $BugId = '37038';
2717 "Assigning to original string does not corrupt match vars";
2726 my $aeek = bless {} => 'wooosh';
2727 eval_ok sub {$aeek -> gloople () =~ /(.)/g},
2728 "//g match against return value of sub";
2731 eval_ok sub {gloople () =~ /(.)/g},
2732 "26410 didn't affect sub calls for some reason";
2737 local $TODO = "See changes 26925-26928, which reverted change 26410";
2741 sub variable : lvalue {$var}
2743 my $o = bless [] => 'lv';
2747 $f .= $1 if $o -> variable =~ /(.)/g;
2752 iseq $f, "ab", "pos() retained between calls";
2756 ok 0, "Code failed: $@";
2760 sub variable : lvalue {$var}
2764 $g .= $1 if variable =~ /(.)/g;
2769 iseq $g, "ab", "pos() retained between calls";
2773 ok 0, "Code failed: $@";
2780 local $BugId = '37836';
2781 skip "In EBCDIC" if $IS_EBCDIC;
2783 $_ = pack 'U0C2', 0xa2, 0xf8; # Ill-formed UTF-8
2785 eval_ok sub {!($ret = s/[\0]+//g)},
2786 "Ill-formed UTF-8 doesn't match NUL in class";
2791 # chr(65535) should be allowed in regexes
2792 local $BugId = '38293';
2793 no warnings 'utf8'; # To allow non-characters
2798 ok $c eq "", "U+FFFF, parsed as atom";
2803 ok $c eq "", "U+FFFF backslashed, parsed as atom";
2807 ok $c eq "", "U+FFFF, parsed in class";
2812 ok $c eq "", "U+FFFF backslashed, parsed in class";
2815 $s =~ s/\x{ffff}//i;
2816 ok $s eq "AB", "U+FFFF, EXACTF";
2820 ok $s eq "\x{ffff}", "U+FFFF, BOUND";
2824 ok $s eq "\x{ffff}", "U+FFFF, NBOUND";
2829 local $BugId = '39583';
2831 # The printing characters
2832 my @chars = ("A" .. "Z");
2834 my $size = 32771 - 4;
2837 # Create some random junk. Inefficient, but it works.
2838 for (my $i = 0; $i < $size; $ i++) {
2839 $str .= $chars [rand @chars];
2842 $str .= ($delim x 4);
2845 ok $str =~ s/^(.*?)${delim}{4}//s, "Pattern matches";
2846 iseq $str, "", "Empty string";
2847 ok defined $1 && length ($1) == $size, '$1 is correct size';
2852 local $BugId = '27940';
2853 ok "\0-A" =~ /\c@-A/, '@- should not be interpolated in a pattern';
2854 ok "\0\0A" =~ /\c@+A/, '@+ should not be interpolated in a pattern';
2855 ok "X\@-A" =~ /X@-A/, '@- should not be interpolated in a pattern';
2856 ok "X\@\@A" =~ /X@+A/, '@+ should not be interpolated in a pattern';
2858 ok "X\0A" =~ /X\c@?A/, '\c@?';
2859 ok "X\0A" =~ /X\c@*A/, '\c@*';
2860 ok "X\0A" =~ /X\c@(A)/, '\c@(';
2861 ok "X\0A" =~ /X(\c@)A/, '\c@)';
2862 ok "X\0A" =~ /X\c@|ZA/, '\c@|';
2864 ok "X\@A" =~ /X@?A/, '@?';
2865 ok "X\@A" =~ /X@*A/, '@*';
2866 ok "X\@A" =~ /X@(A)/, '@(';
2867 ok "X\@A" =~ /X(@)A/, '@)';
2868 ok "X\@A" =~ /X@|ZA/, '@|';
2870 local $" = ','; # non-whitespace and non-RE-specific
2871 ok 'abc' =~ /(.)(.)(.)/, 'The last successful match is bogus';
2872 ok "A@+B" =~ /A@{+}B/, 'Interpolation of @+ in /@{+}/';
2873 ok "A@-B" =~ /A@{-}B/, 'Interpolation of @- in /@{-}/';
2874 ok "A@+B" =~ /A@{+}B/x, 'Interpolation of @+ in /@{+}/x';
2875 ok "A@-B" =~ /A@{-}B/x, 'Interpolation of @- in /@{-}/x';
2881 unshift @INC, 'lib';
2885 ok 'fooB' =~ /\N{foo}[\N{B}\N{b}]/, "Passthrough charname";
2888 # Why doesn't must_warn work here?
2891 local $SIG {__WARN__} = sub {$w .= "@_"};
2892 eval 'q(xxWxx) =~ /[\N{WARN}]/';
2893 ok $w && $w =~ /^Ignoring excess chars from/,
2894 "Ignoring excess chars warning";
2897 eval q [ok "\0" !~ /[\N{EMPTY-STR}XY]/,
2898 "Zerolength charname in charclass doesn't match \\0"];
2899 ok $w && $w =~ /^Ignoring zero length/,
2900 'Ignoring zero length \N{%} in character class warning';
2902 ok 'AB' =~ /(\N{EVIL})/ && $1 eq 'A', 'Charname caching $1';
2903 ok 'ABC' =~ /(\N{EVIL})/, 'Charname caching $1';
2904 ok 'xy' =~ /x\N{EMPTY-STR}y/,
2905 'Empty string charname produces NOTHING node';
2906 ok '' =~ /\N{EMPTY-STR}/,
2907 'Empty string charname produces NOTHING node';
2913 use charnames ':full';
2915 ok 'aabc' !~ /a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against aabc';
2916 ok 'a+bc' =~ /a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against a+bc';
2918 ok ' A B' =~ /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
2919 'Intermixed named and unicode escapes';
2920 ok "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}" =~
2921 /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
2922 'Intermixed named and unicode escapes';
2923 ok "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}" =~
2924 /[\N{SPACE}\N{U+0041}][\N{SPACE}\N{U+0042}]/,
2925 'Intermixed named and unicode escapes';
2932 { (?> [^{}]+ | (??{ $brackets }) )* }
2935 ok "{b{c}d" !~ m/^((??{ $brackets }))/, "Bracket mismatch";
2947 <<stuff1>and<stuff2>><<<<right>>>>
2950 local $_ = '<<<stuff1>and<stuff2>><<<<right>>>>>';
2951 ok /^(<((?:(?>[^<>]+)|(?1))*)>(?{push @stack, $2 }))$/,
2952 "Recursion matches";
2953 iseq @stack, @expect, "Right amount of matches"
2954 or skip "Won't test individual results as count isn't equal",
2957 foreach my $expect (@expect) {
2958 iseq $stack [$idx], $expect,
2959 "Expecting '$expect' at stack pos #$idx";
2967 my $s = '123453456';
2968 $s =~ s/(?<digits>\d+)\k<digits>/$+{digits}/;
2969 ok $s eq '123456', 'Named capture (angle brackets) s///';
2971 $s =~ s/(?'digits'\d+)\k'digits'/$+{digits}/;
2972 ok $s eq '123456', 'Named capture (single quotes) s///';
2978 pack('U', 0x00F1), # n-tilde
2979 '_'.pack('U', 0x00F1), # _ + n-tilde
2980 'c'.pack('U', 0x0327), # c + cedilla
2981 pack('U*', 0x00F1, 0x0327), # n-tilde + cedilla
2982 'a'.pack('U', 0x00B2), # a + superscript two
2983 pack('U', 0x0391), # ALPHA
2984 pack('U', 0x0391).'2', # ALPHA + 2
2985 pack('U', 0x0391).'_', # ALPHA + _
2988 for my $uni (@ary) {
2989 my ($r1, $c1, $r2, $c2) = eval qq {
2991 scalar ("..foo foo.." =~ /(?'${uni}'foo) \\k'${uni}'/),
2993 scalar ("..bar bar.." =~ /(?<${uni}>bar) \\k<${uni}>/),
2996 ok $r1, "Named capture UTF (?'')";
2997 ok defined $c1 && $c1 eq 'foo', "Named capture UTF \%+";
2998 ok $r2, "Named capture UTF (?<>)";
2999 ok defined $c2 && $c2 eq 'bar', "Named capture UTF \%+";
3005 my $s = 'foo bar baz';
3006 my (@k, @v, @fetch, $res);
3008 my @names = qw ($+{A} $+{B} $+{C});
3009 if ($s =~ /(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz)/) {
3010 while (my ($k, $v) = each (%+)) {
3013 @k = sort keys (%+);
3014 @v = sort values (%+);
3024 iseq $fetch [$_] [0], $fetch [$_] [1], $names [$_];
3029 iseq $res, 1, "'$s' =~ /(?<A>foo)\\s+(?<B>bar)?\\s+(?<C>baz)/";
3030 iseq $count, 3, "Got 3 keys in %+ via each";
3031 iseq 0 + @k, 3, 'Got 3 keys in %+ via keys';
3032 iseq "@k", "A B C", "Got expected keys";
3033 iseq "@v", "bar baz foo", "Got expected values";
3035 no warnings "uninitialized";
3036 print for $+ {this_key_doesnt_exist};
3038 ok !$@, 'lvalue $+ {...} should not throw an exception';
3044 # Almost the same as the block above, except that the capture is nested.
3046 local $BugId = '50496';
3047 my $s = 'foo bar baz';
3048 my (@k, @v, @fetch, $res);
3050 my @names = qw ($+{A} $+{B} $+{C} $+{D});
3051 if ($s =~ /(?<D>(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz))/) {
3052 while (my ($k,$v) = each(%+)) {
3055 @k = sort keys (%+);
3056 @v = sort values (%+);
3067 iseq $fetch [$_] [0], $fetch [$_] [1], $names [$_];
3072 iseq $res, 1, "'$s' =~ /(?<D>(?<A>foo)\\s+(?<B>bar)?\\s+(?<C>baz))/";
3073 iseq $count, 4, "Got 4 keys in %+ via each";
3074 iseq @k, 4, 'Got 4 keys in %+ via keys';
3075 iseq "@k", "A B C D", "Got expected keys";
3076 iseq "@v", "bar baz foo foo bar baz", "Got expected values";
3078 no warnings "uninitialized";
3079 print for $+ {this_key_doesnt_exist};
3081 ok !$@,'lvalue $+ {...} should not throw an exception';
3086 my $s = 'foo bar baz';
3088 if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) {
3089 foreach my $name (sort keys(%-)) {
3090 my $ary = $- {$name};
3091 foreach my $idx (0 .. $#$ary) {
3092 push @res, "$name:$idx:$ary->[$idx]";
3096 my @expect = qw (A:0:1 A:1:3 B:0:2 B:1:4);
3097 iseq "@res", "@expect", "Check %-";
3099 no warnings "uninitialized";
3100 print for $- {this_key_doesnt_exist};
3102 ok !$@,'lvalue $- {...} should not throw an exception';
3108 # stress test CURLYX/WHILEM.
3110 # This test includes varying levels of nesting, and according to
3111 # profiling done against build 28905, exercises every code line in the
3112 # CURLYX and WHILEM blocks, except those related to LONGJMP, the
3113 # super-linear cache and warnings. It executes about 0.5M regexes
3115 skip "No psycho tests" if $ENV {PERL_SKIP_PSYCHO_TEST};
3116 print "# Set PERL_SKIP_PSYCHO_TEST to skip this test\n";
3151 my $msg = "CURLYX stress test";
3153 for my $a ("x","a","aa") {
3154 for my $b ("x","bbb","bbbb") {
3156 for my $c ("x","c","cc") {
3158 for my $d ("x","d","dd") {
3160 for my $e ("x","e","ee") {
3162 for my $f ("x","f","ff") {
3164 for my $g ("x","g","gg") {
3166 for my $h ("x","h","hh") {
3168 for my $i ("x","i","ii") {
3170 for my $j ("x","j","jj") {
3172 for my $k ("x","k","kk") {
3174 for my $l ("x","l","ll") {
3178 $msg .= ": unexpected match for [$ls]";
3182 my $cap = "$1$2$3$4$5$6$7$8$9$10$11$12";
3183 unless ($ls eq $cap) {
3184 $msg .= ": capture: [$ls], got [$cap]";
3190 unless ($ls =~ /x/) {
3191 $msg = ": failed for [$ls]";
3214 ok "xaaay" !~ /xa{3\,4}y/, '\, in a pattern';
3215 ok "xa{3,4}y" =~ /xa{3\,4}y/, '\, in a pattern';
3218 ok "x\c_y" !~ /x\c\_y/, '\_ in a pattern';
3219 ok "x\c\_y" =~ /x\c\_y/, '\_ in a pattern';
3221 # \c\ followed by other characters
3222 for my $c ("z", "\0", "!", chr(254), chr(256)) {
3223 my $targ = "a\034$c";
3224 my $reg = "a\\c\\$c";
3225 ok eval ("qq/$targ/ =~ /$reg/"), "\\c\\ in pattern";
3231 local $BugId = '36046';
3236 while ($str =~ /b/g) {$mval = $#-; $pval = $#+; $count ++}
3237 iseq $mval, 0, '@- should be empty';
3238 iseq $pval, 0, '@+ should be empty';
3239 iseq $count, 1, 'Should have matched once only';
3243 { # Test the (*PRUNE) pattern
3245 'aaab' =~ /a+b?(?{$count++})(*FAIL)/;
3246 iseq $count, 9, "Expect 9 for no (*PRUNE)";
3248 'aaab' =~ /a+b?(*PRUNE)(?{$count++})(*FAIL)/;
3249 iseq $count, 3, "Expect 3 with (*PRUNE)";
3252 1 while /.(*PRUNE)(?{$count++})(*FAIL)/g;
3253 iseq $count, 4, "/.(*PRUNE)/";
3255 'aaab' =~ /a+b?(??{'(*PRUNE)'})(?{$count++})(*FAIL)/;
3256 iseq $count, 3, "Expect 3 with (*PRUNE)";
3259 1 while /.(??{'(*PRUNE)'})(?{$count++})(*FAIL)/g;
3260 iseq $count, 4, "/.(*PRUNE)/";
3264 { # Test the (*SKIP) pattern
3266 'aaab' =~ /a+b?(*SKIP)(?{$count++})(*FAIL)/;
3267 iseq $count, 1, "Expect 1 with (*SKIP)";
3270 1 while /.(*SKIP)(?{$count++})(*FAIL)/g;
3271 iseq $count, 4, "/.(*SKIP)/";
3275 1 while /(a+b?)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
3276 iseq $count, 2, "Expect 2 with (*SKIP)";
3277 iseq "@res", "aaab aaab", "Adjacent (*SKIP) works as expected";
3281 { # Test the (*SKIP) pattern
3283 'aaab' =~ /a+b?(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/;
3284 iseq $count, 1, "Expect 1 with (*SKIP)";
3287 1 while /.(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/g;
3288 iseq $count, 4, "/.(*SKIP)/";
3292 1 while /(a+b?)(*MARK:foo)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
3293 iseq $count, 2, "Expect 2 with (*SKIP)";
3294 iseq "@res", "aaab aaab", "Adjacent (*SKIP) works as expected";
3298 { # Test the (*SKIP) pattern
3300 'aaab' =~ /a*(*MARK:a)b?(*MARK:b)(*SKIP:a)(?{$count++})(*FAIL)/;
3301 iseq $count, 3, "Expect 3 with *MARK:a)b?(*MARK:b)(*SKIP:a)";
3302 local $_ = 'aaabaaab';
3306 /(a*(*MARK:a)b?)(*MARK:x)(*SKIP:a)(?{$count++; push @res,$1})(*FAIL)/g;
3307 iseq $count, 5, "Expect 5 with (*MARK:a)b?)(*MARK:x)(*SKIP:a)";
3308 iseq "@res", "aaab b aaab b ",
3309 "Adjacent (*MARK:a)b?)(*MARK:x)(*SKIP:a) works as expected";
3313 { # Test the (*COMMIT) pattern
3315 'aaabaaab' =~ /a+b?(*COMMIT)(?{$count++})(*FAIL)/;
3316 iseq $count, 1, "Expect 1 with (*COMMIT)";
3319 1 while /.(*COMMIT)(?{$count++})(*FAIL)/g;
3320 iseq $count, 1, "/.(*COMMIT)/";
3324 1 while /(a+b?)(*COMMIT)(?{$count++; push @res,$1})(*FAIL)/g;
3325 iseq $count, 1, "Expect 1 with (*COMMIT)";
3326 iseq "@res", "aaab", "Adjacent (*COMMIT) works as expected";
3331 # Test named commits and the $REGERROR var
3333 for my $name ('', ':foo') {
3334 for my $pat ("(*PRUNE$name)",
3335 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)",
3337 for my $suffix ('(*FAIL)', '') {
3338 'aaaab' =~ /a+b$pat$suffix/;
3340 ($suffix ? ($name ? 'foo' : "1") : ""),
3341 "Test $pat and \$REGERROR $suffix";
3349 # Test named commits and the $REGERROR var
3352 for my $name ('', ':foo') {
3353 for my $pat ("(*PRUNE$name)",
3354 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)",
3356 for my $suffix ('(*FAIL)','') {
3357 'aaaab' =~ /a+b$pat$suffix/;
3359 ($suffix ? ($name ? 'foo' : "1") : ""),
3360 "Test $pat and \$REGERROR $suffix";
3368 # Test named commits and the $REGERROR var
3369 local $Message = '$REGERROR';
3371 for my $word (qw (bar baz bop)) {
3374 /a+(?:bar(*COMMIT:bar)|baz(*COMMIT:baz)|bop(*COMMIT:bop))(*FAIL)/;
3375 iseq $REGERROR, $word;
3381 local $BugId = '40684';
3382 local $Message = '/m in precompiled regexp';
3384 my $rex = qr'^abc$'m;
3391 #Mindnumbingly simple test of (*THEN)
3393 ok /A (*THEN) X | B (*THEN) C/x, "Simple (*THEN) test";
3399 local $Message = "Relative Recursion";
3400 my $parens = qr/(\((?:[^()]++|(?-1))*+\))/;
3401 local $_ = 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))';
3402 my ($all, $one, $two) = ('', '', '');
3403 ok /foo $parens \s* \+ \s* bar $parens/x;
3404 iseq $1, '((2*3)+4-3)';
3405 iseq $2, '(2*(3+4)-1*(2-3))';
3406 iseq $&, 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))';
3412 local $_ = join 'bar', $spaces, $spaces;
3414 s/(?>\s+bar)(?{$count++})//g;
3415 iseq $_, $spaces, "SUSPEND final string";
3416 iseq $count, 1, "Optimiser should have prevented more than one match";
3420 local $BugId = '36909';
3421 local $Message = '(?: ... )? should not lose $^R';
3425 ok 'x foofoo y' =~ m {
3426 (foo) # $^R correctly set
3427 (?{ "last regexp code result" })
3429 iseq $^R, 'last regexp code result';
3431 iseq $^R, 'Nothing';
3436 ok 'x foofoo y' =~ m {
3437 (?:foo|bar)+ # $^R correctly set
3438 (?{ "last regexp code result" })
3440 iseq $^R, 'last regexp code result';
3442 iseq $^R, 'Nothing';
3446 ok 'x foofoo y' =~ m {
3447 (foo|bar)\1+ # $^R undefined
3448 (?{ "last regexp code result" })
3450 iseq $^R, 'last regexp code result';
3452 iseq $^R, 'Nothing';
3456 ok 'x foofoo y' =~ m {
3457 (foo|bar)\1 # This time without the +
3458 (?{"last regexp code result"})
3460 iseq $^R, 'last regexp code result';
3462 iseq $^R, 'Nothing';
3467 local $BugId = '22395';
3468 local $Message = 'Match is linear, not quadratic';
3470 for my $l (10, 100, 1000) {
3472 ('a' x $l) =~ /(.*)(?{$count++})[bc]/;
3473 local $TODO = "Should be L+1 not L*(L+3)/2 (L=$l)";
3474 iseq $count, $l + 1;
3480 local $BugId = '22614';
3481 local $Message = '@-/@+ should not have undefined values';
3484 /(.){1,}(?{push @len,0+@-})(.){1,}(?{})^/;
3485 iseq "@len", "2 2 2";
3490 local $BugId = '18209';
3491 local $Message = '$& set on s///';
3492 my $text = ' word1 word2 word3 word4 word5 word6 ';
3494 my @words = ('word1', 'word3', 'word5');
3496 foreach my $word (@words) {
3497 $text =~ s/$word\s//gi; # Leave a space to seperate words
3498 # in the resultant str.
3499 # The following block is not working.
3506 iseq $text, ' word2 word4 word6 ';
3512 local $BugId = '6893';
3513 local $_ = qq (A\nB\nC\n);
3515 while (m#(\G|\n)([^\n]*)\n#gsx) {
3519 iseq "@res", "A B C", "/g pattern shouldn't infinite loop";
3524 # From Message-ID: <877ixs6oa6.fsf@k75.linux.bogus>
3525 my $dow_name = "nada";
3526 my $parser = "(\$dow_name) = \$time_string =~ /(D\x{e9}\\ " .
3527 "C\x{e9}adaoin|D\x{e9}\\ Sathairn|\\w+|\x{100})/";
3528 my $time_string = "D\x{e9} C\x{e9}adaoin";
3530 ok !$@, "Test Eval worked";
3531 iseq $dow_name, $time_string, "UTF-8 trie common prefix extraction";
3537 ($v = 'bar') =~ /(\w+)/g;
3539 iseq "$1", 'bar', '$1 is safe after /g - may fail due ' .
3540 'to specialized config in pp_hot.c'
3545 local $Message = "http://nntp.perl.org/group/perl.perl5.porters/118663";
3546 my $qr_barR1 = qr/(bar)\g-1/;
3547 ok "foobarbarxyz" =~ $qr_barR1;
3548 ok "foobarbarxyz" =~ qr/foo${qr_barR1}xyz/;
3549 ok "foobarbarxyz" =~ qr/(foo)${qr_barR1}xyz/;
3550 ok "foobarbarxyz" =~ qr/(foo)(bar)\g{-1}xyz/;
3551 ok "foobarbarxyz" =~ qr/(foo${qr_barR1})xyz/;
3552 ok "foobarbarxyz" =~ qr/(foo(bar)\g{-1})xyz/;
3557 local $BugId = '41010';
3558 local $Message = 'No optimizer bug';
3559 my @tails = ('', '(?(1))', '(|)', '()?');
3560 my @quants = ('*','+');
3564 for my $pat (@$pats) {
3565 for my $quant (@quants) {
3566 for my $tail (@tails) {
3567 my $re = "($pat$quant\$)$tail";
3568 ok /$re/ && $1 eq $_, "'$_' =~ /$re/";
3569 ok /$re/m && $1 eq $_, "'$_' =~ /$re/m";
3578 '(1|[23]|4|[56]|[78]|[90])',
3579 '(?:1|[23]|4|[56]|[78]|[90])',
3580 '(1|2|3|4|5|6|7|8|9|0)',
3581 '(?:1|2|3|4|5|6|7|8|9|0)');
3582 my @spats = ('[ ]', ' ', '( |\t)', '(?: |\t)', '[ \t]', '\s');
3584 my @dstrs = ('12345');
3585 $doit -> (\@spats, @sstrs);
3586 $doit -> (\@dpats, @dstrs);
3591 local $Message = '$REGMARK';
3593 our ($REGMARK, $REGERROR);
3594 ok 'foofoo' =~ /foo (*MARK:foo) (?{push @r,$REGMARK}) /x;
3596 iseq $REGMARK, "foo";
3597 ok 'foofoo' !~ /foo (*MARK:foo) (*FAIL) /x;
3599 iseq $REGERROR, 'foo';
3604 local $Message = '\K test';
3606 $x = "abc.def.ghi.jkl";
3608 iseq $x, "abc.def.ghi";
3610 $x = "one two three four";
3611 $x =~ s/o+ \Kthree//g;
3612 iseq $x, "one two four";
3616 iseq $x, "aabbccddee";
3622 return '4' if $_[0] eq '09028623';
3624 # Nested EVAL using PL_curpm (via $1 or friends)
3626 our $grabit = qr/ ([0-6][0-9]{7}) (??{ kt $1 }) [890] /x;
3627 $re = qr/^ ( (??{ $grabit }) ) $ /x;
3628 my @res = '0902862349' =~ $re;
3629 iseq join ("-", @res), "0902862349",
3630 'PL_curpm is set properly on nested eval';
3632 our $qr = qr/ (o) (??{ $1 }) /x;
3633 ok 'boob'=~/( b (??{ $qr }) b )/x && 1, "PL_curpm, nested eval";
3638 use charnames ":full";
3639 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "I =~ Alphabetic";
3640 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Uppercase}/, "I =~ Uppercase";
3641 ok "\N{ROMAN NUMERAL ONE}" !~ /\p{Lowercase}/, "I !~ Lowercase";
3642 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "I =~ ID_Start";
3643 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "I =~ ID_Continue";
3644 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "i =~ Alphabetic";
3645 ok "\N{SMALL ROMAN NUMERAL ONE}" !~ /\p{Uppercase}/, "i !~ Uppercase";
3646 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Lowercase}/, "i =~ Lowercase";
3647 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "i =~ ID_Start";
3648 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "i =~ ID_Continue"
3653 # requirement of Unicode Technical Standard #18, 1.7 Code Points
3654 # cf. http://www.unicode.org/reports/tr18/#Supplementary_Characters
3655 for my $u (0x7FF, 0x800, 0xFFFF, 0x10000) {
3656 no warnings 'utf8'; # oops
3658 my $x = sprintf '%04X', $u;
3659 ok "A${c}B" =~ /A[\0-\x{10000}]B/, "Unicode range - $x";
3667 if ('1' =~ /(?|(?<digit>1)|(?<digit>2))/) {
3668 $res = "@{$- {digit}}";
3671 "Check that (?|...) doesnt cause dupe entries in the names array";
3674 if ('11' =~ /(?|(?<digit>1)|(?<digit>2))(?&digit)/) {
3675 $res = "@{$- {digit}}";
3677 iseq $res, "1", "Check that (?&..) to a buffer inside " .
3678 "a (?|...) goes to the leftmost";
3684 local $Message = "ASCII pattern that really is UTF-8";
3686 local $SIG {__WARN__} = sub {push @w, "@_"};
3687 my $c = qq (\x{DF});
3688 ok $c =~ /${c}|\x{100}/;
3694 local $Message = "Corruption of match results of qr// across scopes";
3695 my $qr = qr/(fo+)(ba+r)/;
3697 iseq "$1$2", "foobar";
3699 'foooooobaaaaar' =~ /$qr/;
3700 iseq "$1$2", 'foooooobaaaaar';
3702 iseq "$1$2", "foobar";
3707 local $Message = "HORIZWS";
3708 local $_ = "\t \r\n \n \t".chr(11)."\n";
3711 iseq $_, "hhHHhHhhHH";
3712 $_ = "\t \r\n \n \t" . chr (11) . "\n";
3716 iseq $_, "hhHHhHhhHH";
3721 local $Message = "Various whitespace special patterns";
3722 my @h = map {chr $_} 0x09, 0x20, 0xa0, 0x1680, 0x180e, 0x2000,
3723 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006,
3724 0x2007, 0x2008, 0x2009, 0x200a, 0x202f, 0x205f,
3726 my @v = map {chr $_} 0x0a, 0x0b, 0x0c, 0x0d, 0x85, 0x2028,
3728 my @lb = ("\x0D\x0A", map {chr $_} 0x0A .. 0x0D, 0x85, 0x2028, 0x2029);
3729 foreach my $t ([\@h, qr/\h/, qr/\h+/],
3730 [\@v, qr/\v/, qr/\v+/],
3731 [\@lb, qr/\R/, qr/\R+/],) {
3732 my $ary = shift @$t;
3733 foreach my $pat (@$t) {
3734 foreach my $str (@$ary) {
3735 ok $str =~ /($pat)/, $pat;
3736 iseq $1, $str, $pat;
3737 utf8::upgrade ($str);
3738 ok $str =~ /($pat)/, "Upgraded string - $pat";
3739 iseq $1, $str, "Upgraded string - $pat";
3747 local $Message = "Check that \\xDF match properly in its various forms";
3748 # Test that \xDF matches properly. this is pretty hacky stuff,
3749 # but its actually needed. The malarky with '-' is to prevent
3750 # compilation caching from playing any role in the test.
3751 my @df = (chr (0xDF), '-', chr (0xDF));
3752 utf8::upgrade ($df [2]);
3753 my @strs = ('ss', 'sS', 'Ss', 'SS', chr (0xDF));
3754 my @ss = map {("$_", "$_")} @strs;
3755 utf8::upgrade ($ss [$_ * 2 + 1]) for 0 .. $#strs;
3757 for my $ssi (0 .. $#ss) {
3758 for my $dfi (0 .. $#df) {
3759 my $pat = $df [$dfi];
3760 my $str = $ss [$ssi];
3761 my $utf_df = ($dfi > 1) ? 'utf8' : '';
3762 my $utf_ss = ($ssi % 2) ? 'utf8' : '';
3763 (my $sstr = $str) =~ s/\xDF/\\xDF/;
3765 if ($utf_df || $utf_ss || length ($ss [$ssi]) == 1) {
3766 my $ret = $str =~ /$pat/i;
3767 next if $pat eq '-';
3768 ok $ret, "\"$sstr\" =~ /\\xDF/i " .
3769 "(str is @{[$utf_ss||'latin']}, pat is " .
3770 "@{[$utf_df||'latin']})";
3773 my $ret = $str !~ /$pat/i;
3774 next if $pat eq '-';
3775 ok $ret, "\"$sstr\" !~ /\\xDF/i " .
3776 "(str is @{[$utf_ss||'latin']}, pat is " .
3777 "@{[$utf_df||'latin']})";
3785 local $Message = "BBC(Bleadperl Breaks CPAN) Today: String::Multibyte";
3786 my $re = qr/(?:[\x00-\xFF]{4})/;
3787 my $hyp = "\0\0\0-";
3788 my $esc = "\0\0\0\\";
3790 my $str = "$esc$hyp$hyp$esc$esc";
3791 my @a = ($str =~ /\G(?:\Q$esc$esc\E|\Q$esc$hyp\E|$re)/g);
3795 iseq "@a","$esc$hyp=$hyp=$esc$esc";
3800 # Test for keys in %+ and %-
3801 local $Message = 'Test keys in %+ and %-';
3802 no warnings 'uninitialized';
3804 /(?<foo>a)|(?<foo>b)/;
3805 iseq ((join ",", sort keys %+), "foo");
3806 iseq ((join ",", sort keys %-), "foo");
3807 iseq ((join ",", sort values %+), "a");
3808 iseq ((join ",", sort map "@$_", values %-), "a ");
3809 /(?<bar>a)(?<bar>b)(?<quux>.)/;
3810 iseq ((join ",", sort keys %+), "bar,quux");
3811 iseq ((join ",", sort keys %-), "bar,quux");
3812 iseq ((join ",", sort values %+), "a,c"); # leftmost
3813 iseq ((join ",", sort map "@$_", values %-), "a b,c");
3814 /(?<un>a)(?<deux>c)?/; # second buffer won't capture
3815 iseq ((join ",", sort keys %+), "un");
3816 iseq ((join ",", sort keys %-), "deux,un");
3817 iseq ((join ",", sort values %+), "a");
3818 iseq ((join ",", sort map "@$_", values %-), ",a");
3823 # length() on captures, the numbered ones end up in Perl_magic_len
3824 my $_ = "aoeu \xe6var ook";
3825 /^ \w+ \s (?<eek>\S+)/x;
3827 iseq length ($`), 0, q[length $`];
3828 iseq length ($'), 4, q[length $'];
3829 iseq length ($&), 9, q[length $&];
3830 iseq length ($1), 4, q[length $1];
3831 iseq length ($+{eek}), 4, q[length $+{eek} == length $1];
3838 $ok = exists ($-{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/;
3839 iseq $ok, 1, '$-{x} exists after "bar"=~/(?<x>foo)|bar/';
3840 iseq scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/';
3841 iseq scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/';
3844 $ok = exists ($+{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/;
3845 iseq $ok, 0, '$+{x} not exists after "bar"=~/(?<x>foo)|bar/';
3846 iseq scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/';
3847 iseq scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/';
3850 $ok = exists ($-{x}) ? 1 : 0 if 'foo' =~ /(?<x>foo)|bar/;
3851 iseq $ok, 1, '$-{x} exists after "foo"=~/(?<x>foo)|bar/';
3852 iseq scalar (%+), 1, 'scalar %+ == 1 after "foo"=~/(?<x>foo)|bar/';
3853 iseq scalar (%-), 1, 'scalar %- == 1 after "foo"=~/(?<x>foo)|bar/';
3856 $ok = exists ($+{x}) ? 1 : 0 if 'foo'=~/(?<x>foo)|bar/;
3857 iseq $ok, 1, '$+{x} exists after "foo"=~/(?<x>foo)|bar/';
3863 ($_ = 'abc') =~ /(abc)/g;
3865 iseq "$1", 'abc', "/g leads to unsafe match vars: $1";
3870 local $Message = 'Message-ID: <20070818091501.7eff4831@r2d2>';
3874 $str .= "@x"; # this should ALWAYS be the empty string
3878 iseq length ($str), 0, "Trie scope error, string should be empty";
3880 my @foo = ('a') x 5;
3884 s/a|/push @bar, 1/e;
3886 iseq length ($str), 0, "Trie scope error, string should be empty";
3891 local $BugId = '45605';
3892 # [perl #45605] Regexp failure with utf8-flagged and byte-flagged string
3894 my $utf_8 = "\xd6schel";
3895 utf8::upgrade ($utf_8);
3896 $utf_8 =~ m {(\xd6|Ö)schel};
3897 iseq $1, "\xd6", "Upgrade error";
3901 # more TRIE/AHOCORASICK problems with mixed utf8 / latin-1 and case folding
3902 for my $chr (160 .. 255) {
3903 my $chr_byte = chr($chr);
3904 my $chr_utf8 = chr($chr); utf8::upgrade($chr_utf8);
3905 my $rx = qr{$chr_byte|X}i;
3906 ok($chr_utf8 =~ $rx, "utf8/latin, codepoint $chr");
3911 # Regardless of utf8ness any character matches itself when
3912 # doing a case insensitive match. See also [perl #36207]
3913 local $BugId = '36207';
3914 for my $o (0 .. 255) {
3915 my @ch = (chr ($o), chr ($o));
3916 utf8::upgrade ($ch [1]);
3917 for my $u_str (0, 1) {
3918 for my $u_pat (0, 1) {
3919 ok $ch [$u_str] =~ /\Q$ch[$u_pat]\E/i,
3920 "\$c =~ /\$c/i : chr ($o) : u_str = $u_str u_pat = $u_pat";
3921 ok $ch [$u_str] =~ /\Q$ch[$u_pat]\E|xyz/i,
3922 "\$c=~/\$c|xyz/i : chr($o) : u_str = $u_str u_pat = $u_pat";
3930 our $a = 3; "" =~ /(??{ $a })/;
3932 iseq $b, $a, "Copy of scalar used for postponed subexpression";
3937 local $BugId = '49190';
3938 local $Message = '$REGMARK in replacement';
3941 ok s/(*:B)A/$REGMARK/;
3944 ok s/(*:X)A+|(*:Y)B+|(*:Z)C+/$REGMARK/g;
3965 my $match = '<bla><blubb></blubb></bla>' =~ m/^$nested_tags$/;
3966 ok $match, 'nested construct matches';
3967 iseq "@ctl_n", "bla blubb", '$^N inside of (?{}) works as expected';
3968 iseq "@plus", "bla blubb", '$+ inside of (?{}) works as expected';
3973 local $BugId = '52658';
3974 local $Message = 'Substitution evaluation in list context';
3975 my $reg = '../xxx/';
3976 my @te = ($reg =~ m{^(/?(?:\.\./)*)},
3977 $reg =~ s/(x)/'b'/eg > 1 ? '##' : '++');
3978 iseq $reg, '../bbb/';
3979 iseq $te [0], '../';
3982 # This currently has to come before any "use encoding" in this file.
3985 local $BugId = '59342';
3986 must_warn 'qr/\400/', '^Use of octal value above 377';
3991 # XXX: This set of tests is essentially broken, POSIX character classes
3992 # should not have differing definitions under Unicode.
3993 # There are property names for that.
3994 skip "Tests assume ASCII", 4 unless $IS_ASCII;
3996 my @notIsPunct = grep {/[[:punct:]]/ and not /\p{IsPunct}/}
3997 map {chr} 0x20 .. 0x7f;
3998 iseq join ('', @notIsPunct), '$+<=>^`|~',
3999 '[:punct:] disagress with IsPunct on Symbols';
4001 my @isPrint = grep {not /[[:print:]]/ and /\p{IsPrint}/}
4002 map {chr} 0 .. 0x1f, 0x7f .. 0x9f;
4003 iseq join ('', @isPrint), "\x09\x0a\x0b\x0c\x0d\x85",
4004 'IsPrint disagrees with [:print:] on control characters';
4006 my @isPunct = grep {/[[:punct:]]/ != /\p{IsPunct}/}
4007 map {chr} 0x80 .. 0xff;
4008 iseq join ('', @isPunct), "\xa1\xab\xb7\xbb\xbf", # ¡ « · » ¿
4009 'IsPunct disagrees with [:punct:] outside ASCII';
4011 my @isPunctLatin1 = eval q {
4012 use encoding 'latin1';
4013 grep {/[[:punct:]]/ != /\p{IsPunct}/} map {chr} 0x80 .. 0xff;
4015 skip "Eval failed ($@)", 1 if $@;
4016 skip "PERL_LEGACY_UNICODE_CHARCLASS_MAPPINGS set to 0", 1
4017 if !$ENV{PERL_TEST_LEGACY_POSIX_CC};
4018 iseq join ('', @isPunctLatin1), '',
4019 'IsPunct agrees with [:punct:] with explicit Latin1';
4024 local $BugId = '60034';
4025 my $a = "xyzt" x 8192;
4026 ok $a =~ /\A(?>[a-z])*\z/,
4027 '(?>) does not cause wrongness on long string';
4028 my $b = $a . chr 256;
4033 ok $b =~ /\A(?>[a-z])*\z/,
4034 '(?>) does not cause wrongness on long string with UTF-8';
4039 # Keep the following tests last -- they may crash perl
4041 print "# Tests that follow may crash perl\n";
4043 local $BugId = '19049/38869';
4044 local $Message = 'Pattern in a loop, failure should not ' .
4045 'affect previous success';
4047 'ab cdef', # Matches regex
4048 ('e' x 40000 ) .'ab c' # Matches not, but 'ab c' matches part of it
4053 m/ab(.+)cd/i; # The ignore-case seems to be important
4054 $y = $1; # Use $1, which might not be from the last match!
4055 $x = substr ($list [0], $- [0], $+ [0] - $- [0]);
4063 local $BugId = '24274';
4065 ok (("a" x (2 ** 15 - 10)) =~ /^()(a|bb)*$/, "Recursive stack cracker");
4066 ok ((q(a)x 100) =~ /^(??{'(.)'x 100})/,
4067 "Regexp /^(??{'(.)'x 100})/ crashes older perls");
4073 ok $@ =~ /\QSequence \k... not terminated in regex;\E/,
4074 'Lone \k not allowed';
4079 local $Message = "Substitution with lookahead (possible segv)";
4082 iseq $_, "ns_1ns_1ns_1";
4087 s/(?=\d+)|(?<=\d)/!Bang!/g;
4088 iseq $_, "!Bang!1!Bang!2!Bang!3!Bang!";
4093 # [perl #45337] utf8 + "[a]a{2}" + /$.../ = panic: sv_len_utf8 cache
4094 local $BugId = '45337';
4095 local ${^UTF8CACHE} = -1;
4096 local $Message = "Shouldn't panic";
4102 local $BugId = '57042';
4103 local $Message = "Check if tree logic breaks \$^R";
4104 my $cond_re = qr/\s*
4111 for my $line ("(A)","(B)") {
4112 if ($line =~ m/$cond_re/) {
4113 push @res, $^R ? "#$^R" : "UNDEF";
4116 iseq "@res","#1 #2";
4119 no warnings 'closure';
4120 my $re = qr/A(??{"1"})/;
4121 ok "A1B" =~ m/^((??{ $re }))((??{"B"}))$/;
4129 local $Message = 'Test if $^N and $+ work in (?{{})';
4137 push @ctl_n, (defined $^N ? $^N : "undef");
4138 push @plus, (defined $+ ? $+ : "undef");
4149 # [ Expected result, Regex, Expected value(s) of $^N, Expected value(s) of $+ ]
4150 [ 1, qr#^$nested_tags$#, "bla blubb bla", "a b a" ],
4151 [ 1, qr#^($nested_tags)$#, "bla blubb <bla><blubb></blubb></bla>", "a b a" ],
4152 [ 1, qr#^(|)$nested_tags$#, "bla blubb bla", "a b a" ],
4153 [ 1, qr#^(?:|)$nested_tags$#, "bla blubb bla", "a b a" ],
4154 [ 1, qr#^<(bl|bla)>$nested_tags<(/\1)>$#, "blubb /bla", "b /bla" ],
4155 [ 1, qr#(??{"(|)"})$nested_tags$#, "bla blubb bla", "a b a" ],
4156 [ 1, qr#^(??{"(bla|)"})$nested_tags$#, "bla blubb bla", "a b a" ],
4157 [ 1, qr#^(??{"(|)"})(??{$nested_tags})$#, "bla blubb undef", "a b undef" ],
4158 [ 1, qr#^(??{"(?:|)"})$nested_tags$#, "bla blubb bla", "a b a" ],
4159 [ 1, qr#^((??{"(?:bla|)"}))((??{$nested_tags}))$#, "bla blubb <bla><blubb></blubb></bla>", "a b <bla><blubb></blubb></bla>" ],
4160 [ 1, qr#^((??{"(?!)?"}))((??{$nested_tags}))$#, "bla blubb <bla><blubb></blubb></bla>", "a b <bla><blubb></blubb></bla>" ],
4161 [ 1, qr#^((??{"(?:|<(/?bla)>)"}))((??{$nested_tags}))\1$#, "bla blubb <bla><blubb></blubb></bla>", "a b <bla><blubb></blubb></bla>" ],
4162 [ 0, qr#^((??{"(?!)"}))?((??{$nested_tags}))(?!)$#, "bla blubb undef", "a b undef" ],
4164 ) { #"#silence vim highlighting
4168 my $match = (("<bla><blubb></blubb></bla>" =~ $test->[1]) ? 1 : 0);
4169 push @ctl_n, (defined $^N ? $^N : "undef");
4170 push @plus, (defined $+ ? $+ : "undef");
4171 ok($test->[0] == $match, "match $c");
4172 if ($test->[0] != $match) {
4173 # unset @ctl_n and @plus
4174 @ctl_n = @plus = ();
4176 iseq("@ctl_n", $test->[2], "ctl_n $c");
4177 iseq("@plus", $test->[3], "plus $c");
4183 local $BugId = '56194';
4188 defined $_[0] ? $_[0] : "undef";
4191 ok("123" =~ m/^(\d)(((??{1 + $^N})))+$/);
4196 my $re = qr#(1)((??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1}))*(?{$^N})#;
4197 my $re2 = qr#(1)((??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1}))*(?{$^N})(|a(b)c|def)(??{"$^R"})#;
4198 my $re3 = qr#(1)((??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1})){2}(?{$^N})(|a(b)c|def)(??{"$^R"})#;
4200 local $re5 = qr#(1)((??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1})){2}(?{$^N})#;
4201 my $re6 = qr#(??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1})#;
4202 my $re7 = qr#(??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1})#;
4203 my $re8 = qr/(\d+)/;
4210 # Expected values of $^N
4211 # Expected values of $+
4212 # Expected values of $1, $2, $3, $4 and $5
4216 qr#^(1)((??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1}))+(??{$^N})$#,
4219 "\$1 = 1, \$2 = 3, \$3 = undef, \$4 = undef, \$5 = undef",
4223 qr#^(1)((??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1}))+(abc|def|)?(??{$+})$#,
4226 "\$1 = 1, \$2 = 3, \$3 = undef, \$4 = undef, \$5 = undef",
4230 qr#^(1)((??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1}))+(|abc|def)?(??{$+})$#,
4233 "\$1 = 1, \$2 = 3, \$3 = undef, \$4 = undef, \$5 = undef",
4237 qr#^(1)((??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1}))+(abc|def|)?(??{$^N})$#,
4240 "\$1 = 1, \$2 = 3, \$3 = undef, \$4 = undef, \$5 = undef",
4244 qr#^(1)((??{ push @ctl_n, $f->($^N); push @plus, $f->($+); $^N + 1}))+(|abc|def)?(??{$^N})$#,
4247 "\$1 = 1, \$2 = 3, \$3 = undef, \$4 = undef, \$5 = undef",
4251 qr#^($re)(|a(b)c|def)(??{$^R})$#,
4254 "\$1 = 123, \$2 = 1, \$3 = 3, \$4 = abc, \$5 = b",
4261 "\$1 = 123abc3, \$2 = 1, \$3 = 3, \$4 = abc, \$5 = b",
4268 "\$1 = 123abc3, \$2 = 1, \$3 = 3, \$4 = abc, \$5 = b",
4272 qr#^(??{$re5})(|abc|def)(??{"$^R"})$#,
4275 "\$1 = abc, \$2 = undef, \$3 = undef, \$4 = undef, \$5 = undef",
4279 qr#^(??{$re5})(|a(b)c|def)(??{"$^R"})$#,
4282 "\$1 = abc, \$2 = b, \$3 = undef, \$4 = undef, \$5 = undef",
4286 qr#^((\d+)((??{push @ctl_n, $f->($^N); push @plus, $f->($+);$^N + 1}))((??{push @ctl_n, $f->($^N); push @plus, $f->($+);$^N + 1}))((??{push @ctl_n, $f->($^N); push @plus, $f->($+);$^N + 1})))$#,
4287 "1234 123 12 1 2 3 1234",
4288 "1234 123 12 1 2 3 4",
4289 "\$1 = 1234, \$2 = 1, \$3 = 2, \$4 = 3, \$5 = 4",
4293 qr#^(\d+)($re6)($re6)($re6)$re6(($re6)$re6)$#,
4294 "1234556 123455 12345 1234 123 12 1 2 3 4 4 5 56",
4295 "1234556 123455 12345 1234 123 12 1 2 3 4 4 5 5",
4296 "\$1 = 1, \$2 = 2, \$3 = 3, \$4 = 4, \$5 = 56",
4300 qr#^((??{$re8}))($re7)($re7)($re7)$re7($re7)($re7(\2))$#,
4301 "12345562 1234556 123455 12345 1234 123 12 1 2 3 4 4 5 62",