3 # This is a home for regular expression tests that don't fit into
4 # the format supported by op/regexp.t. If you want to add a test
5 # that does fit that format, add it to op/re_tests, not here.
16 my $EXPECTED_TESTS = 3965; # 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 local $TODO = "See bug 60464" if $l > 32767;
498 ok "ba$a=" =~ /b(?:a|b)+=/;
504 # 20000 nodes, each taking 3 words per string, and 1 per branch
505 my $long_constant_len = join '|', 12120 .. 32645;
506 my $long_var_len = join '|', 8120 .. 28645;
507 my %ans = ( 'ax13876y25677lbc' => 1,
508 'ax13876y25677mcb' => 0, # not b.
509 'ax13876y35677nbc' => 0, # Num too big
510 'ax13876y25677y21378obc' => 1,
511 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
512 'ax13876y25677y21378y21378kbc' => 1,
513 'ax13876y25677y21378y21378kcb' => 0, # Not b.
514 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
517 local $Message = "20000 nodes";
519 local $Error = "const-len '$_'";
520 ok !($ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o);
522 local $Error = "var-len '$_'";
523 ok !($ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o);
528 local $Message = "Complicated backtracking";
529 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
530 my $expect = "(bla()) ((l)u((e))) (l(e)e)";
537 (?{ $c = 1 }) # Initialize
539 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
541 ) # Fail: will unwind one iteration back
544 [^()]+ # Match a big chunk
547 ) # Do not try to match subchunks
555 )+ # This may not match with different subblocks
560 ) # Otherwise the chunk 1 may succeed with $c>0
566 push @ans, $res while $res = matchit;
567 iseq "@ans", "1 1 1";
570 iseq "@ans", $expect;
572 local $Message = "Recursion with (??{ })";
574 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
576 @ans = my @ans1 = ();
577 push (@ans, $res), push (@ans1, $&) while $res = m/$matched/g;
579 iseq "@ans", "1 1 1";
580 iseq "@ans1", $expect;
583 iseq "@ans", $expect;
588 ok "abc" =~ /^(??{"a"})b/, '"abc" =~ /^(??{"a"})b/';
592 my @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
593 iseq "@ans", 'a/ b', "Stack may be bad";
597 local $Message = "Eval-group not allowed at runtime";
598 my $code = '{$blah = 45}';
601 ok $@ && $@ =~ /not allowed at runtime/ && $blah == 12;
603 for $code ('{$blah = 45}','=xx') {
605 my $res = eval { "xx" =~ /(?$code)/o };
606 no warnings 'uninitialized';
607 local $Error = "'$@', '$res', '$blah'";
608 if ($code eq '=xx') {
612 ok $@ && $@ =~ /not allowed at runtime/ && $blah == 12;
616 $code = '{$blah = 45}';
627 local $Message = "Pos checks";
641 iseq f (pos ($x)), 4;
645 local $Message = 'Checking $^R';
647 'foot' =~ /foo(?{$x = 12; 75})[t]/;
651 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
652 ok $^R eq '67' && $x eq '12';
655 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
656 ok $^R eq '79' && $x eq '12';
660 iseq qr/\b\v$/i, '(?i-xsm:\b\v$)', 'qr/\b\v$/i';
661 iseq qr/\b\v$/s, '(?s-xim:\b\v$)', 'qr/\b\v$/s';
662 iseq qr/\b\v$/m, '(?m-xis:\b\v$)', 'qr/\b\v$/m';
663 iseq qr/\b\v$/x, '(?x-ism:\b\v$)', 'qr/\b\v$/x';
664 iseq qr/\b\v$/xism, '(?msix:\b\v$)', 'qr/\b\v$/xism';
665 iseq qr/\b\v$/, '(?-xism:\b\v$)', 'qr/\b\v$/';
670 local $Message = "Look around";
673 foreach my $ans ('', 'c') {
674 ok /(?<=(?=a)..)((?=c)|.)/g or skip "Match failed", 1;
680 local $Message = "Empty clause";
682 foreach my $ans ('', 'a', '') {
683 ok /^|a|$/g or skip "Match failed", 1;
689 local $Message = "Prefixify";
692 my ($v, $a, $b, $res) = @_;
693 ok $v =~ s/\Q$a\E/$b/ or skip "Match failed", 1;
698 prefixify ('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
699 prefixify ('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
705 ok $1 && /$1/, "Capture a quote";
709 local $Message = "Call code from qr //";
712 ok /$a$a/ && $b eq '9';
715 ok /$a$a/ && $b eq '11';
719 ok $@ && $@ =~ /not allowed at runtime/;
728 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
736 my $match = eval { /$a$c$a/ };
737 ok $@ && $@ =~ /Eval-group not allowed/ && !$match;
744 $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
754 no warnings 'closure';
755 local $Message = '(?{ $var } refers to package vars';
759 '' =~ /(?{ $c = 4 })/;
766 must_die 'q(a:[b]:) =~ /[x[:foo:]]/',
767 'POSIX class \[:[^:]+:\] unknown in regex',
768 'POSIX class [: :] must have valid name';
770 for my $d (qw [= .]) {
771 must_die "/[[${d}foo${d}]]/",
772 "\QPOSIX syntax [$d $d] is reserved for future extensions",
773 "POSIX syntax [[$d $d]] is an error";
779 # test if failure of patterns returns empty list
780 local $Message = "Failed pattern returns empty list";
797 local $Message = '@- and @+ tests';
804 ok !defined $+ [1] && !defined $- [1] &&
805 !defined $+ [2] && !defined $- [2];
816 ok !defined $+ [3] && !defined $- [3] &&
817 !defined $+ [4] && !defined $- [4];
827 ok !defined $+ [2] && !defined $- [2] &&
828 !defined $+ [4] && !defined $- [4];
838 ok !defined $+ [2] && !defined $- [2] &&
839 !defined $+ [3] && !defined $- [3];
848 local $DiePattern = '^Modification of a read-only value attempted';
849 local $Message = 'Elements of @- and @+ are read-only';
850 must_die '$+[0] = 13';
851 must_die '$-[0] = 13';
852 must_die '@+ = (7, 6, 5)';
853 must_die '@- = qw (foo bar)';
858 local $Message = '\G testing';
870 ok $str =~ /\G../ && $& eq 'cd';
872 local $TODO = $running_as_thread;
873 ok $str =~ /.\G./ && $& eq 'bc';
878 local $Message = 'pos inside (?{ })';
881 ok $str =~ /b(?{$foo = $_; $bar = pos})c/;
884 ok !defined pos ($str);
889 ok $str =~ /b(?{$foo = $_; $bar = pos})c/g;
897 ok /b(?{$foo = $_; $bar = pos})c/;
903 ok /b(?{$foo = $_; $bar = pos})c/g;
911 1 while /b(?{$foo = $_; $bar = pos})c/g;
919 ok s/b(?{$foo = $_; $bar = pos})c/x/g;
920 iseq $foo, 'abcde|abcde';
922 iseq $_, 'axde|axde';
927 () = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
928 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
929 iseq "@res", "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
932 () = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
933 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
934 iseq "@res", "'' 'ab' 'cde|abcde' " .
935 "'' 'abc' 'de|abcde' " .
936 "'abcd' 'e|' 'abcde' " .
937 "'abcde|' 'ab' 'cde' " .
938 "'abcde|' 'abc' 'de'" ;
943 local $Message = '\G anchor checks';
944 my $foo = 'aabbccddeeffgg';
947 local $TODO = $running_as_thread;
948 no warnings 'uninitialized';
949 ok $foo =~ /.\G(..)/g;
953 ok $foo =~ /.\G(..)/g;
957 ok $foo =~ /.\G(..)/g;
964 ok $foo =~ /\G(..)/g;
967 ok $foo =~ /\G(..)/g;
971 ok $foo =~ /\G(..)/g;
978 my @res = /(\d*|x)/g;
980 iseq "@res", "123||x|123|", "0 match in alternation";
985 local $Message = "Match against temporaries (created via pp_helem())" .
987 ok {foo => "bar\n" . $^X} -> {foo} =~ /^(.*)\n/g;
993 local $Message = 'package $i inside (?{ }), ' .
994 'saved substrings and changing $_';
995 our @a = qw [foo bar];
997 s/(\w)(?{push @b, $1})/,$1,/g for @a;
998 iseq "@b", "f o o b a r";
999 iseq "@a", ",f,,o,,o, ,b,,a,,r,";
1001 local $Message = 'lexical $i inside (?{ }), ' .
1002 'saved substrings and changing $_';
1003 no warnings 'closure';
1004 my @c = qw [foo bar];
1006 s/(\w)(?{push @d, $1})/,$1,/g for @c;
1007 iseq "@d", "f o o b a r";
1008 iseq "@c", ",f,,o,,o, ,b,,a,,r,";
1013 local $Message = 'Brackets';
1016 { (?> [^{}]+ | (??{ $brackets }) )* }
1019 ok "{{}" =~ $brackets;
1021 ok "something { long { and } hairy" =~ $brackets;
1023 ok "something { long { and } hairy" =~ m/((??{ $brackets }))/;
1031 nok m/^-.*bb/mg, '$_ = "a-a\nxbb"; m/^-.*bb/mg';
1036 local $Message = '\G anchor checks';
1037 my $text = "aaXbXcc";
1039 ok $text !~ /\GXb*X/g;
1045 nok /^\s*A/m, '$_ = "xA\n" x 500; /^\s*A/m"';
1047 my $text = "abc dbf";
1048 my @res = ($text =~ /.*?(b).*?\b/g);
1049 iseq "@res", "b b", '\b is not special';
1054 local $Message = '\S, [\S], \s, [\s]';
1055 my @a = map chr, 0 .. 255;
1056 my @b = grep /\S/, @a;
1057 my @c = grep /[^\s]/, @a;
1061 @c = grep /[\S]/, @a;
1065 @c = grep /[^\S]/, @a;
1069 @c = grep /[\s]/, @a;
1073 local $Message = '\D, [\D], \d, [\d]';
1074 my @a = map chr, 0 .. 255;
1075 my @b = grep /\D/, @a;
1076 my @c = grep /[^\d]/, @a;
1080 @c = grep /[\D]/, @a;
1084 @c = grep /[^\D]/, @a;
1088 @c = grep /[\d]/, @a;
1092 local $Message = '\W, [\W], \w, [\w]';
1093 my @a = map chr, 0 .. 255;
1094 my @b = grep /\W/, @a;
1095 my @c = grep /[^\w]/, @a;
1099 @c = grep /[\W]/, @a;
1103 @c = grep /[^\W]/, @a;
1107 @c = grep /[\w]/, @a;
1113 # see if backtracking optimization works correctly
1114 local $Message = 'Backtrack optimization';
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;
1124 ok "\n\n" =~ /\n?+ $ \n/x;
1130 use overload '""' => sub {'Object S'};
1133 local $Message = "Ref stringification";
1134 ::ok do { \my $v} =~ /^SCALAR/, "Scalar ref stringification";
1135 ::ok do {\\my $v} =~ /^REF/, "Ref ref stringification";
1136 ::ok [] =~ /^ARRAY/, "Array ref stringification";
1137 ::ok {} =~ /^HASH/, "Hash ref stringification";
1138 ::ok 'S' -> new =~ /^Object S/, "Object stringification";
1143 local $Message = "Test result of match used as match";
1144 ok 'a1b' =~ ('xyz' =~ /y/);
1146 ok 'a1b' =~ ('xyz' =~ /t/);
1152 local $Message = '"1" is not \s';
1153 may_not_warn sub {ok ("1\n" x 102) !~ /^\s*\n/m};
1158 local $Message = '\s, [[:space:]] and [[:blank:]]';
1159 my %space = (spc => " ",
1164 # There's no \v but the vertical tabulator seems miraculously
1165 # be 11 both in ASCII and EBCDIC.
1169 my @space0 = sort grep {$space {$_} =~ /\s/ } keys %space;
1170 my @space1 = sort grep {$space {$_} =~ /[[:space:]]/} keys %space;
1171 my @space2 = sort grep {$space {$_} =~ /[[:blank:]]/} keys %space;
1173 iseq "@space0", "cr ff lf spc tab";
1174 iseq "@space1", "cr ff lf spc tab vt";
1175 iseq "@space2", "spc tab";
1180 local $BugId = '20000731.001';
1181 ok "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/,
1182 "Match UTF-8 char in presense of (??{ })";
1187 local $BugId = '20001021.005';
1188 no warnings 'uninitialized';
1189 ok undef =~ /^([^\/]*)(.*)$/, "Used to cause a SEGV";
1195 local $Message = '\C matches octet';
1197 ok /(.)(\C)(\C)(.)/ or skip q [\C doesn't match], 4;
1199 if ($IS_ASCII) { # ASCII (or equivalent), should be UTF-8
1203 elsif ($IS_EBCDIC) { # EBCDIC (or equivalent), should be UTF-EBCDIC
1209 ok 0, "Unexpected platform", "ord ('A') = $ordA";
1210 skip "Unexpected platform";
1219 local $Message = '\C matches octet';
1221 ok /(\C)/g or skip q [\C doesn't match], 2;
1225 elsif ($IS_EBCDIC) {
1229 ok 0, "Unexpected platform", "ord ('A') = $ordA";
1231 ok /(\C)/g or skip q [\C doesn't match];
1235 elsif ($IS_EBCDIC) {
1239 ok 0, "Unexpected platform", "ord ('A') = $ordA";
1245 # Japhy -- added 03/03/2001
1246 () = (my $str = "abc") =~ /(...)/;
1248 iseq $1, "abc", 'Changing subject does not modify $1';
1254 # The trick is that in EBCDIC the explicit numeric range should
1255 # match (as also in non-EBCDIC) but the explicit alphabetic range
1257 ok "\x8e" =~ /[\x89-\x91]/, '"\x8e" =~ /[\x89-\x91]/';
1258 ok "\xce" =~ /[\xc9-\xd1]/, '"\xce" =~ /[\xc9-\xd1]/';
1260 skip "Not an EBCDIC platform", 2 unless ord ('i') == 0x89 &&
1263 # In most places these tests would succeed since \x8e does not
1264 # in most character sets match 'i' or 'j' nor would \xce match
1265 # 'I' or 'J', but strictly speaking these tests are here for
1266 # the good of EBCDIC, so let's test these only there.
1267 nok "\x8e" !~ /[i-j]/, '"\x8e" !~ /[i-j]/';
1268 nok "\xce" !~ /[I-J]/, '"\xce" !~ /[I-J]/';
1273 ok "\x{ab}" =~ /\x{ab}/, '"\x{ab}" =~ /\x{ab}/ ';
1274 ok "\x{abcd}" =~ /\x{abcd}/, '"\x{abcd}" =~ /\x{abcd}/';
1279 local $Message = 'bug id 20001008.001';
1281 my @x = ("stra\337e 138", "stra\337e 138");
1283 ok s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1284 ok my ($latin) = /^(.+)(?:\s+\d)/;
1285 iseq $latin, "stra\337e";
1286 ok $latin =~ s/stra\337e/straße/;
1288 # Previous code follows, but outcommented - there were no tests.
1290 # $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1291 # use utf8; # needed for the raw UTF-8
1292 # $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1298 local $Message = 'Test \x escapes';
1299 ok "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1300 ok "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1301 ok "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1302 ok "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1303 ok "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1304 ok "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1305 ok "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1306 ok "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1311 local $BugId = '20001028.003';
1313 # Fist half of the bug.
1314 local $Message = 'HEBREW ACCENT QADMA matched by .*';
1316 ok my ($Y) = $X =~ /(.*)/;
1318 iseq length ($Y), 1;
1320 # Second half of the bug.
1321 $Message = 'HEBREW ACCENT QADMA in replacement';
1323 $X =~ s/^/chr(1488)/e;
1325 iseq ord ($X), 1488;
1330 local $BugId = '20001108.001';
1331 local $Message = 'Repeated s///';
1332 my $X = "Szab\x{f3},Bal\x{e1}zs";
1334 $Y =~ s/(B)/$1/ for 0 .. 3;
1336 iseq $X, "Szab\x{f3},Bal\x{e1}zs";
1341 local $BugId = '20000517.001';
1342 local $Message = 's/// on UTF-8 string';
1345 iseq $x, "\x{100}B";
1351 local $BugId = '20001230.002';
1352 local $Message = '\C and É';
1353 ok "École" =~ /^\C\C(.)/ && $1 eq 'c';
1354 ok "École" =~ /^\C\C(c)/;
1360 local $Message = 'Match code points > 255';
1361 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1362 ok /(.\x{300})./ or skip "No match", 4;
1363 ok $` eq "abc\x{100}" && length ($`) == 4;
1364 ok $& eq "\x{200}\x{300}\x{380}" && length ($&) == 3;
1365 ok $' eq "\x{400}defg" && length ($') == 5;
1366 ok $1 eq "\x{200}\x{300}" && length ($1) == 2;
1371 # The original bug report had 'no utf8' here but that was irrelevant.
1372 local $BugId = '20010306.008';
1373 local $Message = "Don't dump core";
1374 my $a = "a\x{1234}";
1375 ok $a =~ m/\w/; # used to core dump.
1380 local $BugId = '20010410.006';
1381 local $Message = '/g in scalar context';
1382 for my $rx ('/(.*?)\{(.*?)\}/csg',
1383 '/(.*?)\{(.*?)\}/cg',
1384 '/(.*?)\{(.*?)\}/sg',
1385 '/(.*?)\{(.*?)\}/g',
1386 '/(.+?)\{(.+?)\}/csg',) {
1388 my $input = "a{b}c{d}";
1390 while (eval \$input =~ $rx) {
1400 my $x = "\x{10FFFD}";
1402 ok ord($x) == 0x10FFFD && length($x) == 1, "From Robin Houston";
1414 while (my ($code, $match) = each %d) {
1415 local $Message = "Properties of \\x$code";
1416 my $char = eval qq ["\\x{$code}"];
1418 ok (($char =~ /[\x80-\xff]/) xor !$$match [$i ++]);
1419 ok (($char =~ /[\x80-\x{100}]/) xor !$$match [$i ++]);
1420 ok (($char =~ /[\x{100}]/) xor !$$match [$i ++]);
1428 must_warn 'qr/(?c)/', '^Useless \(\?c\)';
1429 must_warn 'qr/(?-c)/', '^Useless \(\?-c\)';
1430 must_warn 'qr/(?g)/', '^Useless \(\?g\)';
1431 must_warn 'qr/(?-g)/', '^Useless \(\?-g\)';
1432 must_warn 'qr/(?o)/', '^Useless \(\?o\)';
1433 must_warn 'qr/(?-o)/', '^Useless \(\?-o\)';
1435 # Now test multi-error regexes
1436 must_warn 'qr/(?g-o)/', '^Useless \(\?g\).*\nUseless \(\?-o\)';
1437 must_warn 'qr/(?g-c)/', '^Useless \(\?g\).*\nUseless \(\?-c\)';
1438 # (?c) means (?g) error won't be thrown
1439 must_warn 'qr/(?o-cg)/', '^Useless \(\?o\).*\nUseless \(\?-c\)';
1440 must_warn 'qr/(?ogc)/', '^Useless \(\?o\).*\nUseless \(\?g\).*\n' .
1446 local $Message = "/x tests";
1466 local $Message = "/o feature";
1467 sub test_o {$_ [0] =~ /$_[1]/o; return $1}
1468 iseq test_o ('abc', '(.)..'), 'a';
1469 iseq test_o ('abc', '..(.)'), 'a';
1474 local $BugId = "20010619.003";
1475 # Amazingly vertical tabulator is the same in ASCII and EBCDIC.
1476 for ("\n", "\t", "\014", "\r") {
1477 ok !/[[:print:]]/, "'$_' not in [[:print:]]";
1480 ok /[[:print:]]/, "'$_' in [[:print:]]";
1486 # Test basic $^N usage outside of a regex
1487 local $Message = '$^N usage outside of a regex';
1489 ok ($x =~ /cde/ and !defined $^N);
1490 ok ($x =~ /(cde)/ and $^N eq "cde");
1491 ok ($x =~ /(c)(d)(e)/ and $^N eq "e");
1492 ok ($x =~ /(c(d)e)/ and $^N eq "cde");
1493 ok ($x =~ /(foo)|(c(d)e)/ and $^N eq "cde");
1494 ok ($x =~ /(c(d)e)|(foo)/ and $^N eq "cde");
1495 ok ($x =~ /(c(d)e)|(abc)/ and $^N eq "abc");
1496 ok ($x =~ /(c(d)e)|(abc)x/ and $^N eq "cde");
1497 ok ($x =~ /(c(d)e)(abc)?/ and $^N eq "cde");
1498 ok ($x =~ /(?:c(d)e)/ and $^N eq "d");
1499 ok ($x =~ /(?:c(d)e)(?:f)/ and $^N eq "d");
1500 ok ($x =~ /(?:([abc])|([def]))*/ and $^N eq "f");
1501 ok ($x =~ /(?:([ace])|([bdf]))*/ and $^N eq "f");
1502 ok ($x =~ /(([ace])|([bd]))*/ and $^N eq "e");
1503 {ok ($x =~ /(([ace])|([bdf]))*/ and $^N eq "f");}
1504 ## Test to see if $^N is automatically localized -- it should now
1505 ## have the value set in the previous test.
1506 iseq $^N, "e", '$^N is automatically localized';
1508 # Now test inside (?{ ... })
1509 local $Message = '$^N usage inside (?{ ... })';
1511 ok ($x =~ /a([abc])(?{$y=$^N})c/ and $y eq "b");
1512 ok ($x =~ /a([abc]+)(?{$y=$^N})d/ and $y eq "bc");
1513 ok ($x =~ /a([abcdefg]+)(?{$y=$^N})d/ and $y eq "bc");
1514 ok ($x =~ /(a([abcdefg]+)(?{$y=$^N})d)(?{$z=$^N})e/ and $y eq "bc"
1516 ok ($x =~ /(a([abcdefg]+)(?{$y=$^N})de)(?{$z=$^N})/ and $y eq "bc"
1524 ## Should probably put in tests for all the POSIX stuff,
1525 ## but not sure how to guarantee a specific locale......
1527 skip "Not an ASCII platform", 2 unless $IS_ASCII;
1528 local $Message = 'Test [[:cntrl:]]';
1529 my $AllBytes = join "" => map {chr} 0 .. 255;
1530 (my $x = $AllBytes) =~ s/[[:cntrl:]]//g;
1531 iseq $x, join "", map {chr} 0x20 .. 0x7E, 0x80 .. 0xFF;
1533 ($x = $AllBytes) =~ s/[^[:cntrl:]]//g;
1534 iseq $x, join "", map {chr} 0x00 .. 0x1F, 0x7F;
1539 # With /s modifier UTF8 chars were interpreted as bytes
1540 local $Message = "UTF-8 chars aren't bytes";
1541 my $a = "Hello \x{263A} World";
1542 my @a = ($a =~ /./gs);
1548 local $Message = '. matches \n with /s';
1549 my $str1 = "foo\nbar";
1550 my $str2 = "foo\n\x{100}bar";
1551 my ($a, $b) = map {chr} $IS_ASCII ? (0xc4, 0x80) : (0x8c, 0x41);
1553 @a = $str1 =~ /./g; iseq @a, 6; iseq "@a", "f o o b a r";
1554 @a = $str1 =~ /./gs; iseq @a, 7; iseq "@a", "f o o \n b a r";
1555 @a = $str1 =~ /\C/g; iseq @a, 7; iseq "@a", "f o o \n b a r";
1556 @a = $str1 =~ /\C/gs; iseq @a, 7; iseq "@a", "f o o \n b a r";
1557 @a = $str2 =~ /./g; iseq @a, 7; iseq "@a", "f o o \x{100} b a r";
1558 @a = $str2 =~ /./gs; iseq @a, 8; iseq "@a", "f o o \n \x{100} b a r";
1559 @a = $str2 =~ /\C/g; iseq @a, 9; iseq "@a", "f o o \n $a $b b a r";
1560 @a = $str2 =~ /\C/gs; iseq @a, 9; iseq "@a", "f o o \n $a $b b a r";
1565 # [ID 20010814.004] pos() doesn't work when using =~m// in list context
1566 local $BugId = '20010814.004';
1568 my $a = join ":", /b./gc;
1569 my $b = join ":", /a./gc;
1571 iseq "$a $b $c", 'ba:ba ad:ae 10', "pos() works with () = m//";
1576 # [ID 20010407.006] matching utf8 return values from
1577 # functions does not work
1578 local $BugId = '20010407.006';
1579 local $Message = 'UTF-8 return values from functions';
1580 package ID_20010407_006;
1586 ::ok length ($y) == 2 && $y eq $x;
1589 ::ok length ($y) == 2 && $y eq $x;
1594 no warnings 'digit';
1595 # Check that \x## works. 5.6.1 and 5.005_03 fail some of these.
1598 ok ($x =~ /^\x4EE$/, "Check only 2 bytes of hex are matched.");
1601 ok ($x =~ /^\x4Ei$/, "Check that invalid hex digit stops it (2)");
1604 ok ($x =~ /^\x4j$/, "Check that invalid hex digit stops it (1)");
1607 ok ($x =~ /^\xk$/, "Check that invalid hex digit stops it (0)");
1610 ok ($x =~ /^\xx$/, "\\xx isn't to be treated as \\0");
1613 ok ($x =~ /^\xxa$/, "\\xxa isn't to be treated as \\xa");
1616 ok ($x =~ /^\x9_b$/, "\\x9_b isn't to be treated as \\x9b");
1618 # and now again in [] ranges
1621 ok ($x =~ /^[\x4EE]{2}$/, "Check only 2 bytes of hex are matched.");
1624 ok ($x =~ /^[\x4Ei]{2}$/, "Check that invalid hex digit stops it (2)");
1627 ok ($x =~ /^[\x4j]{2}$/, "Check that invalid hex digit stops it (1)");
1630 ok ($x =~ /^[\xk]{2}$/, "Check that invalid hex digit stops it (0)");
1633 ok ($x =~ /^[\xx]{2}$/, "\\xx isn't to be treated as \\0");
1636 ok ($x =~ /^[\xxa]{3}$/, "\\xxa isn't to be treated as \\xa");
1639 ok ($x =~ /^[\x9_b]{3}$/, "\\x9_b isn't to be treated as \\x9b");
1641 # Check that \x{##} works. 5.6.1 fails quite a few of these.
1644 ok ($x =~ /^\x{9_b}$/, "\\x{9_b} is to be treated as \\x9b");
1647 ok ($x =~ /^\x{9_b}y$/, "\\x{9_b} is to be treated as \\x9b (again)");
1650 ok ($x =~ /^\x{9b_}y$/, "\\x{9b_} is to be treated as \\x9b");
1653 ok ($x =~ /^\x{9_bq}y$/, "\\x{9_bc} is to be treated as \\x9b");
1656 ok ($x =~ /^\x{x9b}y$/, "\\x{x9b} is to be treated as \\x0");
1659 ok ($x =~ /^\x{0x9b}y$/, "\\x{0x9b} is to be treated as \\x0");
1662 ok ($x =~ /^\x{09b}y$/, "\\x{09b} is to be treated as \\x9b");
1665 ok ($x =~ /^[\x{9_b}]$/, "\\x{9_b} is to be treated as \\x9b");
1668 ok ($x =~ /^[\x{9_b}y]{2}$/,
1669 "\\x{9_b} is to be treated as \\x9b (again)");
1672 ok ($x =~ /^[\x{9b_}y]{2}$/, "\\x{9b_} is to be treated as \\x9b");
1675 ok ($x =~ /^[\x{9_bq}y]{2}$/, "\\x{9_bc} is to be treated as \\x9b");
1678 ok ($x =~ /^[\x{x9b}y]{2}$/, "\\x{x9b} is to be treated as \\x0");
1681 ok ($x =~ /^[\x{0x9b}y]{2}$/, "\\x{0x9b} is to be treated as \\x0");
1684 ok ($x =~ /^[\x{09b}y]{2}$/, "\\x{09b} is to be treated as \\x9b");
1690 # High bit bug -- japhy
1692 ok $x =~ /.*?\200/, "High bit fine";
1697 # The basic character classes and Unicode
1698 ok "\x{0100}" =~ /\w/, 'LATIN CAPITAL LETTER A WITH MACRON in /\w/';
1699 ok "\x{0660}" =~ /\d/, 'ARABIC-INDIC DIGIT ZERO in /\d/';
1700 ok "\x{1680}" =~ /\s/, 'OGHAM SPACE MARK in /\s/';
1705 local $Message = "Folding matches and Unicode";
1706 ok "a\x{100}" =~ /A/i;
1707 ok "A\x{100}" =~ /a/i;
1708 ok "a\x{100}" =~ /a/i;
1709 ok "A\x{100}" =~ /A/i;
1710 ok "\x{101}a" =~ /\x{100}/i;
1711 ok "\x{100}a" =~ /\x{100}/i;
1712 ok "\x{101}a" =~ /\x{101}/i;
1713 ok "\x{100}a" =~ /\x{101}/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\x{100}/i;
1718 ok "a\x{100}" =~ /[A]/i;
1719 ok "A\x{100}" =~ /[a]/i;
1720 ok "a\x{100}" =~ /[a]/i;
1721 ok "A\x{100}" =~ /[A]/i;
1722 ok "\x{101}a" =~ /[\x{100}]/i;
1723 ok "\x{100}a" =~ /[\x{100}]/i;
1724 ok "\x{101}a" =~ /[\x{101}]/i;
1725 ok "\x{100}a" =~ /[\x{101}]/i;
1730 use charnames ':full';
1731 local $Message = "Folding 'LATIN LETTER A WITH GRAVE'";
1733 my $lower = "\N{LATIN SMALL LETTER A WITH GRAVE}";
1734 my $UPPER = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";
1736 ok $lower =~ m/$UPPER/i;
1737 ok $UPPER =~ m/$lower/i;
1738 ok $lower =~ m/[$UPPER]/i;
1739 ok $UPPER =~ m/[$lower]/i;
1741 local $Message = "Folding 'GREEK LETTER ALPHA WITH VRACHY'";
1743 $lower = "\N{GREEK CAPITAL LETTER ALPHA WITH VRACHY}";
1744 $UPPER = "\N{GREEK SMALL LETTER ALPHA WITH VRACHY}";
1746 ok $lower =~ m/$UPPER/i;
1747 ok $UPPER =~ m/$lower/i;
1748 ok $lower =~ m/[$UPPER]/i;
1749 ok $UPPER =~ m/[$lower]/i;
1751 local $Message = "Folding 'LATIN LETTER Y WITH DIAERESIS'";
1753 $lower = "\N{LATIN SMALL LETTER Y WITH DIAERESIS}";
1754 $UPPER = "\N{LATIN CAPITAL LETTER Y WITH DIAERESIS}";
1756 ok $lower =~ m/$UPPER/i;
1757 ok $UPPER =~ m/$lower/i;
1758 ok $lower =~ m/[$UPPER]/i;
1759 ok $UPPER =~ m/[$lower]/i;
1764 use charnames ':full';
1765 local $PatchId = "13843";
1766 local $Message = "GREEK CAPITAL LETTER SIGMA vs " .
1767 "COMBINING GREEK PERISPOMENI";
1769 my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}";
1770 my $char = "\N{COMBINING GREEK PERISPOMENI}";
1772 may_not_warn sub {ok "_:$char:_" !~ m/_:$SIGMA:_/i};
1777 local $Message = '\X';
1778 use charnames ':full';
1780 ok "a!" =~ /^(\X)!/ && $1 eq "a";
1781 ok "\xDF!" =~ /^(\X)!/ && $1 eq "\xDF";
1782 ok "\x{100}!" =~ /^(\X)!/ && $1 eq "\x{100}";
1783 ok "\x{100}\x{300}!" =~ /^(\X)!/ && $1 eq "\x{100}\x{300}";
1784 ok "\N{LATIN CAPITAL LETTER E}!" =~ /^(\X)!/ &&
1785 $1 eq "\N{LATIN CAPITAL LETTER E}";
1786 ok "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}!"
1788 $1 eq "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}";
1790 local $Message = '\C and \X';
1791 ok "!abc!" =~ /a\Cc/;
1792 ok "!abc!" =~ /a\Xc/;
1797 local $Message = "Final Sigma";
1799 my $SIGMA = "\x{03A3}"; # CAPITAL
1800 my $Sigma = "\x{03C2}"; # SMALL FINAL
1801 my $sigma = "\x{03C3}"; # SMALL
1803 ok $SIGMA =~ /$SIGMA/i;
1804 ok $SIGMA =~ /$Sigma/i;
1805 ok $SIGMA =~ /$sigma/i;
1807 ok $Sigma =~ /$SIGMA/i;
1808 ok $Sigma =~ /$Sigma/i;
1809 ok $Sigma =~ /$sigma/i;
1811 ok $sigma =~ /$SIGMA/i;
1812 ok $sigma =~ /$Sigma/i;
1813 ok $sigma =~ /$sigma/i;
1815 ok $SIGMA =~ /[$SIGMA]/i;
1816 ok $SIGMA =~ /[$Sigma]/i;
1817 ok $SIGMA =~ /[$sigma]/i;
1819 ok $Sigma =~ /[$SIGMA]/i;
1820 ok $Sigma =~ /[$Sigma]/i;
1821 ok $Sigma =~ /[$sigma]/i;
1823 ok $sigma =~ /[$SIGMA]/i;
1824 ok $sigma =~ /[$Sigma]/i;
1825 ok $sigma =~ /[$sigma]/i;
1827 local $Message = "More final Sigma";
1829 my $S3 = "$SIGMA$Sigma$sigma";
1831 ok ":$S3:" =~ /:(($SIGMA)+):/i && $1 eq $S3 && $2 eq $sigma;
1832 ok ":$S3:" =~ /:(($Sigma)+):/i && $1 eq $S3 && $2 eq $sigma;
1833 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;
1837 ok ":$S3:" =~ /:(([$sigma])+):/i && $1 eq $S3 && $2 eq $sigma;
1842 use charnames ':full';
1843 local $Message = "Parlez-Vous " .
1844 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais?";
1846 ok "Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran.ais/ &&
1848 ok "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran.ais/ &&
1849 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais";
1850 ok "Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran\Cais/ &&
1852 # COMBINING CEDILLA is two bytes when encoded
1853 ok "Franc\N{COMBINING CEDILLA}ais" =~ /Franc\C\Cais/;
1854 ok "Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran\Xais/ &&
1856 ok "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran\Xais/ &&
1857 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais";
1858 ok "Franc\N{COMBINING CEDILLA}ais" =~ /Fran\Xais/ &&
1859 $& eq "Franc\N{COMBINING CEDILLA}ais";
1860 ok "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
1861 /Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais/ &&
1862 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais";
1863 ok "Franc\N{COMBINING CEDILLA}ais" =~ /Franc\N{COMBINING CEDILLA}ais/ &&
1864 $& eq "Franc\N{COMBINING CEDILLA}ais";
1867 ["Fran\N{LATIN SMALL LETTER C}ais", "Francais"],
1868 ["Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais",
1869 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais"],
1870 ["Franc\N{COMBINING CEDILLA}ais", "Franc\N{COMBINING CEDILLA}ais"],
1872 foreach my $entry (@f) {
1873 my ($subject, $match) = @$entry;
1874 ok $subject =~ /Fran(?:c\N{COMBINING CEDILLA}?|
1875 \N{LATIN SMALL LETTER C WITH CEDILLA})ais/x &&
1882 local $Message = "Lingering (and useless) UTF8 flag doesn't mess up /i";
1884 my $str = "abcDE\x{100}";
1888 $pat = "ABcde\x{100}";
1893 $pat = "ABcde\x{100}";
1894 $str = "abcDE\x{100}";
1902 use charnames ':full';
1903 local $Message = "LATIN SMALL LETTER SHARP S " .
1904 "(\N{LATIN SMALL LETTER SHARP S})";
1906 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1907 /\N{LATIN SMALL LETTER SHARP S}/;
1908 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1909 /\N{LATIN SMALL LETTER SHARP S}/i;
1910 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1911 /[\N{LATIN SMALL LETTER SHARP S}]/;
1912 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1913 /[\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;
1918 ok "SS" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i;
1920 ok "\N{LATIN SMALL LETTER SHARP S}" =~ /ss/i;
1921 ok "\N{LATIN SMALL LETTER SHARP S}" =~ /SS/i;
1923 local $Message = "Unoptimized named sequence in class";
1924 ok "ss" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i;
1925 ok "SS" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i;
1926 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1927 /[\N{LATIN SMALL LETTER SHARP S}x]/;
1928 ok "\N{LATIN SMALL LETTER SHARP S}" =~
1929 /[\N{LATIN SMALL LETTER SHARP S}x]/i;
1934 # More whitespace: U+0085, U+2028, U+2029\n";
1936 # U+0085, U+00A0 need to be forced to be Unicode, the \x{100} does that.
1938 skip "EBCDIC platform", 4 if $IS_EBCDIC;
1939 # Do \x{0015} and \x{0041} match \s in EBCDIC?
1940 ok "<\x{100}\x{0085}>" =~ /<\x{100}\s>/, '\x{0085} in \s';
1941 ok "<\x{0085}>" =~ /<\v>/, '\x{0085} in \v';
1942 ok "<\x{100}\x{00A0}>" =~ /<\x{100}\s>/, '\x{00A0} in \s';
1943 ok "<\x{00A0}>" =~ /<\h>/, '\x{00A0} in \h';
1945 my @h = map {sprintf "%05x" => $_} 0x01680, 0x0180E, 0x02000 .. 0x0200A,
1946 0x0202F, 0x0205F, 0x03000;
1947 my @v = map {sprintf "%05x" => $_} 0x02028, 0x02029;
1949 my @H = map {sprintf "%05x" => $_} 0x01361, 0x0200B, 0x02408, 0x02420,
1951 my @V = map {sprintf "%05x" => $_} 0x0008A .. 0x0008D, 0x00348, 0x10100,
1955 my $str = eval qq ["<\\x{$hex}>"];
1956 ok $str =~ /<\s>/, "\\x{$hex} in \\s";
1957 ok $str =~ /<\h>/, "\\x{$hex} in \\h";
1958 ok $str !~ /<\v>/, "\\x{$hex} not in \\v";
1962 my $str = eval qq ["<\\x{$hex}>"];
1963 ok $str =~ /<\s>/, "\\x{$hex} in \\s";
1964 ok $str =~ /<\v>/, "\\x{$hex} in \\v";
1965 ok $str !~ /<\h>/, "\\x{$hex} not in \\h";
1969 my $str = eval qq ["<\\x{$hex}>"];
1970 ok $str =~ /<\S>/, "\\x{$hex} in \\S";
1971 ok $str =~ /<\H>/, "\\x{$hex} in \\H";
1975 my $str = eval qq ["<\\x{$hex}>"];
1976 ok $str =~ /<\S>/, "\\x{$hex} in \\S";
1977 ok $str =~ /<\V>/, "\\x{$hex} in \\V";
1983 # . with /s should work on characters, as opposed to bytes
1984 local $Message = ". with /s works on characters, not bytes";
1986 my $s = "\x{e4}\x{100}";
1987 # This is not expected to match: the point is that
1988 # neither should we get "Malformed UTF-8" warnings.
1989 may_not_warn sub {$s =~ /\G(.+?)\n/gcs}, "No 'Malformed UTF-8' warning";
1992 push @c => $1 while $s =~ /\G(.)/gs;
1997 # Test only chars < 256
1998 my $t1 = "Q003\n\n\x{e4}\x{f6}\n\nQ004\n\n\x{e7}";
2000 while ($t1 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2004 my $t2 = $t1 . "\x{100}"; # Repeat with a larger char
2006 while ($t2 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2016 local $Message = "Unicode lookbehind";
2017 ok "A\x{100}B" =~ /(?<=A.)B/;
2018 ok "A\x{200}\x{300}B" =~ /(?<=A..)B/;
2019 ok "\x{400}AB" =~ /(?<=\x{400}.)B/;
2020 ok "\x{500}\x{600}B" =~ /(?<=\x{500}.)B/;
2022 # Original code also contained:
2023 # ok "\x{500\x{600}}B" =~ /(?<=\x{500}.)B/;
2024 # but that looks like a typo.
2029 local $Message = 'UTF-8 hash keys and /$/';
2030 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters
2031 # /2002-01/msg01327.html
2034 my $v = substr ($u, 0, 1);
2035 my $w = substr ($u, 1, 1);
2036 my %u = ($u => $u, $v => $v, $w => $w);
2038 my $m1 = /^\w*$/ ? 1 : 0;
2039 my $m2 = $u {$_} =~ /^\w*$/ ? 1 : 0;
2046 local $BugId = "20020124.005";
2047 local $PatchId = "14795";
2048 local $Message = "s///eg";
2050 for my $char ("a", "\x{df}", "\x{100}") {
2051 my $x = "$char b $char";
2056 iseq substr ($x, 0, 1), substr ($x, -1, 1);
2062 local $Message = "No SEGV in s/// and UTF-8";
2063 my $s = "s#\x{100}" x 4;
2064 ok $s =~ s/[^\w]/ /g;
2065 if ($ENV {REAL_POSIX_CC}) {
2069 iseq $s, "s \x{100}" x 4;
2075 local $Message = "UTF-8 bug (maybe already known?)";
2077 $u =~ s/./\x{100}/g;
2078 iseq $u, "\x{100}\x{100}\x{100}";
2081 $u =~ s/[ao]/\x{100}/g;
2082 iseq $u, "f\x{100}\x{100}b\x{100}r";
2084 $u =~ s/\x{100}/e/g;
2090 local $Message = "UTF-8 bug with s///";
2091 # check utf8/non-utf8 mixtures
2092 # try to force all float/anchored check combinations
2096 for my $re ("xx.*$c", "x.*$c$c", "$c.*xx", "$c$c.*x",
2097 "xx.*(?=$c)", "(?=$c).*xx",) {
2099 ok +($subst = "xxx") !~ s/$re//;
2101 for my $re ("xx.*$c*", "$c*.*xx") {
2103 ok +($subst = "xxx") =~ s/$re//;
2106 for my $re ("xxy*", "y*xx") {
2108 ok +($subst = "xx$c") =~ s/$re//;
2111 ok +($subst = "xy$c") !~ s/$re//;
2113 for my $re ("xy$c*z", "x$c*yz") {
2115 ok +($subst = "xyz") =~ s/$re//;
2122 local $Message = "qr /.../x";
2123 my $R = qr / A B C # D E/x;
2124 ok "ABCDE" =~ $R && $& eq "ABC";
2125 ok "ABCDE" =~ /$R/ && $& eq "ABC";
2126 ok "ABCDE" =~ m/$R/ && $& eq "ABC";
2127 ok "ABCDE" =~ /($R)/ && $1 eq "ABC";
2128 ok "ABCDE" =~ m/($R)/ && $1 eq "ABC";
2133 local $BugId = "20020412.005";
2134 local $Message = "Correct pmop flags checked when empty pattern";
2136 # Requires reuse of last successful pattern.
2141 ok $match != $_, $Message,
2142 sprintf "'match one' %s on %s iteration" =>
2143 $match ? 'succeeded' : 'failed',
2144 $_ ? 'second' : 'first';
2147 my $result = join "" => $num =~ //g;
2153 local $BugId = '20020630.002';
2154 local $Message = 'UTF-8 regex matches above 32k';
2155 for (['byte', "\x{ff}"], ['utf8', "\x{1ff}"]) {
2156 my ($type, $char) = @$_;
2157 for my $len (32000, 32768, 33000) {
2158 my $s = $char . "f" x $len;
2159 my $r = $s =~ /$char([f]*)/gc;
2160 ok $r, $Message, "<$type x $len>";
2161 ok !$r || pos ($s) == $len + 1, $Message,
2162 "<$type x $len>; pos = @{[pos $s]}";
2169 our $a = bless qr /foo/ => 'Foo';
2170 ok 'goodfood' =~ $a, "Reblessed qr // matches";
2171 iseq $a, '(?-xism:foo)', "Reblessed qr // stringifies";
2173 my $z = my $y = "\317\276"; # Byte representation of $x
2175 ok $x =~ $a, "UTF-8 interpolation in qr //";
2176 ok "a$a" =~ $x, "Stringified qr // preserves UTF-8";
2177 ok "a$x" =~ /^a$a\z/, "Interpolated qr // preserves UTF-8";
2178 ok "a$x" =~ /^a(??{$a})\z/,
2179 "Postponed interpolation of qr // preserves UTF-8";
2181 local $BugId = '17776';
2182 iseq length qr /##/x, 12, "## in qr // doesn't corrupt memory";
2186 ok "$x$x" =~ /^$x(??{$x})\z/,
2187 "Postponed UTF-8 string in UTF-8 re matches UTF-8";
2188 ok "$y$x" =~ /^$y(??{$x})\z/,
2189 "Postponed UTF-8 string in non-UTF-8 re matches UTF-8";
2190 ok "$y$x" !~ /^$y(??{$y})\z/,
2191 "Postponed non-UTF-8 string in non-UTF-8 re doesn't match UTF-8";
2192 ok "$x$x" !~ /^$x(??{$y})\z/,
2193 "Postponed non-UTF-8 string in UTF-8 re doesn't match UTF-8";
2194 ok "$y$y" =~ /^$y(??{$y})\z/,
2195 "Postponed non-UTF-8 string in non-UTF-8 re matches non-UTF8";
2196 ok "$x$y" =~ /^$x(??{$y})\z/,
2197 "Postponed non-UTF-8 string in UTF-8 re matches non-UTF8";
2199 $y = $z; # Reset $y after upgrade.
2200 ok "$x$y" !~ /^$x(??{$x})\z/,
2201 "Postponed UTF-8 string in UTF-8 re doesn't match non-UTF-8";
2202 ok "$y$y" !~ /^$y(??{$x})\z/,
2203 "Postponed UTF-8 string in non-UTF-8 re doesn't match non-UTF-8";
2209 local $PatchId = '18179';
2210 my $s = "\x{100}" x 5;
2211 my $ok = $s =~ /(\x{100}{4})/;
2212 my ($ord, $len) = (ord $1, length $1);
2213 ok $ok && $ord == 0x100 && $len == 4, "No panic: end_shift";
2218 local $BugId = '15763';
2219 our $a = "x\x{100}";
2220 chop $a; # Leaves the UTF-8 flag
2221 $a .= "y"; # 1 byte before 'y'.
2223 ok $a =~ /^\C/, 'match one \C on 1-byte UTF-8';
2224 ok $a =~ /^\C{1}/, 'match \C{1}';
2226 ok $a =~ /^\Cy/, 'match \Cy';
2227 ok $a =~ /^\C{1}y/, 'match \C{1}y';
2229 ok $a !~ /^\C\Cy/, q {don't match two \Cy};
2230 ok $a !~ /^\C{2}y/, q {don't match \C{2}y};
2232 $a = "\x{100}y"; # 2 bytes before "y"
2234 ok $a =~ /^\C/, 'match one \C on 2-byte UTF-8';
2235 ok $a =~ /^\C{1}/, 'match \C{1}';
2236 ok $a =~ /^\C\C/, 'match two \C';
2237 ok $a =~ /^\C{2}/, 'match \C{2}';
2239 ok $a =~ /^\C\C\C/, 'match three \C on 2-byte UTF-8 and a byte';
2240 ok $a =~ /^\C{3}/, 'match \C{3}';
2242 ok $a =~ /^\C\Cy/, 'match two \C';
2243 ok $a =~ /^\C{2}y/, 'match \C{2}';
2245 ok $a !~ /^\C\C\Cy/, q {don't match three \Cy};
2246 ok $a !~ /^\C{2}\Cy/, q {don't match \C{2}\Cy};
2247 ok $a !~ /^\C{3}y/, q {don't match \C{3}y};
2249 $a = "\x{1000}y"; # 3 bytes before "y"
2251 ok $a =~ /^\C/, 'match one \C on three-byte UTF-8';
2252 ok $a =~ /^\C{1}/, 'match \C{1}';
2253 ok $a =~ /^\C\C/, 'match two \C';
2254 ok $a =~ /^\C{2}/, 'match \C{2}';
2255 ok $a =~ /^\C\C\C/, 'match three \C';
2256 ok $a =~ /^\C{3}/, 'match \C{3}';
2258 ok $a =~ /^\C\C\C\C/, 'match four \C on three-byte UTF-8 and a byte';
2259 ok $a =~ /^\C{4}/, 'match \C{4}';
2261 ok $a =~ /^\C\C\Cy/, 'match three \Cy';
2262 ok $a =~ /^\C{3}y/, 'match \C{3}y';
2264 ok $a !~ /^\C\C\C\Cy/, q {don't match four \Cy};
2265 ok $a !~ /^\C{4}y/, q {don't match \C{4}y};
2272 utf8::upgrade($_); chop $_; $\="\n";
2273 ok /[^\s]+/, 'm/[^\s]/ utf8';
2274 ok /[^\d]+/, 'm/[^\d]/ utf8';
2275 ok +($a = $_, $_ =~ s/[^\s]+/./g), 's/[^\s]/ utf8';
2276 ok +($a = $_, $a =~ s/[^\d]+/./g), 's/[^\s]/ utf8';
2281 local $BugId = '15397';
2282 local $Message = 'UTF-8 matching';
2283 ok "\x{100}" =~ /\x{100}/;
2284 ok "\x{100}" =~ /(\x{100})/;
2285 ok "\x{100}" =~ /(\x{100}){1}/;
2286 ok "\x{100}\x{100}" =~ /(\x{100}){2}/;
2287 ok "\x{100}\x{100}" =~ /(\x{100})(\x{100})/;
2292 local $BugId = '7471';
2293 local $Message = 'Neither ()* nor ()*? sets $1 when matched 0 times';
2295 ok /(AB)*?CD/ && !defined $1;
2296 ok /(AB)*CD/ && !defined $1;
2301 local $BugId = '3547';
2302 local $Message = "Caching shouldn't prevent match";
2303 my $pattern = "^(b+?|a){1,2}c";
2304 ok "bac" =~ /$pattern/ && $1 eq 'a';
2305 ok "bbac" =~ /$pattern/ && $1 eq 'a';
2306 ok "bbbac" =~ /$pattern/ && $1 eq 'a';
2307 ok "bbbbac" =~ /$pattern/ && $1 eq 'a';
2313 local $BugId = '18232';
2314 local $Message = '$1 should keep UTF-8 ness';
2315 ok "\x{100}" =~ /(.)/;
2316 iseq $1, "\x{100}", '$1 is UTF-8';
2318 iseq $1, "\x{100}", '$1 is still UTF-8';
2319 isneq $1, "\xC4\x80", '$1 is not non-UTF-8';
2324 local $BugId = '19767';
2325 local $Message = "Optimizer doesn't prematurely reject match";
2328 my $attr = 'Name-1';
2329 my $NormalChar = qr /[\p{IsDigit}\p{IsLower}\p{IsUpper}]/;
2330 my $NormalWord = qr /${NormalChar}+?/;
2331 my $PredNameHyphen = qr /^${NormalWord}(\-${NormalWord})*?$/;
2334 ok $attr =~ $PredNameHyphen; # Original test.
2337 ok "0" =~ /\p{N}+\z/; # Variant.
2342 local $BugId = '20683';
2343 local $Message = "(??{ }) doesn't return stale values";
2345 foreach (1, 2, 3, 4) {
2346 $p ++ if /(??{ $p })/
2353 sub TIESCALAR {bless []}
2357 foreach (1, 2, 3, 4) {
2365 # Subject: Odd regexp behavior
2366 # From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
2367 # Date: Wed, 26 Feb 2003 16:53:12 +0000
2368 # Message-Id: <E18o4nw-0008Ly-00@wisbech.cl.cam.ac.uk>
2369 # To: perl-unicode@perl.org
2371 local $Message = 'Markus Kuhn 2003-02-26';
2373 my $x = "\x{2019}\nk";
2374 ok $x =~ s/(\S)\n(\S)/$1 $2/sg;
2375 ok $x eq "\x{2019} k";
2378 ok $x =~ s/(\S)\n(\S)/$1 $2/sg;
2381 ok "\x{2019}" =~ /\S/;
2386 local $BugId = '21411';
2387 local $Message = "(??{ .. }) in split doesn't corrupt its stack";
2389 ok '-1-3-5-' eq join '', split /((??{$i++}))/, '-1-3-5-';
2390 no warnings 'deprecated', 'syntax';
2391 split /(?{'WOW'})/, 'abc';
2398 # XXX DAPM 13-Apr-06. Recursive split is still broken. It's only luck it
2399 # hasn't been crashing. Disable this test until it is fixed properly.
2400 # XXX also check what it returns rather than just doing ok(1,...)
2401 # split /(?{ split "" })/, "abc";
2402 local $TODO = "Recursive split is still broken";
2403 ok 0, 'cache_re & "(?{": it dumps core in 5.6.1 & 5.8.0';
2408 ok "\x{100}\n" =~ /\x{100}\n$/, "UTF-8 length cache and fbm_compile";
2414 use overload q /""/ => sub {${$_ [0]};};
2415 sub new {my ($c, $v) = @_; bless \$v, $c;}
2418 $_ = Str -> new ("a\x{100}/\x{100}b");
2419 ok join (":", /\b(.)\x{100}/g) eq "a:/", "re_intuit_start and PL_bostr";
2424 local $BugId = '17757';
2425 $_ = "code: 'x' { '...' }\n"; study;
2426 my @x; push @x, $& while m/'[^\']*'/gx;
2428 iseq "@x", "'x':'...'", "Parse::RecDescent triggered infinite loop";
2433 my $re = qq /^([^X]*)X/;
2434 utf8::upgrade ($re);
2435 ok "\x{100}X" =~ /$re/, "S_cl_and ANYOF_UNICODE & ANYOF_INVERTED";
2440 local $BugId = '22354';
2442 ok "a\nb" !~ /^b/, "Propagated modifier; $_[0]";
2443 ok "a\nb" =~ /^b/m, "Propagated modifier; $_[0] - with /m";
2446 $_ = "x"; s/x/func "in subst"/e;
2447 $_ = "x"; s/x/func "in multiline subst"/em;
2450 # Next two give 'panic: malloc'.
2451 # Outcommented, using two TODOs.
2453 local $TODO = 'panic: malloc';
2454 local $Message = 'Postponed regexp and propaged modifier';
2457 skip "panic: malloc", 2;
2458 $_ = "x"; /x(?{func "in regexp"})/;
2459 $_ = "x"; /x(?{func "in multiline regexp"})/m;
2465 local $BugId = '19049';
2468 iseq "abcde", $`, 'Global match sets $`';
2473 ok "123\x{100}" =~ /^.*1.*23\x{100}$/,
2474 'UTF-8 + multiple floating substr';
2479 local $Message = '<20030808193656.5109.1@llama.ni-s.u-net.com>';
2481 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
2482 ok " \x{101}" =~ qr/\x{100}/i;
2484 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
2485 ok " \x{1E01}" =~ qr/\x{1E00}/i;
2487 # DESERET SMALL/CAPITAL LETTER LONG I
2488 ok " \x{10428}" =~ qr/\x{10400}/i;
2490 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
2491 ok " \x{1E01}x" =~ qr/\x{1E00}X/i;
2496 # [perl #23769] Unicode regex broken on simple example
2497 # regrepeat() didn't handle UTF-8 EXACT case right.
2498 local $BugId = '23769';
2499 my $Mess = 'regrepeat() handles UTF-8 EXACT case right';
2500 local $Message = $Mess;
2502 my $s = "\x{a0}\x{a0}\x{a0}\x{100}"; chop $s;
2506 ok $s =~ /\x{a0}\x{a0}/;
2508 $Message = "$Mess (easy variant)";
2509 ok "aaa\x{100}" =~ /(a+)/;
2512 $Message = "$Mess (easy invariant)";
2513 ok "aaa\x{100} " =~ /(a+?)/;
2516 $Message = "$Mess (regrepeat variant)";
2517 ok "\xa0\xa0\xa0\x{100} " =~ /(\xa0+?)/;
2520 $Message = "$Mess (regrepeat invariant)";
2521 ok "\xa0\xa0\xa0\x{100}" =~ /(\xa0+)/;
2522 iseq $1, "\xa0\xa0\xa0";
2524 $Message = "$Mess (hard variant)";
2525 ok "\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+?)/;
2526 iseq $1, "\xa0\xa1";
2528 $Message = "$Mess (hard invariant)";
2529 ok "ababab\x{100} " =~ /((?:ab)+)/;
2532 ok "\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+)/;
2533 iseq $1, "\xa0\xa1\xa0\xa1\xa0\xa1";
2535 ok "ababab\x{100} " =~ /((?:ab)+?)/;
2538 $Message = "Don't match first byte of UTF-8 representation";
2539 ok "\xc4\xc4\xc4" !~ /(\x{100}+)/;
2540 ok "\xc4\xc4\xc4" !~ /(\x{100}+?)/;
2541 ok "\xc4\xc4\xc4" !~ /(\x{100}++)/;
2547 my $head = 'x' x $_;
2548 local $Message = q [Don't misparse \x{...} in regexp ] .
2549 q [near 127 char EXACT limit];
2550 for my $tail ('\x{0061}', '\x{1234}', '\x61') {
2551 eval_ok qq ["$head$tail" =~ /$head$tail/];
2553 local $Message = q [Don't misparse \N{...} in regexp ] .
2554 q [near 127 char EXACT limit];
2555 for my $tail ('\N{SNOWFLAKE}') {
2556 eval_ok qq [use charnames ':full';
2557 "$head$tail" =~ /$head$tail/];
2564 # perl panic: pp_match start/end pointers
2565 local $BugId = '25269';
2566 iseq "a-bc", eval {my ($x, $y) = "bca" =~ /^(?=.*(a)).*(bc)/; "$x-$y"},
2567 'Captures can move backwards in string';
2572 local $BugId = '27940'; # \cA not recognized in character classes
2573 ok "a\cAb" =~ /\cA/, '\cA in pattern';
2574 ok "a\cAb" =~ /[\cA]/, '\cA in character class';
2575 ok "a\cAb" =~ /[\cA-\cB]/, '\cA in character class range';
2576 ok "abc" =~ /[^\cA-\cB]/, '\cA in negated character class range';
2577 ok "a\cBb" =~ /[\cA-\cC]/, '\cB in character class range';
2578 ok "a\cCbc" =~ /[^\cA-\cB]/, '\cC in negated character class range';
2579 ok "a\cAb" =~ /(??{"\cA"})/, '\cA in ??{} pattern';
2580 ok "ab" !~ /a\cIb/x, '\cI in pattern';
2585 # perl #28532: optional zero-width match at end of string is ignored
2586 local $BugId = '28532';
2587 ok "abc" =~ /^abc(\z)?/ && defined($1),
2588 'Optional zero-width match at end of string';
2589 ok "abc" =~ /^abc(\z)??/ && !defined($1),
2590 'Optional zero-width match at end of string';
2597 "words" =~ /(word|word|word)(?{push @got, $1})s$/;
2598 iseq @got, 1, "TRIE optimation";
2601 "words" =~ /(word|word|word)(?{push @got,$1})s$/i;
2602 iseq @got, 1,"TRIEF optimisation";
2604 my @nums = map {int rand 1000} 1 .. 100;
2605 my $re = "(" . (join "|", @nums) . ")";
2609 ok $_ =~ /$re/, "Trie nums";
2612 $_ = join " ", @nums;
2614 push @got, $1 while /$re/g;
2617 $count {$_} ++ for @got;
2620 $ok = 0 if --$count {$_} < 0;
2622 ok $ok, "Trie min count matches";
2628 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
2629 ok "foba \x{101}foo" =~ qr/(foo|\x{100}foo|bar)/i &&
2631 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH MACRON";
2633 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
2634 ok "foba \x{1E01}foo" =~ qr/(foo|\x{1E00}foo|bar)/i &&
2635 $1 eq "\x{1E01}foo",
2636 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW";
2638 # DESERET SMALL/CAPITAL LETTER LONG I
2639 ok "foba \x{10428}foo" =~ qr/(foo|\x{10400}foo|bar)/i &&
2640 $1 eq "\x{10428}foo",
2641 "TRIEF + DESERET SMALL/CAPITAL LETTER LONG I";
2643 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
2644 ok "foba \x{1E01}xfoo" =~ qr/(foo|\x{1E00}Xfoo|bar)/i &&
2645 $1 eq "\x{1E01}xfoo",
2646 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'";
2648 use charnames ':full';
2650 my $s = "\N{LATIN SMALL LETTER SHARP S}";
2651 ok "foba ba$s" =~ qr/(foo|Ba$s|bar)/i && $1 eq "ba$s",
2652 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
2653 ok "foba ba$s" =~ qr/(Ba$s|foo|bar)/i && $1 eq "ba$s",
2654 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
2655 ok "foba ba$s" =~ qr/(foo|bar|Ba$s)/i && $1 eq "ba$s",
2656 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
2658 ok "foba ba$s" =~ qr/(foo|Bass|bar)/i && $1 eq "ba$s",
2659 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss";
2661 ok "foba ba$s" =~ qr/(foo|BaSS|bar)/i && $1 eq "ba$s",
2662 "TRIEF + LATIN SMALL LETTER SHARP S =~ SS";
2664 ok "foba ba${s}pxySS$s$s" =~ qr/(b(?:a${s}t|a${s}f|a${s}p)[xy]+$s*)/i
2665 && $1 eq "ba${s}pxySS$s$s",
2666 "COMMON PREFIX TRIEF + LATIN SMALL LETTER SHARP S";
2672 print "# Set PERL_SKIP_PSYCHO_TEST to skip this test\n";
2673 my @normal = qw [the are some normal words];
2675 skip "Skipped Psycho", 2 * @normal if $ENV {PERL_SKIP_PSYCHO_TEST};
2679 my @psycho = (@normal, map chr $_, 255 .. 20000);
2680 my $psycho1 = "@psycho";
2681 for (my $i = @psycho; -- $i;) {
2682 my $j = int rand (1 + $i);
2683 @psycho [$i, $j] = @psycho [$j, $i];
2685 my $psycho2 = "@psycho";
2687 foreach my $word (@normal) {
2688 ok $word =~ /($psycho1)/ && $1 eq $word, 'Psycho';
2689 ok $word =~ /($psycho2)/ && $1 eq $word, 'Psycho';
2695 local $BugId = '36207';
2696 my $utf8 = "\xe9\x{100}"; chop $utf8;
2697 my $latin1 = "\xe9";
2699 ok $utf8 =~ /\xe9/i, "utf8/latin";
2700 ok $utf8 =~ /$latin1/i, "utf8/latin runtime";
2701 ok $utf8 =~ /(abc|\xe9)/i, "utf8/latin trie";
2702 ok $utf8 =~ /(abc|$latin1)/i, "utf8/latin trie runtime";
2704 ok "\xe9" =~ /$utf8/i, "latin/utf8";
2705 ok "\xe9" =~ /(abc|$utf8)/i, "latin/utf8 trie";
2706 ok $latin1 =~ /$utf8/i, "latin/utf8 runtime";
2707 ok $latin1 =~ /(abc|$utf8)/i, "latin/utf8 trie runtime";
2712 local $BugId = '37038';
2718 "Assigning to original string does not corrupt match vars";
2727 my $aeek = bless {} => 'wooosh';
2728 eval_ok sub {$aeek -> gloople () =~ /(.)/g},
2729 "//g match against return value of sub";
2732 eval_ok sub {gloople () =~ /(.)/g},
2733 "26410 didn't affect sub calls for some reason";
2738 local $TODO = "See changes 26925-26928, which reverted change 26410";
2742 sub variable : lvalue {$var}
2744 my $o = bless [] => 'lv';
2748 $f .= $1 if $o -> variable =~ /(.)/g;
2753 iseq $f, "ab", "pos() retained between calls";
2757 ok 0, "Code failed: $@";
2761 sub variable : lvalue {$var}
2765 $g .= $1 if variable =~ /(.)/g;
2770 iseq $g, "ab", "pos() retained between calls";
2774 ok 0, "Code failed: $@";
2781 local $BugId = '37836';
2782 skip "In EBCDIC" if $IS_EBCDIC;
2784 $_ = pack 'U0C2', 0xa2, 0xf8; # Ill-formed UTF-8
2786 eval_ok sub {!($ret = s/[\0]+//g)},
2787 "Ill-formed UTF-8 doesn't match NUL in class";
2792 # chr(65535) should be allowed in regexes
2793 local $BugId = '38293';
2794 no warnings 'utf8'; # To allow non-characters
2799 ok $c eq "", "U+FFFF, parsed as atom";
2804 ok $c eq "", "U+FFFF backslashed, parsed as atom";
2808 ok $c eq "", "U+FFFF, parsed in class";
2813 ok $c eq "", "U+FFFF backslashed, parsed in class";
2816 $s =~ s/\x{ffff}//i;
2817 ok $s eq "AB", "U+FFFF, EXACTF";
2821 ok $s eq "\x{ffff}", "U+FFFF, BOUND";
2825 ok $s eq "\x{ffff}", "U+FFFF, NBOUND";
2830 local $BugId = '39583';
2832 # The printing characters
2833 my @chars = ("A" .. "Z");
2835 my $size = 32771 - 4;
2838 # Create some random junk. Inefficient, but it works.
2839 for (my $i = 0; $i < $size; $ i++) {
2840 $str .= $chars [rand @chars];
2843 $str .= ($delim x 4);
2846 ok $str =~ s/^(.*?)${delim}{4}//s, "Pattern matches";
2847 iseq $str, "", "Empty string";
2848 ok defined $1 && length ($1) == $size, '$1 is correct size';
2853 local $BugId = '27940';
2854 ok "\0-A" =~ /\c@-A/, '@- should not be interpolated in a pattern';
2855 ok "\0\0A" =~ /\c@+A/, '@+ should not be interpolated in a pattern';
2856 ok "X\@-A" =~ /X@-A/, '@- should not be interpolated in a pattern';
2857 ok "X\@\@A" =~ /X@+A/, '@+ should not be interpolated in a pattern';
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@)A/, '\c@)';
2863 ok "X\0A" =~ /X\c@|ZA/, '\c@|';
2865 ok "X\@A" =~ /X@?A/, '@?';
2866 ok "X\@A" =~ /X@*A/, '@*';
2867 ok "X\@A" =~ /X@(A)/, '@(';
2868 ok "X\@A" =~ /X(@)A/, '@)';
2869 ok "X\@A" =~ /X@|ZA/, '@|';
2871 local $" = ','; # non-whitespace and non-RE-specific
2872 ok 'abc' =~ /(.)(.)(.)/, 'The last successful match is bogus';
2873 ok "A@+B" =~ /A@{+}B/, 'Interpolation of @+ in /@{+}/';
2874 ok "A@-B" =~ /A@{-}B/, 'Interpolation of @- in /@{-}/';
2875 ok "A@+B" =~ /A@{+}B/x, 'Interpolation of @+ in /@{+}/x';
2876 ok "A@-B" =~ /A@{-}B/x, 'Interpolation of @- in /@{-}/x';
2884 ok 'fooB' =~ /\N{foo}[\N{B}\N{b}]/, "Passthrough charname";
2887 # Why doesn't must_warn work here?
2890 local $SIG {__WARN__} = sub {$w .= "@_"};
2891 eval 'q(xxWxx) =~ /[\N{WARN}]/';
2892 ok $w && $w =~ /^Ignoring excess chars from/,
2893 "Ignoring excess chars warning";
2896 eval q [ok "\0" !~ /[\N{EMPTY-STR}XY]/,
2897 "Zerolength charname in charclass doesn't match \\0"];
2898 ok $w && $w =~ /^Ignoring zero length/,
2899 'Ignoring zero length \N{%} in character class warning';
2901 ok 'AB' =~ /(\N{EVIL})/ && $1 eq 'A', 'Charname caching $1';
2902 ok 'ABC' =~ /(\N{EVIL})/, 'Charname caching $1';
2903 ok 'xy' =~ /x\N{EMPTY-STR}y/,
2904 'Empty string charname produces NOTHING node';
2905 ok '' =~ /\N{EMPTY-STR}/,
2906 'Empty string charname produces NOTHING node';
2912 use charnames ':full';
2914 ok 'aabc' !~ /a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against aabc';
2915 ok 'a+bc' =~ /a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against a+bc';
2917 ok ' A B' =~ /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
2918 'Intermixed named and unicode escapes';
2919 ok "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}" =~
2920 /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
2921 'Intermixed named and unicode escapes';
2922 ok "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}" =~
2923 /[\N{SPACE}\N{U+0041}][\N{SPACE}\N{U+0042}]/,
2924 'Intermixed named and unicode escapes';
2931 { (?> [^{}]+ | (??{ $brackets }) )* }
2934 ok "{b{c}d" !~ m/^((??{ $brackets }))/, "Bracket mismatch";
2946 <<stuff1>and<stuff2>><<<<right>>>>
2949 local $_ = '<<<stuff1>and<stuff2>><<<<right>>>>>';
2950 ok /^(<((?:(?>[^<>]+)|(?1))*)>(?{push @stack, $2 }))$/,
2951 "Recursion matches";
2952 iseq @stack, @expect, "Right amount of matches"
2953 or skip "Won't test individual results as count isn't equal",
2956 foreach my $expect (@expect) {
2957 iseq $stack [$idx], $expect,
2958 "Expecting '$expect' at stack pos #$idx";
2966 my $s = '123453456';
2967 $s =~ s/(?<digits>\d+)\k<digits>/$+{digits}/;
2968 ok $s eq '123456', 'Named capture (angle brackets) s///';
2970 $s =~ s/(?'digits'\d+)\k'digits'/$+{digits}/;
2971 ok $s eq '123456', 'Named capture (single quotes) s///';
2977 pack('U', 0x00F1), # n-tilde
2978 '_'.pack('U', 0x00F1), # _ + n-tilde
2979 'c'.pack('U', 0x0327), # c + cedilla
2980 pack('U*', 0x00F1, 0x0327), # n-tilde + cedilla
2981 'a'.pack('U', 0x00B2), # a + superscript two
2982 pack('U', 0x0391), # ALPHA
2983 pack('U', 0x0391).'2', # ALPHA + 2
2984 pack('U', 0x0391).'_', # ALPHA + _
2987 for my $uni (@ary) {
2988 my ($r1, $c1, $r2, $c2) = eval qq {
2990 scalar ("..foo foo.." =~ /(?'${uni}'foo) \\k'${uni}'/),
2992 scalar ("..bar bar.." =~ /(?<${uni}>bar) \\k<${uni}>/),
2995 ok $r1, "Named capture UTF (?'')";
2996 ok defined $c1 && $c1 eq 'foo', "Named capture UTF \%+";
2997 ok $r2, "Named capture UTF (?<>)";
2998 ok defined $c2 && $c2 eq 'bar', "Named capture UTF \%+";
3004 my $s = 'foo bar baz';
3005 my (@k, @v, @fetch, $res);
3007 my @names = qw ($+{A} $+{B} $+{C});
3008 if ($s =~ /(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz)/) {
3009 while (my ($k, $v) = each (%+)) {
3012 @k = sort keys (%+);
3013 @v = sort values (%+);
3023 iseq $fetch [$_] [0], $fetch [$_] [1], $names [$_];
3028 iseq $res, 1, "'$s' =~ /(?<A>foo)\\s+(?<B>bar)?\\s+(?<C>baz)/";
3029 iseq $count, 3, "Got 3 keys in %+ via each";
3030 iseq 0 + @k, 3, 'Got 3 keys in %+ via keys';
3031 iseq "@k", "A B C", "Got expected keys";
3032 iseq "@v", "bar baz foo", "Got expected values";
3034 no warnings "uninitialized";
3035 print for $+ {this_key_doesnt_exist};
3037 ok !$@, 'lvalue $+ {...} should not throw an exception';
3043 # Almost the same as the block above, except that the capture is nested.
3045 local $BugId = '50496';
3046 my $s = 'foo bar baz';
3047 my (@k, @v, @fetch, $res);
3049 my @names = qw ($+{A} $+{B} $+{C} $+{D});
3050 if ($s =~ /(?<D>(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz))/) {
3051 while (my ($k,$v) = each(%+)) {
3054 @k = sort keys (%+);
3055 @v = sort values (%+);
3066 iseq $fetch [$_] [0], $fetch [$_] [1], $names [$_];
3071 iseq $res, 1, "'$s' =~ /(?<D>(?<A>foo)\\s+(?<B>bar)?\\s+(?<C>baz))/";
3072 iseq $count, 4, "Got 4 keys in %+ via each";
3073 iseq @k, 4, 'Got 4 keys in %+ via keys';
3074 iseq "@k", "A B C D", "Got expected keys";
3075 iseq "@v", "bar baz foo foo bar baz", "Got expected values";
3077 no warnings "uninitialized";
3078 print for $+ {this_key_doesnt_exist};
3080 ok !$@,'lvalue $+ {...} should not throw an exception';
3085 my $s = 'foo bar baz';
3087 if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) {
3088 foreach my $name (sort keys(%-)) {
3089 my $ary = $- {$name};
3090 foreach my $idx (0 .. $#$ary) {
3091 push @res, "$name:$idx:$ary->[$idx]";
3095 my @expect = qw (A:0:1 A:1:3 B:0:2 B:1:4);
3096 iseq "@res", "@expect", "Check %-";
3098 no warnings "uninitialized";
3099 print for $- {this_key_doesnt_exist};
3101 ok !$@,'lvalue $- {...} should not throw an exception';
3107 # stress test CURLYX/WHILEM.
3109 # This test includes varying levels of nesting, and according to
3110 # profiling done against build 28905, exercises every code line in the
3111 # CURLYX and WHILEM blocks, except those related to LONGJMP, the
3112 # super-linear cache and warnings. It executes about 0.5M regexes
3114 skip "No psycho tests" if $ENV {PERL_SKIP_PSYCHO_TEST};
3115 print "# Set PERL_SKIP_PSYCHO_TEST to skip this test\n";
3150 my $msg = "CURLYX stress test";
3152 for my $a ("x","a","aa") {
3153 for my $b ("x","bbb","bbbb") {
3155 for my $c ("x","c","cc") {
3157 for my $d ("x","d","dd") {
3159 for my $e ("x","e","ee") {
3161 for my $f ("x","f","ff") {
3163 for my $g ("x","g","gg") {
3165 for my $h ("x","h","hh") {
3167 for my $i ("x","i","ii") {
3169 for my $j ("x","j","jj") {
3171 for my $k ("x","k","kk") {
3173 for my $l ("x","l","ll") {
3177 $msg .= ": unexpected match for [$ls]";
3181 my $cap = "$1$2$3$4$5$6$7$8$9$10$11$12";
3182 unless ($ls eq $cap) {
3183 $msg .= ": capture: [$ls], got [$cap]";
3189 unless ($ls =~ /x/) {
3190 $msg = ": failed for [$ls]";
3213 ok "xaaay" !~ /xa{3\,4}y/, '\, in a pattern';
3214 ok "xa{3,4}y" =~ /xa{3\,4}y/, '\, in a pattern';
3217 ok "x\c_y" !~ /x\c\_y/, '\_ in a pattern';
3218 ok "x\c\_y" =~ /x\c\_y/, '\_ in a pattern';
3220 # \c\ followed by other characters
3221 for my $c ("z", "\0", "!", chr(254), chr(256)) {
3222 my $targ = "a\034$c";
3223 my $reg = "a\\c\\$c";
3224 ok eval ("qq/$targ/ =~ /$reg/"), "\\c\\ in pattern";
3230 local $BugId = '36046';
3235 while ($str =~ /b/g) {$mval = $#-; $pval = $#+; $count ++}
3236 iseq $mval, 0, '@- should be empty';
3237 iseq $pval, 0, '@+ should be empty';
3238 iseq $count, 1, 'Should have matched once only';
3242 { # Test the (*PRUNE) pattern
3244 'aaab' =~ /a+b?(?{$count++})(*FAIL)/;
3245 iseq $count, 9, "Expect 9 for no (*PRUNE)";
3247 'aaab' =~ /a+b?(*PRUNE)(?{$count++})(*FAIL)/;
3248 iseq $count, 3, "Expect 3 with (*PRUNE)";
3251 1 while /.(*PRUNE)(?{$count++})(*FAIL)/g;
3252 iseq $count, 4, "/.(*PRUNE)/";
3254 'aaab' =~ /a+b?(??{'(*PRUNE)'})(?{$count++})(*FAIL)/;
3255 iseq $count, 3, "Expect 3 with (*PRUNE)";
3258 1 while /.(??{'(*PRUNE)'})(?{$count++})(*FAIL)/g;
3259 iseq $count, 4, "/.(*PRUNE)/";
3263 { # Test the (*SKIP) pattern
3265 'aaab' =~ /a+b?(*SKIP)(?{$count++})(*FAIL)/;
3266 iseq $count, 1, "Expect 1 with (*SKIP)";
3269 1 while /.(*SKIP)(?{$count++})(*FAIL)/g;
3270 iseq $count, 4, "/.(*SKIP)/";
3274 1 while /(a+b?)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
3275 iseq $count, 2, "Expect 2 with (*SKIP)";
3276 iseq "@res", "aaab aaab", "Adjacent (*SKIP) works as expected";
3280 { # Test the (*SKIP) pattern
3282 'aaab' =~ /a+b?(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/;
3283 iseq $count, 1, "Expect 1 with (*SKIP)";
3286 1 while /.(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/g;
3287 iseq $count, 4, "/.(*SKIP)/";
3291 1 while /(a+b?)(*MARK:foo)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
3292 iseq $count, 2, "Expect 2 with (*SKIP)";
3293 iseq "@res", "aaab aaab", "Adjacent (*SKIP) works as expected";
3297 { # Test the (*SKIP) pattern
3299 'aaab' =~ /a*(*MARK:a)b?(*MARK:b)(*SKIP:a)(?{$count++})(*FAIL)/;
3300 iseq $count, 3, "Expect 3 with *MARK:a)b?(*MARK:b)(*SKIP:a)";
3301 local $_ = 'aaabaaab';
3305 /(a*(*MARK:a)b?)(*MARK:x)(*SKIP:a)(?{$count++; push @res,$1})(*FAIL)/g;
3306 iseq $count, 5, "Expect 5 with (*MARK:a)b?)(*MARK:x)(*SKIP:a)";
3307 iseq "@res", "aaab b aaab b ",
3308 "Adjacent (*MARK:a)b?)(*MARK:x)(*SKIP:a) works as expected";
3312 { # Test the (*COMMIT) pattern
3314 'aaabaaab' =~ /a+b?(*COMMIT)(?{$count++})(*FAIL)/;
3315 iseq $count, 1, "Expect 1 with (*COMMIT)";
3318 1 while /.(*COMMIT)(?{$count++})(*FAIL)/g;
3319 iseq $count, 1, "/.(*COMMIT)/";
3323 1 while /(a+b?)(*COMMIT)(?{$count++; push @res,$1})(*FAIL)/g;
3324 iseq $count, 1, "Expect 1 with (*COMMIT)";
3325 iseq "@res", "aaab", "Adjacent (*COMMIT) works as expected";
3330 # Test named commits and the $REGERROR var
3332 for my $name ('', ':foo') {
3333 for my $pat ("(*PRUNE$name)",
3334 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)",
3336 for my $suffix ('(*FAIL)', '') {
3337 'aaaab' =~ /a+b$pat$suffix/;
3339 ($suffix ? ($name ? 'foo' : "1") : ""),
3340 "Test $pat and \$REGERROR $suffix";
3348 # Test named commits and the $REGERROR var
3351 for my $name ('', ':foo') {
3352 for my $pat ("(*PRUNE$name)",
3353 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)",
3355 for my $suffix ('(*FAIL)','') {
3356 'aaaab' =~ /a+b$pat$suffix/;
3358 ($suffix ? ($name ? 'foo' : "1") : ""),
3359 "Test $pat and \$REGERROR $suffix";
3367 # Test named commits and the $REGERROR var
3368 local $Message = '$REGERROR';
3370 for my $word (qw (bar baz bop)) {
3373 /a+(?:bar(*COMMIT:bar)|baz(*COMMIT:baz)|bop(*COMMIT:bop))(*FAIL)/;
3374 iseq $REGERROR, $word;
3380 local $BugId = '40684';
3381 local $Message = '/m in precompiled regexp';
3383 my $rex = qr'^abc$'m;
3390 #Mindnumbingly simple test of (*THEN)
3392 ok /A (*THEN) X | B (*THEN) C/x, "Simple (*THEN) test";
3398 local $Message = "Relative Recursion";
3399 my $parens = qr/(\((?:[^()]++|(?-1))*+\))/;
3400 local $_ = 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))';
3401 my ($all, $one, $two) = ('', '', '');
3402 ok /foo $parens \s* \+ \s* bar $parens/x;
3403 iseq $1, '((2*3)+4-3)';
3404 iseq $2, '(2*(3+4)-1*(2-3))';
3405 iseq $&, 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))';
3411 local $_ = join 'bar', $spaces, $spaces;
3413 s/(?>\s+bar)(?{$count++})//g;
3414 iseq $_, $spaces, "SUSPEND final string";
3415 iseq $count, 1, "Optimiser should have prevented more than one match";
3419 local $BugId = '36909';
3420 local $Message = '(?: ... )? should not lose $^R';
3424 ok 'x foofoo y' =~ m {
3425 (foo) # $^R correctly set
3426 (?{ "last regexp code result" })
3428 iseq $^R, 'last regexp code result';
3430 iseq $^R, 'Nothing';
3435 ok 'x foofoo y' =~ m {
3436 (?:foo|bar)+ # $^R correctly set
3437 (?{ "last regexp code result" })
3439 iseq $^R, 'last regexp code result';
3441 iseq $^R, 'Nothing';
3445 ok 'x foofoo y' =~ m {
3446 (foo|bar)\1+ # $^R undefined
3447 (?{ "last regexp code result" })
3449 iseq $^R, 'last regexp code result';
3451 iseq $^R, 'Nothing';
3455 ok 'x foofoo y' =~ m {
3456 (foo|bar)\1 # This time without the +
3457 (?{"last regexp code result"})
3459 iseq $^R, 'last regexp code result';
3461 iseq $^R, 'Nothing';
3466 local $BugId = '22395';
3467 local $Message = 'Match is linear, not quadratic';
3469 for my $l (10, 100, 1000) {
3471 ('a' x $l) =~ /(.*)(?{$count++})[bc]/;
3472 local $TODO = "Should be L+1 not L*(L+3)/2 (L=$l)";
3473 iseq $count, $l + 1;
3479 local $BugId = '22614';
3480 local $Message = '@-/@+ should not have undefined values';
3483 /(.){1,}(?{push @len,0+@-})(.){1,}(?{})^/;
3484 iseq "@len", "2 2 2";
3489 local $BugId = '18209';
3490 local $Message = '$& set on s///';
3491 my $text = ' word1 word2 word3 word4 word5 word6 ';
3493 my @words = ('word1', 'word3', 'word5');
3495 foreach my $word (@words) {
3496 $text =~ s/$word\s//gi; # Leave a space to seperate words
3497 # in the resultant str.
3498 # The following block is not working.
3505 iseq $text, ' word2 word4 word6 ';
3511 local $BugId = '6893';
3512 local $_ = qq (A\nB\nC\n);
3514 while (m#(\G|\n)([^\n]*)\n#gsx) {
3518 iseq "@res", "A B C", "/g pattern shouldn't infinite loop";
3523 # From Message-ID: <877ixs6oa6.fsf@k75.linux.bogus>
3524 my $dow_name = "nada";
3525 my $parser = "(\$dow_name) = \$time_string =~ /(D\x{e9}\\ " .
3526 "C\x{e9}adaoin|D\x{e9}\\ Sathairn|\\w+|\x{100})/";
3527 my $time_string = "D\x{e9} C\x{e9}adaoin";
3529 ok !$@, "Test Eval worked";
3530 iseq $dow_name, $time_string, "UTF-8 trie common prefix extraction";
3536 ($v = 'bar') =~ /(\w+)/g;
3538 iseq "$1", 'bar', '$1 is safe after /g - may fail due ' .
3539 'to specialized config in pp_hot.c'
3544 local $Message = "http://nntp.perl.org/group/perl.perl5.porters/118663";
3545 my $qr_barR1 = qr/(bar)\g-1/;
3546 ok "foobarbarxyz" =~ $qr_barR1;
3547 ok "foobarbarxyz" =~ qr/foo${qr_barR1}xyz/;
3548 ok "foobarbarxyz" =~ qr/(foo)${qr_barR1}xyz/;
3549 ok "foobarbarxyz" =~ qr/(foo)(bar)\g{-1}xyz/;
3550 ok "foobarbarxyz" =~ qr/(foo${qr_barR1})xyz/;
3551 ok "foobarbarxyz" =~ qr/(foo(bar)\g{-1})xyz/;
3556 local $BugId = '41010';
3557 local $Message = 'No optimizer bug';
3558 my @tails = ('', '(?(1))', '(|)', '()?');
3559 my @quants = ('*','+');
3563 for my $pat (@$pats) {
3564 for my $quant (@quants) {
3565 for my $tail (@tails) {
3566 my $re = "($pat$quant\$)$tail";
3567 ok /$re/ && $1 eq $_, "'$_' =~ /$re/";
3568 ok /$re/m && $1 eq $_, "'$_' =~ /$re/m";
3577 '(1|[23]|4|[56]|[78]|[90])',
3578 '(?:1|[23]|4|[56]|[78]|[90])',
3579 '(1|2|3|4|5|6|7|8|9|0)',
3580 '(?:1|2|3|4|5|6|7|8|9|0)');
3581 my @spats = ('[ ]', ' ', '( |\t)', '(?: |\t)', '[ \t]', '\s');
3583 my @dstrs = ('12345');
3584 $doit -> (\@spats, @sstrs);
3585 $doit -> (\@dpats, @dstrs);
3590 local $Message = '$REGMARK';
3592 our ($REGMARK, $REGERROR);
3593 ok 'foofoo' =~ /foo (*MARK:foo) (?{push @r,$REGMARK}) /x;
3595 iseq $REGMARK, "foo";
3596 ok 'foofoo' !~ /foo (*MARK:foo) (*FAIL) /x;
3598 iseq $REGERROR, 'foo';
3603 local $Message = '\K test';
3605 $x = "abc.def.ghi.jkl";
3607 iseq $x, "abc.def.ghi";
3609 $x = "one two three four";
3610 $x =~ s/o+ \Kthree//g;
3611 iseq $x, "one two four";
3615 iseq $x, "aabbccddee";
3621 return '4' if $_[0] eq '09028623';
3623 # Nested EVAL using PL_curpm (via $1 or friends)
3625 our $grabit = qr/ ([0-6][0-9]{7}) (??{ kt $1 }) [890] /x;
3626 $re = qr/^ ( (??{ $grabit }) ) $ /x;
3627 my @res = '0902862349' =~ $re;
3628 iseq join ("-", @res), "0902862349",
3629 'PL_curpm is set properly on nested eval';
3631 our $qr = qr/ (o) (??{ $1 }) /x;
3632 ok 'boob'=~/( b (??{ $qr }) b )/x && 1, "PL_curpm, nested eval";
3637 use charnames ":full";
3638 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "I =~ Alphabetic";
3639 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Uppercase}/, "I =~ Uppercase";
3640 ok "\N{ROMAN NUMERAL ONE}" !~ /\p{Lowercase}/, "I !~ Lowercase";
3641 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "I =~ ID_Start";
3642 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "I =~ ID_Continue";
3643 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "i =~ Alphabetic";
3644 ok "\N{SMALL ROMAN NUMERAL ONE}" !~ /\p{Uppercase}/, "i !~ Uppercase";
3645 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Lowercase}/, "i =~ Lowercase";
3646 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "i =~ ID_Start";
3647 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "i =~ ID_Continue"
3652 # requirement of Unicode Technical Standard #18, 1.7 Code Points
3653 # cf. http://www.unicode.org/reports/tr18/#Supplementary_Characters
3654 for my $u (0x7FF, 0x800, 0xFFFF, 0x10000) {
3655 no warnings 'utf8'; # oops
3657 my $x = sprintf '%04X', $u;
3658 ok "A${c}B" =~ /A[\0-\x{10000}]B/, "Unicode range - $x";
3666 if ('1' =~ /(?|(?<digit>1)|(?<digit>2))/) {
3667 $res = "@{$- {digit}}";
3670 "Check that (?|...) doesnt cause dupe entries in the names array";
3673 if ('11' =~ /(?|(?<digit>1)|(?<digit>2))(?&digit)/) {
3674 $res = "@{$- {digit}}";
3676 iseq $res, "1", "Check that (?&..) to a buffer inside " .
3677 "a (?|...) goes to the leftmost";
3683 local $Message = "ASCII pattern that really is UTF-8";
3685 local $SIG {__WARN__} = sub {push @w, "@_"};
3686 my $c = qq (\x{DF});
3687 ok $c =~ /${c}|\x{100}/;
3693 local $Message = "Corruption of match results of qr// across scopes";
3694 my $qr = qr/(fo+)(ba+r)/;
3696 iseq "$1$2", "foobar";
3698 'foooooobaaaaar' =~ /$qr/;
3699 iseq "$1$2", 'foooooobaaaaar';
3701 iseq "$1$2", "foobar";
3706 local $Message = "HORIZWS";
3707 local $_ = "\t \r\n \n \t".chr(11)."\n";
3710 iseq $_, "hhHHhHhhHH";
3711 $_ = "\t \r\n \n \t" . chr (11) . "\n";
3715 iseq $_, "hhHHhHhhHH";
3720 local $Message = "Various whitespace special patterns";
3721 my @h = map {chr $_} 0x09, 0x20, 0xa0, 0x1680, 0x180e, 0x2000,
3722 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006,
3723 0x2007, 0x2008, 0x2009, 0x200a, 0x202f, 0x205f,
3725 my @v = map {chr $_} 0x0a, 0x0b, 0x0c, 0x0d, 0x85, 0x2028,
3727 my @lb = ("\x0D\x0A", map {chr $_} 0x0A .. 0x0D, 0x85, 0x2028, 0x2029);
3728 foreach my $t ([\@h, qr/\h/, qr/\h+/],
3729 [\@v, qr/\v/, qr/\v+/],
3730 [\@lb, qr/\R/, qr/\R+/],) {
3731 my $ary = shift @$t;
3732 foreach my $pat (@$t) {
3733 foreach my $str (@$ary) {
3734 ok $str =~ /($pat)/, $pat;
3735 iseq $1, $str, $pat;
3736 utf8::upgrade ($str);
3737 ok $str =~ /($pat)/, "Upgraded string - $pat";
3738 iseq $1, $str, "Upgraded string - $pat";
3746 local $Message = "Check that \\xDF match properly in its various forms";
3747 # Test that \xDF matches properly. this is pretty hacky stuff,
3748 # but its actually needed. The malarky with '-' is to prevent
3749 # compilation caching from playing any role in the test.
3750 my @df = (chr (0xDF), '-', chr (0xDF));
3751 utf8::upgrade ($df [2]);
3752 my @strs = ('ss', 'sS', 'Ss', 'SS', chr (0xDF));
3753 my @ss = map {("$_", "$_")} @strs;
3754 utf8::upgrade ($ss [$_ * 2 + 1]) for 0 .. $#strs;
3756 for my $ssi (0 .. $#ss) {
3757 for my $dfi (0 .. $#df) {
3758 my $pat = $df [$dfi];
3759 my $str = $ss [$ssi];
3760 my $utf_df = ($dfi > 1) ? 'utf8' : '';
3761 my $utf_ss = ($ssi % 2) ? 'utf8' : '';
3762 (my $sstr = $str) =~ s/\xDF/\\xDF/;
3764 if ($utf_df || $utf_ss || length ($ss [$ssi]) == 1) {
3765 my $ret = $str =~ /$pat/i;
3766 next if $pat eq '-';
3767 ok $ret, "\"$sstr\" =~ /\\xDF/i " .
3768 "(str is @{[$utf_ss||'latin']}, pat is " .
3769 "@{[$utf_df||'latin']})";
3772 my $ret = $str !~ /$pat/i;
3773 next if $pat eq '-';
3774 ok $ret, "\"$sstr\" !~ /\\xDF/i " .
3775 "(str is @{[$utf_ss||'latin']}, pat is " .
3776 "@{[$utf_df||'latin']})";
3784 local $Message = "BBC(Bleadperl Breaks CPAN) Today: String::Multibyte";
3785 my $re = qr/(?:[\x00-\xFF]{4})/;
3786 my $hyp = "\0\0\0-";
3787 my $esc = "\0\0\0\\";
3789 my $str = "$esc$hyp$hyp$esc$esc";
3790 my @a = ($str =~ /\G(?:\Q$esc$esc\E|\Q$esc$hyp\E|$re)/g);
3794 iseq "@a","$esc$hyp=$hyp=$esc$esc";
3799 # Test for keys in %+ and %-
3800 local $Message = 'Test keys in %+ and %-';
3801 no warnings 'uninitialized';
3803 /(?<foo>a)|(?<foo>b)/;
3804 iseq ((join ",", sort keys %+), "foo");
3805 iseq ((join ",", sort keys %-), "foo");
3806 iseq ((join ",", sort values %+), "a");
3807 iseq ((join ",", sort map "@$_", values %-), "a ");
3808 /(?<bar>a)(?<bar>b)(?<quux>.)/;
3809 iseq ((join ",", sort keys %+), "bar,quux");
3810 iseq ((join ",", sort keys %-), "bar,quux");
3811 iseq ((join ",", sort values %+), "a,c"); # leftmost
3812 iseq ((join ",", sort map "@$_", values %-), "a b,c");
3813 /(?<un>a)(?<deux>c)?/; # second buffer won't capture
3814 iseq ((join ",", sort keys %+), "un");
3815 iseq ((join ",", sort keys %-), "deux,un");
3816 iseq ((join ",", sort values %+), "a");
3817 iseq ((join ",", sort map "@$_", values %-), ",a");
3822 # length() on captures, the numbered ones end up in Perl_magic_len
3823 my $_ = "aoeu \xe6var ook";
3824 /^ \w+ \s (?<eek>\S+)/x;
3826 iseq length ($`), 0, q[length $`];
3827 iseq length ($'), 4, q[length $'];
3828 iseq length ($&), 9, q[length $&];
3829 iseq length ($1), 4, q[length $1];
3830 iseq length ($+{eek}), 4, q[length $+{eek} == length $1];
3837 $ok = exists ($-{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/;
3838 iseq $ok, 1, '$-{x} exists after "bar"=~/(?<x>foo)|bar/';
3839 iseq scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/';
3840 iseq scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/';
3843 $ok = exists ($+{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/;
3844 iseq $ok, 0, '$+{x} not exists after "bar"=~/(?<x>foo)|bar/';
3845 iseq scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/';
3846 iseq scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/';
3849 $ok = exists ($-{x}) ? 1 : 0 if 'foo' =~ /(?<x>foo)|bar/;
3850 iseq $ok, 1, '$-{x} exists after "foo"=~/(?<x>foo)|bar/';
3851 iseq scalar (%+), 1, 'scalar %+ == 1 after "foo"=~/(?<x>foo)|bar/';
3852 iseq scalar (%-), 1, 'scalar %- == 1 after "foo"=~/(?<x>foo)|bar/';
3855 $ok = exists ($+{x}) ? 1 : 0 if 'foo'=~/(?<x>foo)|bar/;
3856 iseq $ok, 1, '$+{x} exists after "foo"=~/(?<x>foo)|bar/';
3862 ($_ = 'abc') =~ /(abc)/g;
3864 iseq "$1", 'abc', "/g leads to unsafe match vars: $1";
3869 local $Message = 'Message-ID: <20070818091501.7eff4831@r2d2>';
3873 $str .= "@x"; # this should ALWAYS be the empty string
3877 iseq length ($str), 0, "Trie scope error, string should be empty";
3879 my @foo = ('a') x 5;
3883 s/a|/push @bar, 1/e;
3885 iseq length ($str), 0, "Trie scope error, string should be empty";
3890 local $BugId = '45605';
3891 # [perl #45605] Regexp failure with utf8-flagged and byte-flagged string
3893 my $utf_8 = "\xd6schel";
3894 utf8::upgrade ($utf_8);
3895 $utf_8 =~ m {(\xd6|Ö)schel};
3896 iseq $1, "\xd6", "Upgrade error";
3900 # more TRIE/AHOCORASICK problems with mixed utf8 / latin-1 and case folding
3901 for my $chr (160 .. 255) {
3902 my $chr_byte = chr($chr);
3903 my $chr_utf8 = chr($chr); utf8::upgrade($chr_utf8);
3904 my $rx = qr{$chr_byte|X}i;
3905 ok($chr_utf8 =~ $rx, "utf8/latin, codepoint $chr");
3910 # Regardless of utf8ness any character matches itself when
3911 # doing a case insensitive match. See also [perl #36207]
3912 local $BugId = '36207';
3913 for my $o (0 .. 255) {
3914 my @ch = (chr ($o), chr ($o));
3915 utf8::upgrade ($ch [1]);
3916 for my $u_str (0, 1) {
3917 for my $u_pat (0, 1) {
3918 ok $ch [$u_str] =~ /\Q$ch[$u_pat]\E/i,
3919 "\$c =~ /\$c/i : chr ($o) : u_str = $u_str u_pat = $u_pat";
3920 ok $ch [$u_str] =~ /\Q$ch[$u_pat]\E|xyz/i,
3921 "\$c=~/\$c|xyz/i : chr($o) : u_str = $u_str u_pat = $u_pat";
3929 our $a = 3; "" =~ /(??{ $a })/;
3931 iseq $b, $a, "Copy of scalar used for postponed subexpression";
3936 local $BugId = '49190';
3937 local $Message = '$REGMARK in replacement';
3940 ok s/(*:B)A/$REGMARK/;
3943 ok s/(*:X)A+|(*:Y)B+|(*:Z)C+/$REGMARK/g;
3964 my $match = '<bla><blubb></blubb></bla>' =~ m/^$nested_tags$/;
3965 ok $match, 'nested construct matches';
3966 iseq "@ctl_n", "bla blubb", '$^N inside of (?{}) works as expected';
3967 iseq "@plus", "bla blubb", '$+ inside of (?{}) works as expected';
3972 local $BugId = '52658';
3973 local $Message = 'Substitution evaluation in list context';
3974 my $reg = '../xxx/';
3975 my @te = ($reg =~ m{^(/?(?:\.\./)*)},
3976 $reg =~ s/(x)/'b'/eg > 1 ? '##' : '++');
3977 iseq $reg, '../bbb/';
3978 iseq $te [0], '../';
3981 # This currently has to come before any "use encoding" in this file.
3984 local $BugId = '59342';
3985 must_warn 'qr/\400/', '^Use of octal value above 377';
3990 # XXX: This set of tests is essentially broken, POSIX character classes
3991 # should not have differing definitions under Unicode.
3992 # There are property names for that.
3993 skip "Tests assume ASCII", 4 unless $IS_ASCII;
3995 my @notIsPunct = grep {/[[:punct:]]/ and not /\p{IsPunct}/}
3996 map {chr} 0x20 .. 0x7f;
3997 iseq join ('', @notIsPunct), '$+<=>^`|~',
3998 '[:punct:] disagress with IsPunct on Symbols';
4000 my @isPrint = grep {not /[[:print:]]/ and /\p{IsPrint}/}
4001 map {chr} 0 .. 0x1f, 0x7f .. 0x9f;
4002 iseq join ('', @isPrint), "\x09\x0a\x0b\x0c\x0d\x85",
4003 'IsPrint disagrees with [:print:] on control characters';
4005 my @isPunct = grep {/[[:punct:]]/ != /\p{IsPunct}/}
4006 map {chr} 0x80 .. 0xff;
4007 iseq join ('', @isPunct), "\xa1\xab\xb7\xbb\xbf", # ¡ « · » ¿
4008 'IsPunct disagrees with [:punct:] outside ASCII';
4010 my @isPunctLatin1 = eval q {
4011 use encoding 'latin1';
4012 grep {/[[:punct:]]/ != /\p{IsPunct}/} map {chr} 0x80 .. 0xff;
4014 skip "Eval failed ($@)", 1 if $@;
4015 skip "PERL_LEGACY_UNICODE_CHARCLASS_MAPPINGS set to 0", 1
4016 if $ENV {REAL_POSIX_CC};
4017 iseq join ('', @isPunctLatin1), '',
4018 'IsPunct agrees with [:punct:] with explicit Latin1';
4023 local $BugId = '60034';
4024 local $TODO = "See bug 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;
4034 ok $b =~ /\A(?>[a-z])*\z/,
4035 '(?>) does not cause wrongness on long string with UTF-8';
4040 # Keep the following tests last -- they may crash perl
4042 print "# Tests that follow may crash perl\n";
4044 local $BugId = '19049/38869';
4045 local $Message = 'Pattern in a loop, failure should not ' .
4046 'affect previous success';
4048 'ab cdef', # Matches regex
4049 ('e' x 40000 ) .'ab c' # Matches not, but 'ab c' matches part of it
4054 m/ab(.+)cd/i; # The ignore-case seems to be important
4055 $y = $1; # Use $1, which might not be from the last match!
4056 $x = substr ($list [0], $- [0], $+ [0] - $- [0]);
4064 local $BugId = '24274';
4066 ok (("a" x (2 ** 15 - 10)) =~ /^()(a|bb)*$/, "Recursive stack cracker");
4067 ok ((q(a)x 100) =~ /^(??{'(.)'x 100})/,
4068 "Regexp /^(??{'(.)'x 100})/ crashes older perls");
4074 ok $@ =~ /\QSequence \k... not terminated in regex;\E/,
4075 'Lone \k not allowed';
4080 local $Message = "Substitution with lookahead (possible segv)";
4083 iseq $_, "ns_1ns_1ns_1";
4088 s/(?=\d+)|(?<=\d)/!Bang!/g;
4089 iseq $_, "!Bang!1!Bang!2!Bang!3!Bang!";
4094 # [perl #45337] utf8 + "[a]a{2}" + /$.../ = panic: sv_len_utf8 cache
4095 local $BugId = '45337';
4096 local ${^UTF8CACHE} = -1;
4097 local $Message = "Shouldn't panic";
4103 local $BugId = '57042';
4104 local $Message = "Check if tree logic breaks \$^R";
4105 my $cond_re = qr/\s*
4112 for my $line ("(A)","(B)") {
4113 if ($line =~ m/$cond_re/) {
4114 push @res, $^R ? "#$^R" : "UNDEF";
4117 iseq "@res","#1 #2";
4120 no warnings 'closure';
4121 my $re = qr/A(??{"1"})/;
4122 ok "A1B" =~ m/^((??{ $re }))((??{"B"}))$/;
4127 # This should be the last test.
4129 iseq $test + 1, $EXPECTED_TESTS, "Got the right number of tests!";
4131 } # End of sub run_tests