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.
9 # Test counter output is generated by a BEGIN block at bottom of file
15 our $Message = "Noname test";
17 eval 'use Config'; # Defaults assumed if this fails
21 if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
22 if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
24 # used to be a test for $*
25 if ($x =~ /^def/m) {print "ok 3\n";} else {print "not ok 3\n";}
28 if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
30 if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
31 if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
33 if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
34 if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
36 if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
37 if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
39 if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
40 if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
43 if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
48 if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
54 if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
57 if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
58 if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
61 if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
62 if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
65 if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
66 if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
68 if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
70 if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
72 # used to be a test for $*
73 if ("ab\ncd\n" =~ /^cd/m) {print "ok 24\n";} else {print "not ok 24\n";}
79 @XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27');
80 while ($_ = shift(@XXX)) {
81 ?(.*)? && (print $1,"\n");
94 while (($key,$val) = each(%XXX)) {
104 if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
109 if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
114 if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
117 /def/; # optimized up to cmd
118 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
120 /cde/ + 0; # optimized only to spat
121 if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
123 /[d][e][f]/; # not optimized
124 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
126 $_ = 'now is the {time for all} good men to come to.';
128 if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
130 $_ = 'xxx {3,4} yyy zzz';
131 print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
132 print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
133 print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
134 print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
135 print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
136 print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
137 print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
138 print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
139 print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
141 $_ = "now is the time for all good men to come to.";
143 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
151 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
160 print join(':',@words) eq "to:to"
162 : "not ok 46 `@words'\n";
166 print join(':',@words) eq "to:to"
168 : "not ok 47 `@words'\n";
182 $t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
196 $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
197 print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
200 print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
202 # perl 4.009 says "unmatched ()"
203 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
204 print $@ eq "" ? "ok 50\n" : "not ok 50\n";
205 print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
210 print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
212 print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
214 print $x == 0 ? "ok 54\n" : "not ok 54\n";
217 print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
219 print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
221 print $x == 0 ? "ok 57\n" : "not ok 57\n";
224 print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
226 print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
229 print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
234 print "not " if (pos $_) != 2;
237 print "not " if defined pos $_;
241 'abc' =~ m'a(?{ $out = 2 })b';
242 print "not " if $out != 2;
246 'abc' =~ m'a(?{ $out = 3 })c';
247 print "not " if $out != 1;
250 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
251 @out = /(?<!foo)bar./g;
252 print "not " if "@out" ne 'bar2 barf';
255 # Tests which depend on REG_INFTY
256 $reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
257 $reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
259 # As well as failing if the pattern matches do unexpected things, the
260 # next three tests will fail if you should have picked up a lower-than-
261 # default value for $reg_infty from Config.pm, but have not.
264 print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
268 print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
272 print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
276 eval "'aaa' =~ /a{1,$reg_infty}/";
277 print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
280 eval "'aaa' =~ /a{1,$reg_infty_p}/";
282 if $@ !~ m%^\QQuantifier in {,} bigger than%;
286 # Poke a couple more parse failures
288 $context = 'x' x 256;
289 eval qq("${context}y" =~ /(?<=$context)y/);
290 print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
298 for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
300 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
304 print "not " if "b$a=" =~ /a$a=/;
309 # 20000 nodes, each taking 3 words per string, and 1 per branch
310 $long_constant_len = join '|', 12120 .. 32645;
311 $long_var_len = join '|', 8120 .. 28645;
312 %ans = ( 'ax13876y25677lbc' => 1,
313 'ax13876y25677mcb' => 0, # not b.
314 'ax13876y35677nbc' => 0, # Num too big
315 'ax13876y25677y21378obc' => 1,
316 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
317 'ax13876y25677y21378y21378kbc' => 1,
318 'ax13876y25677y21378y21378kcb' => 0, # Not b.
319 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
323 print "# const-len `$_' not => $ans{$_}\nnot "
324 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
327 print "# var-len `$_' not => $ans{$_}\nnot "
328 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
333 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
334 $expect = "(bla()) ((l)u((e))) (l(e)e)";
340 (?{ $c = 1 }) # Initialize
342 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
344 ) # Fail: will unwind one iteration back
347 [^()]+ # Match a big chunk
350 ) # Do not try to match subchunks
358 )+ # This may not match with different subblocks
363 ) # Otherwise the chunk 1 may succeed with $c>0
368 push @ans, $res while $res = matchit;
370 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
376 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
380 print "not " unless "abc" =~ /^(??{"a"})b/;
385 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
388 push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
390 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
394 print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
400 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
404 @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
405 print "not " if "@ans" ne 'a/ b';
409 $code = '{$blah = 45}';
412 print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
416 for $code ('{$blah = 45}','=xx') {
418 $res = eval { "xx" =~ /(?$code)/o };
419 if ($code eq '=xx') {
420 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
422 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
428 $code = '{$blah = 45}';
431 print "not " if $blah != 45;
437 print "not " if $blah != 45;
443 print "not " unless pos($x) == 2;
448 print "not " unless pos($x) == 2;
458 print "not " unless f(pos($x)) == 4;
463 'foot' =~ /foo(?{$x = 12; 75})[t]/;
464 print "not " unless $^R eq '75';
469 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
470 print "not " unless $^R eq '67' and $x eq '12';
475 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
476 print "not " unless $^R eq '79' and $x eq '12';
480 print "not " unless qr/\b\v$/i eq '(?i-xsm:\b\v$)';
484 print "not " unless qr/\b\v$/s eq '(?s-xim:\b\v$)';
488 print "not " unless qr/\b\v$/m eq '(?m-xis:\b\v$)';
492 print "not " unless qr/\b\v$/x eq '(?x-ism:\b\v$)';
496 print "not " unless qr/\b\v$/xism eq '(?msix:\b\v$)';
500 print "not " unless qr/\b\v$/ eq '(?-xism:\b\v$)';
505 foreach $ans ('', 'c') {
506 /(?<=(?=a)..)((?=c)|.)/g;
507 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
513 foreach $ans ('', 'a', '') {
515 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
521 my($v,$a,$b,$res) = @_;
523 print "not " unless $res eq $v;
527 prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
528 prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
532 print "not " unless $1 and /$1/;
539 print "not " unless $b eq '9';
545 print "not " unless $b eq '11';
552 print "not " unless $b eq '14';
560 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
561 print "not " unless $lex_res eq '1';
564 print "not " unless $lex_a eq '44';
567 print "not " unless $lex_c eq '43';
573 $match = eval { /$a$c$a/ };
575 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
585 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
586 print "not " unless $lex_res eq '1';
589 print "not " unless $lex_a eq '44';
592 print "not " unless $lex_c eq '43';
601 '' =~ /(?{ $c = 4 })/;
602 print "not " unless $c == 4;
606 print "not " unless $c == 3;
611 my $warn_pat = shift;
612 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
616 my ($warn_pat, $code) = @_;
618 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
625 my $warn_pat = shift;
626 return sub { must_warn(must_warn_pat($warn_pat)) }
629 my $for_future = make_must_warn('reserved for future extensions');
631 &$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
633 #&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
634 print "ok $test\n"; $test++; # now a fatal croak
636 #&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
637 print "ok $test\n"; $test++; # now a fatal croak
639 # test if failure of patterns returns empty list
662 print "not " if $#+ != 0 or $#- != 0;
666 print "not " if $+[0] != 2 or $-[0] != 1;
671 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
676 print "not " if $#+ != 2 or $#- != 2;
680 print "not " if $+[0] != 3 or $-[0] != 0;
684 print "not " if $+[1] != 2 or $-[1] != 1;
688 print "not " if $+[2] != 3 or $-[2] != 2;
693 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
698 print "not " if $#+ != 3 or $#- != 3;
702 print "not " if $+[0] != 3 or $-[0] != 0;
706 print "not " if $+[1] != 2 or $-[1] != 1;
710 print "not " if $+[3] != 3 or $-[3] != 2;
715 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
720 print "not " if $#+ != 1 or $#- != 1;
724 print "not " if $+[0] != 2 or $-[0] != 0;
728 print "not " if $+[1] != 2 or $-[1] != 1;
733 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
737 eval { $+[0] = 13; };
739 if $@ !~ /^Modification of a read-only value attempted/;
743 eval { $-[0] = 13; };
745 if $@ !~ /^Modification of a read-only value attempted/;
749 eval { @+ = (7, 6, 5); };
751 if $@ !~ /^Modification of a read-only value attempted/;
755 eval { @- = qw(foo bar); };
757 if $@ !~ /^Modification of a read-only value attempted/;
762 print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
769 print "not " unless "@a" eq "a a";
776 print "not " if $str =~ /^\G/;
780 print "not " if $str =~ /^.\G/;
784 print "not " unless $str =~ /^..\G/;
788 print "not " if $str =~ /^...\G/;
792 print "not " unless $str =~ /.\G./ and $& eq 'bc';
796 print "not " unless $str =~ /\G../ and $& eq 'cd';
800 undef $foo; undef $bar;
801 print "#'$str','$foo','$bar'\nnot "
802 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
803 and $foo eq 'abcde' and $bar eq 2;
807 undef $foo; undef $bar;
809 print "#'$str','$foo','$bar'\nnot "
810 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
811 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
817 undef $foo; undef $bar;
818 print "#'$str','$foo','$bar'\nnot "
819 unless /b(?{$foo = $_; $bar = pos})c/
820 and $foo eq 'abcde' and $bar eq 2;
824 undef $foo; undef $bar;
825 print "#'$str','$foo','$bar'\nnot "
826 unless /b(?{$foo = $_; $bar = pos})c/g
827 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
831 undef $foo; undef $bar;
833 1 while /b(?{$foo = $_; $bar = pos})c/g;
834 print "#'$str','$foo','$bar'\nnot "
835 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
839 undef $foo; undef $bar;
841 print "#'$str','$foo','$bar','$_'\nnot "
842 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
843 and $bar eq 8 and $_ eq 'axde|axde';
850 @dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
851 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
853 print "#'@res' '$_'\nnot "
854 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
859 @dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
860 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
862 print "#'@res' '$_'\nnot "
864 "'' 'ab' 'cde|abcde' " .
865 "'' 'abc' 'de|abcde' " .
866 "'abcd' 'e|' 'abcde' " .
867 "'abcde|' 'ab' 'cde' " .
868 "'abcde|' 'abc' 'de'" ;
872 #Some more \G anchor checks
873 $foo='aabbccddeeffgg';
882 print "not " unless($1 eq 'cc');
888 print "not " unless($1 eq 'de');
892 print "not " unless $foo =~ /\Gef/g;
899 print "not " unless($1 eq 'aa');
904 print "not " unless($1 eq 'bb');
910 print "not " unless($1 eq 'cd');
916 print "not " unless('123||x|123|' eq join '|', @res);
920 # see if matching against temporaries (created via pp_helem()) is safe
921 { foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
925 # See if $i work inside (?{}) in the presense of saved substrings and
929 s/(\w)(?{push @b, $1})/,$1,/g for @a;
931 print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
935 print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
940 { (?> [^{}]+ | (??{ $brackets }) )* }
944 print "ok $test\n"; # Did we survive?
947 "something { long { and } hairy" =~ $brackets;
948 print "ok $test\n"; # Did we survive?
951 "something { long { and } hairy" =~ m/((??{ $brackets }))/;
952 print "not " unless $1 eq "{ and }";
958 m/^-.*bb/mg and print "not ";
964 $text =~ /\GXb*X/g and print 'not ';
968 $text = "xA\n" x 500;
969 $text =~ /^\s*A/m and print 'not ';
974 @res = ($text =~ /.*?(b).*?\b/g);
975 "@res" eq 'b b' or print 'not ';
982 @c = grep(/[^\s]/,@a);
983 print "not " if "@b" ne "@c";
988 @c = grep(/[\S]/,@a);
989 print "not " if "@b" ne "@c";
994 @c = grep(/[^\S]/,@a);
995 print "not " if "@b" ne "@c";
1000 @c = grep(/[\s]/,@a);
1001 print "not " if "@b" ne "@c";
1006 @c = grep(/[^\d]/,@a);
1007 print "not " if "@b" ne "@c";
1012 @c = grep(/[\D]/,@a);
1013 print "not " if "@b" ne "@c";
1018 @c = grep(/[^\D]/,@a);
1019 print "not " if "@b" ne "@c";
1024 @c = grep(/[\d]/,@a);
1025 print "not " if "@b" ne "@c";
1030 @c = grep(/[^\w]/,@a);
1031 print "not " if "@b" ne "@c";
1036 @c = grep(/[\W]/,@a);
1037 print "not " if "@b" ne "@c";
1042 @c = grep(/[^\W]/,@a);
1043 print "not " if "@b" ne "@c";
1048 @c = grep(/[\w]/,@a);
1051 # see if backtracking optimization works correctly
1052 "\n\n" =~ /\n $ \n/x or print "not ";
1056 "\n\n" =~ /\n* $ \n/x or print "not ";
1060 "\n\n" =~ /\n+ $ \n/x or print "not ";
1064 [] =~ /^ARRAY/ or print "# [] \nnot ";
1071 use overload '""' => sub { 'Object S' };
1072 sub new { bless [] }
1077 $a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1081 # test result of match used as match (!)
1082 'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1086 'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1092 local $SIG{__WARN__} = sub { $w = 1 };
1094 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1096 print $w ? "not " : "", "ok $test\n";
1099 my %space = ( spc => " ",
1104 # There's no \v but the vertical tabulator seems miraculously
1105 # be 11 both in ASCII and EBCDIC.
1109 my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1110 my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1111 my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1113 print "not " unless "@space0" eq "cr ff lf spc tab";
1114 print "ok $test # @space0\n";
1117 print "not " unless "@space1" eq "cr ff lf spc tab vt";
1118 print "ok $test # @space1\n";
1121 print "not " unless "@space2" eq "spc tab";
1122 print "ok $test # @space2\n";
1125 # bugid 20001021.005 - this caused a SEGV
1126 print "not " unless undef =~ /^([^\/]*)(.*)$/;
1130 # bugid 20000731.001
1132 print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1136 my $ordA = ord('A');
1139 if (/(.)(\C)(\C)(.)/) {
1144 print "not ok 233\n";
1146 if ($ordA == 65) { # ASCII (or equivalent), should be UTF-8
1150 print "not ok 234\n";
1155 print "not ok 235\n";
1157 } elsif ($ordA == 193) { # EBCDIC (or equivalent), should be UTF-EBCDIC
1161 print "not ok 234\n";
1166 print "not ok 235\n";
1170 print "not ok $_ # ord('A') == $ordA\n";
1176 print "not ok 236\n";
1180 print "not ok $_\n";
1186 # currently \C are still tagged as UTF-8
1191 print "not ok 238\n";
1193 } elsif ($ordA == 193) {
1197 print "not ok 238\n";
1200 print "not ok 238 # ord('A') == $ordA\n";
1204 print "not ok $_\n";
1209 # currently \C are still tagged as UTF-8
1214 print "not ok 240\n";
1216 } elsif ($ordA == 193) {
1220 print "not ok 240\n";
1223 print "not ok 240 # ord('A') == $ordA\n";
1227 print "not ok $_\n";
1232 # japhy -- added 03/03/2001
1233 () = (my $str = "abc") =~ /(...)/;
1235 print "not " if $1 ne "abc";
1239 # The 242 and 243 go with the 244 and 245.
1240 # The trick is that in EBCDIC the explicit numeric range should match
1241 # (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1243 if ("\x8e" =~ /[\x89-\x91]/) {
1246 print "not ok 242\n";
1249 if ("\xce" =~ /[\xc9-\xd1]/) {
1252 print "not ok 243\n";
1255 # In most places these tests would succeed since \x8e does not
1256 # in most character sets match 'i' or 'j' nor would \xce match
1257 # 'I' or 'J', but strictly speaking these tests are here for
1258 # the good of EBCDIC, so let's test these only there.
1259 if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1260 if ("\x8e" !~ /[i-j]/) {
1263 print "not ok 244\n";
1265 if ("\xce" !~ /[I-J]/) {
1268 print "not ok 245\n";
1272 print "ok $_ # Skip: only in EBCDIC\n";
1276 print "not " unless "\x{ab}" =~ /\x{ab}/;
1279 print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1283 # bug id 20001008.001
1286 my @x = ("stra\337e 138","stra\337e 138");
1288 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1289 my($latin) = /^(.+)(?:\s+\d)/;
1290 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1291 "#latin[$latin]\nnot ok $test\n";
1293 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1294 use utf8; # needed for the raw UTF-8
1295 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1300 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1303 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1306 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1309 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1312 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1315 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1318 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1321 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1326 # the first half of 20001028.003
1329 my ($Y) = $X =~ /(.*)/;
1330 print "not " unless $Y eq v1448 && length($Y) == 1;
1337 my $X = "Szab\x{f3},Bal\x{e1}zs";
1339 $Y =~ s/(B)/$1/ for 0..3;
1340 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1345 # the second half of 20001028.003
1348 $X =~ s/^/chr(1488)/e;
1349 print "not " unless length $X == 1 && ord($X) == 1488;
1360 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1365 # bug id 20001230.002
1367 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1370 print "not " unless "École" =~ /^\C\C(c)/;
1375 $test = 264; # till 575
1377 use charnames ":full";
1379 # This is far from complete testing, there are dozens of character
1380 # classes in Unicode. The mixing of literals and \N{...} is
1381 # intentional so that in non-Latin-1 places we test the native
1382 # characters, not the Unicode code points.
1386 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1388 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1389 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1390 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1392 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1399 for my $char (map { s/^\S+ //; $_ }
1400 sort map { sprintf("%06x", ord($_))." $_" } keys %s) {
1401 my $class = $s{$char};
1402 my $code = sprintf("%06x", ord($char));
1403 printf "#\n# 0x$code\n#\n";
1404 print "# IsAlpha\n";
1405 if ($class =~ /^[LM]/) {
1406 print "not " unless $char =~ /\p{IsAlpha}/;
1407 print "ok $test\n"; $test++;
1408 print "not " if $char =~ /\P{IsAlpha}/;
1409 print "ok $test\n"; $test++;
1411 print "not " if $char =~ /\p{IsAlpha}/;
1412 print "ok $test\n"; $test++;
1413 print "not " unless $char =~ /\P{IsAlpha}/;
1414 print "ok $test\n"; $test++;
1416 print "# IsAlnum\n";
1417 if ($class =~ /^[LMN]/ && $char ne "_") {
1418 print "not " unless $char =~ /\p{IsAlnum}/;
1419 print "ok $test\n"; $test++;
1420 print "not " if $char =~ /\P{IsAlnum}/;
1421 print "ok $test\n"; $test++;
1423 print "not " if $char =~ /\p{IsAlnum}/;
1424 print "ok $test\n"; $test++;
1425 print "not " unless $char =~ /\P{IsAlnum}/;
1426 print "ok $test\n"; $test++;
1428 print "# IsASCII\n";
1429 if (ord("A") == 193) {
1430 print "ok $test # Skip: in EBCDIC\n"; $test++;
1431 print "ok $test # Skip: in EBCDIC\n"; $test++;
1433 if ($code le '00007f') {
1434 print "not " unless $char =~ /\p{IsASCII}/;
1435 print "ok $test\n"; $test++;
1436 print "not " if $char =~ /\P{IsASCII}/;
1437 print "ok $test\n"; $test++;
1439 print "not " if $char =~ /\p{IsASCII}/;
1440 print "ok $test\n"; $test++;
1441 print "not " unless $char =~ /\P{IsASCII}/;
1442 print "ok $test\n"; $test++;
1445 print "# IsCntrl\n";
1446 if ($class =~ /^C/) {
1447 print "not " unless $char =~ /\p{IsCntrl}/;
1448 print "ok $test\n"; $test++;
1449 print "not " if $char =~ /\P{IsCntrl}/;
1450 print "ok $test\n"; $test++;
1452 print "not " if $char =~ /\p{IsCntrl}/;
1453 print "ok $test\n"; $test++;
1454 print "not " unless $char =~ /\P{IsCntrl}/;
1455 print "ok $test\n"; $test++;
1457 print "# IsBlank\n";
1458 if ($class =~ /^Z[lp]/ || $char eq " ") {
1459 print "not " unless $char =~ /\p{IsBlank}/;
1460 print "ok $test\n"; $test++;
1461 print "not " if $char =~ /\P{IsBlank}/;
1462 print "ok $test\n"; $test++;
1464 print "not " if $char =~ /\p{IsBlank}/;
1465 print "ok $test\n"; $test++;
1466 print "not " unless $char =~ /\P{IsBlank}/;
1467 print "ok $test\n"; $test++;
1469 print "# IsDigit\n";
1470 if ($class =~ /^Nd$/) {
1471 print "not " unless $char =~ /\p{IsDigit}/;
1472 print "ok $test\n"; $test++;
1473 print "not " if $char =~ /\P{IsDigit}/;
1474 print "ok $test\n"; $test++;
1476 print "not " if $char =~ /\p{IsDigit}/;
1477 print "ok $test\n"; $test++;
1478 print "not " unless $char =~ /\P{IsDigit}/;
1479 print "ok $test\n"; $test++;
1481 print "# IsGraph\n";
1482 if ($class =~ /^([LMNPS])|Co/) {
1483 print "not " unless $char =~ /\p{IsGraph}/;
1484 print "ok $test\n"; $test++;
1485 print "not " if $char =~ /\P{IsGraph}/;
1486 print "ok $test\n"; $test++;
1488 print "not " if $char =~ /\p{IsGraph}/;
1489 print "ok $test\n"; $test++;
1490 print "not " unless $char =~ /\P{IsGraph}/;
1491 print "ok $test\n"; $test++;
1493 print "# IsLower\n";
1494 if ($class =~ /^Ll$/) {
1495 print "not " unless $char =~ /\p{IsLower}/;
1496 print "ok $test\n"; $test++;
1497 print "not " if $char =~ /\P{IsLower}/;
1498 print "ok $test\n"; $test++;
1500 print "not " if $char =~ /\p{IsLower}/;
1501 print "ok $test\n"; $test++;
1502 print "not " unless $char =~ /\P{IsLower}/;
1503 print "ok $test\n"; $test++;
1505 print "# IsPrint\n";
1506 if ($class =~ /^([LMNPS])|Co|Zs/) {
1507 print "not " unless $char =~ /\p{IsPrint}/;
1508 print "ok $test\n"; $test++;
1509 print "not " if $char =~ /\P{IsPrint}/;
1510 print "ok $test\n"; $test++;
1512 print "not " if $char =~ /\p{IsPrint}/;
1513 print "ok $test\n"; $test++;
1514 print "not " unless $char =~ /\P{IsPrint}/;
1515 print "ok $test\n"; $test++;
1517 print "# IsPunct\n";
1518 if ($class =~ /^P/ || $char eq "_") {
1519 print "not " unless $char =~ /\p{IsPunct}/;
1520 print "ok $test\n"; $test++;
1521 print "not " if $char =~ /\P{IsPunct}/;
1522 print "ok $test\n"; $test++;
1524 print "not " if $char =~ /\p{IsPunct}/;
1525 print "ok $test\n"; $test++;
1526 print "not " unless $char =~ /\P{IsPunct}/;
1527 print "ok $test\n"; $test++;
1529 print "# IsSpace\n";
1530 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1531 print "not " unless $char =~ /\p{IsSpace}/;
1532 print "ok $test\n"; $test++;
1533 print "not " if $char =~ /\P{IsSpace}/;
1534 print "ok $test\n"; $test++;
1536 print "not " if $char =~ /\p{IsSpace}/;
1537 print "ok $test\n"; $test++;
1538 print "not " unless $char =~ /\P{IsSpace}/;
1539 print "ok $test\n"; $test++;
1541 print "# IsUpper\n";
1542 if ($class =~ /^L[ut]/) {
1543 print "not " unless $char =~ /\p{IsUpper}/;
1544 print "ok $test\n"; $test++;
1545 print "not " if $char =~ /\P{IsUpper}/;
1546 print "ok $test\n"; $test++;
1548 print "not " if $char =~ /\p{IsUpper}/;
1549 print "ok $test\n"; $test++;
1550 print "not " unless $char =~ /\P{IsUpper}/;
1551 print "ok $test\n"; $test++;
1554 if ($class =~ /^[LMN]/ || $char eq "_") {
1555 print "not " unless $char =~ /\p{IsWord}/;
1556 print "ok $test\n"; $test++;
1557 print "not " if $char =~ /\P{IsWord}/;
1558 print "ok $test\n"; $test++;
1560 print "not " if $char =~ /\p{IsWord}/;
1561 print "ok $test\n"; $test++;
1562 print "not " unless $char =~ /\P{IsWord}/;
1563 print "ok $test\n"; $test++;
1569 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1571 if (/(.\x{300})./) {
1574 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
1577 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
1580 print "not " unless $' eq "\x{400}defg" && length($') == 5;
1583 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
1586 for (576..580) { print "not ok $_\n" }
1591 # bug id 20010306.008
1594 # The original bug report had 'no utf8' here but that was irrelevant.
1595 $a =~ m/\w/; # used to core dump
1603 # bugid 20010410.006
1605 '/(.*?)\{(.*?)\}/csg',
1606 '/(.*?)\{(.*?)\}/cg',
1607 '/(.*?)\{(.*?)\}/sg',
1608 '/(.*?)\{(.*?)\}/g',
1609 '/(.+?)\{(.+?)\}/csg',
1615 $input = "a{b}c{d}";
1617 while (eval \$input =~ $rx) {
1618 print "# \\\$1 = '\$1' \\\$2 = '\$2'\n";
1622 print "not " unless $i == 2;
1623 print "ok " . $test++ . "\n";
1628 # from Robin Houston
1630 my $x = "\x{10FFFD}";
1632 print "not " unless ord($x) == 0x10FFFD && length($x) == 1;
1639 print "not " if $x =~ /[\x80-\xff]/;
1642 print "not " if $x =~ /[\x80-\x{100}]/;
1645 print "not " if $x =~ /[\x{100}]/;
1648 print "not " if $x =~ /\p{InLatin1Supplement}/;
1651 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1654 print "not " if $x =~ /\p{InLatinExtendedA}/;
1657 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1664 print "not " unless $x =~ /[\x80-\xff]/;
1667 print "not " unless $x =~ /[\x80-\x{100}]/;
1670 print "not " if $x =~ /[\x{100}]/;
1673 print "not " unless $x =~ /\p{InLatin1Supplement}/;
1676 print "not " if $x =~ /\P{InLatin1Supplement}/;
1679 print "not " if $x =~ /\p{InLatinExtendedA}/;
1682 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1689 print "not " unless $x =~ /[\x80-\xff]/;
1692 print "not " unless $x =~ /[\x80-\x{100}]/;
1695 print "not " if $x =~ /[\x{100}]/;
1698 # the next two tests must be ignored on EBCDIC
1699 print "not " unless $x =~ /\p{InLatin1Supplement}/ or ord("A") == 193;
1702 print "not " if $x =~ /\P{InLatin1Supplement}/ and ord("A") != 193;
1705 print "not " if $x =~ /\p{InLatinExtendedA}/;
1708 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1715 print "not " if $x =~ /[\x80-\xff]/;
1718 print "not " unless $x =~ /[\x80-\x{100}]/;
1721 print "not " unless $x =~ /[\x{100}]/;
1724 print "not " if $x =~ /\p{InLatin1Supplement}/;
1727 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1730 print "not " unless $x =~ /\p{InLatinExtendedA}/;
1733 print "not " if $x =~ /\P{InLatinExtendedA}/;
1741 local $SIG{__WARN__} = sub { $w .= shift };
1745 print "not " if $w !~ /^Useless \(\?c\)/;
1750 print "not " if $w !~ /^Useless \(\?-c\)/;
1755 print "not " if $w !~ /^Useless \(\?g\)/;
1760 print "not " if $w !~ /^Useless \(\?-g\)/;
1765 print "not " if $w !~ /^Useless \(\?o\)/;
1770 print "not " if $w !~ /^Useless \(\?-o\)/;
1773 # now test multi-error regexes
1777 print "not " if $w !~ /^Useless \(\?g\).*\nUseless \(\?-o\)/;
1782 print "not " if $w !~ /^Useless \(\?g\).*\nUseless \(\?-c\)/;
1786 eval 'qr/(?o-cg)/'; # (?c) means (?g) error won't be thrown
1787 print "not " if $w !~ /^Useless \(\?o\).*\nUseless \(\?-c\)/;
1792 print "not " if $w !~ /^Useless \(\?o\).*\nUseless \(\?g\).*\nUseless \(\?c\)/;
1796 # More Unicode "class" tests
1799 use charnames ':full';
1801 print "not " unless "\N{LATIN CAPITAL LETTER A}" =~ /\p{InBasicLatin}/;
1804 print "not " unless "\N{LATIN CAPITAL LETTER A WITH GRAVE}" =~ /\p{InLatin1Supplement}/;
1807 print "not " unless "\N{LATIN CAPITAL LETTER A WITH MACRON}" =~ /\p{InLatinExtendedA}/;
1810 print "not " unless "\N{LATIN SMALL LETTER B WITH STROKE}" =~ /\p{InLatinExtendedB}/;
1813 print "not " unless "\N{KATAKANA LETTER SMALL A}" =~ /\p{InKatakana}/;
1819 eval <<"EOT"; die if $@;
1824 /x && print "ok 631\n";
1827 eval <<"EOT"; die if $@;
1832 /x && print "ok 632\n";
1836 sub test_o { $_[0] =~/$_[1]/o; return $1}
1837 if(test_o('abc','(.)..') eq 'a') {
1840 print "not ok 633\n";
1842 if(test_o('abc','..(.)') eq 'a') {
1845 print "not ok 634\n";
1848 # 635..639: ID 20010619.003 (only the space character is
1849 # supposed to be [:print:], not the whole isprint()).
1851 print "not " if "\n" =~ /[[:print:]]/;
1854 print "not " if "\t" =~ /[[:print:]]/;
1857 # Amazingly vertical tabulator is the same in ASCII and EBCDIC.
1858 print "not " if "\014" =~ /[[:print:]]/;
1861 print "not " if "\r" =~ /[[:print:]]/;
1864 print "not " unless " " =~ /[[:print:]]/;
1868 ## Test basic $^N usage outside of a regex
1871 $T="ok 640\n";if ($x =~ /cde/ and not defined $^N) {print $T} else {print "not $T"};
1872 $T="ok 641\n";if ($x =~ /(cde)/ and $^N eq "cde") {print $T} else {print "not $T"};
1873 $T="ok 642\n";if ($x =~ /(c)(d)(e)/ and $^N eq "e") {print $T} else {print "not $T"};
1874 $T="ok 643\n";if ($x =~ /(c(d)e)/ and $^N eq "cde") {print $T} else {print "not $T"};
1875 $T="ok 644\n";if ($x =~ /(foo)|(c(d)e)/ and $^N eq "cde") {print $T} else {print "not $T"};
1876 $T="ok 645\n";if ($x =~ /(c(d)e)|(foo)/ and $^N eq "cde") {print $T} else {print "not $T"};
1877 $T="ok 646\n";if ($x =~ /(c(d)e)|(abc)/ and $^N eq "abc") {print $T} else {print "not $T"};
1878 $T="ok 647\n";if ($x =~ /(c(d)e)|(abc)x/ and $^N eq "cde") {print $T} else {print "not $T"};
1879 $T="ok 648\n";if ($x =~ /(c(d)e)(abc)?/ and $^N eq "cde") {print $T} else {print "not $T"};
1880 $T="ok 649\n";if ($x =~ /(?:c(d)e)/ and $^N eq "d" ) {print $T} else {print "not $T"};
1881 $T="ok 650\n";if ($x =~ /(?:c(d)e)(?:f)/ and $^N eq "d" ) {print $T} else {print "not $T"};
1882 $T="ok 651\n";if ($x =~ /(?:([abc])|([def]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1883 $T="ok 652\n";if ($x =~ /(?:([ace])|([bdf]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1884 $T="ok 653\n";if ($x =~ /(([ace])|([bd]))*/ and $^N eq "e" ){print $T} else {print "not $T"};
1886 $T="ok 654\n";if($x =~ /(([ace])|([bdf]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1888 ## test to see if $^N is automatically localized -- it should now
1889 ## have the value set in test 653
1890 $T="ok 655\n";if ($^N eq "e" ){print $T} else {print "not $T"};
1893 ## Now test inside (?{...})
1895 $T="ok 656\n";if ($x =~ /a([abc])(?{$y=$^N})c/ and $y eq "b" ){print $T} else {print "not $T"};
1896 $T="ok 657\n";if ($x =~ /a([abc]+)(?{$y=$^N})d/ and $y eq "bc"){print $T} else {print "not $T"};
1897 $T="ok 658\n";if ($x =~ /a([abcdefg]+)(?{$y=$^N})d/ and $y eq "bc"){print $T} else {print "not $T"};
1898 $T="ok 659\n";if ($x =~ /(a([abcdefg]+)(?{$y=$^N})d)(?{$z=$^N})e/ and $y eq "bc" and $z eq "abcd")
1899 {print $T} else {print "not $T"};
1900 $T="ok 660\n";if ($x =~ /(a([abcdefg]+)(?{$y=$^N})de)(?{$z=$^N})/ and $y eq "bc" and $z eq "abcde")
1901 {print $T} else {print "not $T"};
1903 # Test the Unicode script classes
1905 print "not " unless chr(0x100) =~ /\p{IsLatin}/; # outside Latin-1
1908 print "not " unless chr(0x212b) =~ /\p{IsLatin}/; # Angstrom sign, very outside
1911 print "not " unless chr(0x5d0) =~ /\p{IsHebrew}/; # inside InHebrew
1914 print "not " unless chr(0xfb4f) =~ /\p{IsHebrew}/; # outside InHebrew
1917 # # singleton (not in a range, this test must be ignored on EBCDIC)
1918 # print "not " unless chr(0xb5) =~ /\p{IsGreek}/ or ord("A") == 193;
1920 print "ok 665 # 0xb5 moved from Greek to Common with Unicode 4.0.1\n";
1922 print "not " unless chr(0x37a) =~ /\p{IsGreek}/; # singleton
1925 print "not " unless chr(0x386) =~ /\p{IsGreek}/; # singleton
1928 print "not " unless chr(0x387) =~ /\P{IsGreek}/; # not there
1931 print "not " unless chr(0x388) =~ /\p{IsGreek}/; # range
1934 print "not " unless chr(0x38a) =~ /\p{IsGreek}/; # range
1937 print "not " unless chr(0x38b) =~ /\P{IsGreek}/; # not there
1940 print "not " unless chr(0x38c) =~ /\p{IsGreek}/; # singleton
1943 if (ord("A") == 65) {
1945 ## Test [:cntrl:]...
1947 ## Should probably put in tests for all the POSIX stuff, but not sure how to
1948 ## guarantee a specific locale......
1950 $AllBytes = join('', map { chr($_) } 0..255);
1951 ($x = $AllBytes) =~ s/[[:cntrl:]]//g;
1952 if ($x ne join('', map { chr($_) } 0x20..0x7E, 0x80..0xFF)) {
1957 ($x = $AllBytes) =~ s/[^[:cntrl:]]//g;
1958 if ($x ne join('', map { chr($_) } 0..0x1F, 0x7F)) { print "not " }
1961 print "ok $_ # Skip: EBCDIC\n" for 673..674;
1964 # With /s modifier UTF8 chars were interpreted as bytes
1966 my $a = "Hello \x{263A} World";
1968 my @a = ($a =~ /./gs);
1970 print "not " unless $#a == 12;
1974 @a = ("foo\nbar" =~ /./g);
1975 print "ok 676\n" if @a == 6 && "@a" eq "f o o b a r";
1977 @a = ("foo\nbar" =~ /./gs);
1978 print "ok 677\n" if @a == 7 && "@a" eq "f o o \n b a r";
1980 @a = ("foo\nbar" =~ /\C/g);
1981 print "ok 678\n" if @a == 7 && "@a" eq "f o o \n b a r";
1983 @a = ("foo\nbar" =~ /\C/gs);
1984 print "ok 679\n" if @a == 7 && "@a" eq "f o o \n b a r";
1986 @a = ("foo\n\x{100}bar" =~ /./g);
1987 print "ok 680\n" if @a == 7 && "@a" eq "f o o \x{100} b a r";
1989 @a = ("foo\n\x{100}bar" =~ /./gs);
1990 print "ok 681\n" if @a == 8 && "@a" eq "f o o \n \x{100} b a r";
1992 ($a, $b) = map { chr } ord('A') == 65 ? (0xc4, 0x80) : (0x8c, 0x41);
1994 @a = ("foo\n\x{100}bar" =~ /\C/g);
1995 print "ok 682\n" if @a == 9 && "@a" eq "f o o \n $a $b b a r";
1997 @a = ("foo\n\x{100}bar" =~ /\C/gs);
1998 print "ok 683\n" if @a == 9 && "@a" eq "f o o \n $a $b b a r";
2001 # [ID 20010814.004] pos() doesn't work when using =~m// in list context
2003 $a = join ":", /b./gc;
2004 $b = join ":", /a./gc;
2006 print "$a $b $c" eq 'ba:ba ad:ae 10' ? "ok 684\n" : "not ok 684\t# $a $b $c\n";
2010 # [ID 20010407.006] matching utf8 return values from functions does not work
2012 package ID_20010407_006;
2021 $x =~ /(..)/; $y = $1;
2022 print "not " unless length($y) == 2 && $y eq $x;
2025 x =~ /(..)/; $y = $1;
2026 print "not " unless length($y) == 2 && $y eq $x;
2033 # Force scalar context on the patern match
2035 my($ok, $name) = @_;
2037 printf "%sok %d - %s\n", ($ok ? "" : "not "), $test,
2038 ($name||$Message)."\tLine ".((caller)[2]);
2040 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
2047 # Check that \x## works. 5.6.1 and 5.005_03 fail some of these.
2049 ok ($x =~ /^\x4EE$/, "Check only 2 bytes of hex are matched.");
2052 ok ($x =~ /^\x4Ei$/, "Check that invalid hex digit stops it (2)");
2055 ok ($x =~ /^\x4j$/, "Check that invalid hex digit stops it (1)");
2058 ok ($x =~ /^\xk$/, "Check that invalid hex digit stops it (0)");
2061 ok ($x =~ /^\xx$/, "\\xx isn't to be treated as \\0");
2064 ok ($x =~ /^\xxa$/, "\\xxa isn't to be treated as \\xa");
2067 ok ($x =~ /^\x9_b$/, "\\x9_b isn't to be treated as \\x9b");
2069 print "# and now again in [] ranges\n";
2072 ok ($x =~ /^[\x4EE]{2}$/, "Check only 2 bytes of hex are matched.");
2075 ok ($x =~ /^[\x4Ei]{2}$/, "Check that invalid hex digit stops it (2)");
2078 ok ($x =~ /^[\x4j]{2}$/, "Check that invalid hex digit stops it (1)");
2081 ok ($x =~ /^[\xk]{2}$/, "Check that invalid hex digit stops it (0)");
2084 ok ($x =~ /^[\xx]{2}$/, "\\xx isn't to be treated as \\0");
2087 ok ($x =~ /^[\xxa]{3}$/, "\\xxa isn't to be treated as \\xa");
2090 ok ($x =~ /^[\x9_b]{3}$/, "\\x9_b isn't to be treated as \\x9b");
2095 # Check that \x{##} works. 5.6.1 fails quite a few of these.
2098 ok ($x =~ /^\x{9_b}$/, "\\x{9_b} is to be treated as \\x9b");
2101 ok ($x =~ /^\x{9_b}y$/, "\\x{9_b} is to be treated as \\x9b (again)");
2104 ok ($x =~ /^\x{9b_}y$/, "\\x{9b_} is to be treated as \\x9b");
2107 ok ($x =~ /^\x{9_bq}y$/, "\\x{9_bc} is to be treated as \\x9b");
2110 ok ($x =~ /^\x{x9b}y$/, "\\x{x9b} is to be treated as \\x0");
2113 ok ($x =~ /^\x{0x9b}y$/, "\\x{0x9b} is to be treated as \\x0");
2116 ok ($x =~ /^\x{09b}y$/, "\\x{09b} is to be treated as \\x9b");
2118 print "# and now again in [] ranges\n";
2121 ok ($x =~ /^[\x{9_b}]$/, "\\x{9_b} is to be treated as \\x9b");
2124 ok ($x =~ /^[\x{9_b}y]{2}$/, "\\x{9_b} is to be treated as \\x9b (again)");
2127 ok ($x =~ /^[\x{9b_}y]{2}$/, "\\x{9b_} is to be treated as \\x9b");
2130 ok ($x =~ /^[\x{9_bq}y]{2}$/, "\\x{9_bc} is to be treated as \\x9b");
2133 ok ($x =~ /^[\x{x9b}y]{2}$/, "\\x{x9b} is to be treated as \\x0");
2136 ok ($x =~ /^[\x{0x9b}y]{2}$/, "\\x{0x9b} is to be treated as \\x0");
2139 ok ($x =~ /^[\x{09b}y]{2}$/, "\\x{09b} is to be treated as \\x9b");
2143 # high bit bug -- japhy
2145 $x =~ /.*?\200/ or print "not ";
2149 print "# some Unicode properties\n";
2152 # Dashes, underbars, case.
2153 print "not " unless "\x80" =~ /\p{in-latin1_SUPPLEMENT}/;
2156 # Complement, leading and trailing whitespace.
2157 print "not " unless "\x80" =~ /\P{ ^ In Latin 1 Supplement }/;
2160 # No ^In, dashes, case, dash, any intervening (word-break) whitespace.
2161 # (well, newlines don't work...)
2162 print "not " unless "\x80" =~ /\p{latin-1 supplement}/;
2167 print "not " unless "a" =~ /\pL/;
2170 print "not " unless "a" =~ /\p{IsLl}/;
2173 print "not " if "a" =~ /\p{IsLu}/;
2176 print "not " unless "a" =~ /\p{Ll}/;
2179 print "not " if "a" =~ /\p{Lu}/;
2182 print "not " unless "A" =~ /\pL/;
2185 print "not " unless "A" =~ /\p{IsLu}/;
2188 print "not " if "A" =~ /\p{IsLl}/;
2191 print "not " unless "A" =~ /\p{Lu}/;
2194 print "not " if "A" =~ /\p{Ll}/;
2197 print "not " if "a" =~ /\PL/;
2200 print "not " if "a" =~ /\P{IsLl}/;
2203 print "not " unless "a" =~ /\P{IsLu}/;
2206 print "not " if "a" =~ /\P{Ll}/;
2209 print "not " unless "a" =~ /\P{Lu}/;
2212 print "not " if "A" =~ /\PL/;
2215 print "not " if "A" =~ /\P{IsLu}/;
2218 print "not " unless "A" =~ /\P{IsLl}/;
2221 print "not " if "A" =~ /\P{Lu}/;
2224 print "not " unless "A" =~ /\P{Ll}/;
2230 print "not " if "a" =~ /\p{Common}/;
2233 print "not " unless "1" =~ /\p{Common}/;
2238 print "not " if "a" =~ /\p{Inherited}/;
2241 print "not " unless "\x{300}" =~ /\p{Inherited}/;
2246 # L& and LC are the same
2247 print "not " unless "a" =~ /\p{LC}/ and "a" =~ /\p{L&}/;
2250 print "not " if "1" =~ /\p{LC}/ or "1" =~ /\p{L&}/;
2255 print "not " unless "a" =~ /\p{Lowercase Letter}/;
2258 print "not " if "A" =~ /\p{lowercaseletter}/;
2263 print "not " unless "\x{AC00}" =~ /\p{HangulSyllables}/;
2268 # Script=, Block=, Category=
2270 print "not " unless "\x{0100}" =~ /\p{Script=Latin}/;
2273 print "not " unless "\x{0100}" =~ /\p{Block=LatinExtendedA}/;
2276 print "not " unless "\x{0100}" =~ /\p{Category=UppercaseLetter}/;
2281 print "# the basic character classes and Unicode \n";
2283 # 0100;LATIN CAPITAL LETTER A WITH MACRON;Lu;0;L;0041 0304;;;;N;LATIN CAPITAL LETTER A MACRON;;;0101;
2284 print "not " unless "\x{0100}" =~ /\w/;
2287 # 0660;ARABIC-INDIC DIGIT ZERO;Nd;0;AN;;0;0;0;N;;;;;
2288 print "not " unless "\x{0660}" =~ /\d/;
2291 # 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
2292 print "not " unless "\x{1680}" =~ /\s/;
2297 print "# folding matches and Unicode\n";
2299 print "not " unless "a\x{100}" =~ /A/i;
2302 print "not " unless "A\x{100}" =~ /a/i;
2305 print "not " unless "a\x{100}" =~ /a/i;
2308 print "not " unless "A\x{100}" =~ /A/i;
2311 print "not " unless "\x{101}a" =~ /\x{100}/i;
2314 print "not " unless "\x{100}a" =~ /\x{100}/i;
2317 print "not " unless "\x{101}a" =~ /\x{101}/i;
2320 print "not " unless "\x{100}a" =~ /\x{101}/i;
2323 print "not " unless "a\x{100}" =~ /A\x{100}/i;
2326 print "not " unless "A\x{100}" =~ /a\x{100}/i;
2329 print "not " unless "a\x{100}" =~ /a\x{100}/i;
2332 print "not " unless "A\x{100}" =~ /A\x{100}/i;
2335 print "not " unless "a\x{100}" =~ /[A]/i;
2338 print "not " unless "A\x{100}" =~ /[a]/i;
2341 print "not " unless "a\x{100}" =~ /[a]/i;
2344 print "not " unless "A\x{100}" =~ /[A]/i;
2347 print "not " unless "\x{101}a" =~ /[\x{100}]/i;
2350 print "not " unless "\x{100}a" =~ /[\x{100}]/i;
2353 print "not " unless "\x{101}a" =~ /[\x{101}]/i;
2356 print "not " unless "\x{100}a" =~ /[\x{101}]/i;
2362 use charnames ':full';
2364 print "# LATIN LETTER A WITH GRAVE\n";
2365 my $lower = "\N{LATIN SMALL LETTER A WITH GRAVE}";
2366 my $UPPER = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";
2368 print $lower =~ m/$UPPER/i ? "ok 774\n" : "not ok 774\n";
2369 print $UPPER =~ m/$lower/i ? "ok 775\n" : "not ok 775\n";
2370 print $lower =~ m/[$UPPER]/i ? "ok 776\n" : "not ok 776\n";
2371 print $UPPER =~ m/[$lower]/i ? "ok 777\n" : "not ok 777\n";
2373 print "# GREEK LETTER ALPHA WITH VRACHY\n";
2375 $lower = "\N{GREEK CAPITAL LETTER ALPHA WITH VRACHY}";
2376 $UPPER = "\N{GREEK SMALL LETTER ALPHA WITH VRACHY}";
2378 print $lower =~ m/$UPPER/i ? "ok 778\n" : "not ok 778\n";
2379 print $UPPER =~ m/$lower/i ? "ok 779\n" : "not ok 779\n";
2380 print $lower =~ m/[$UPPER]/i ? "ok 780\n" : "not ok 780\n";
2381 print $UPPER =~ m/[$lower]/i ? "ok 781\n" : "not ok 781\n";
2383 print "# LATIN LETTER Y WITH DIAERESIS\n";
2385 $lower = "\N{LATIN CAPITAL LETTER Y WITH DIAERESIS}";
2386 $UPPER = "\N{LATIN SMALL LETTER Y WITH DIAERESIS}";
2387 print $lower =~ m/$UPPER/i ? "ok 782\n" : "not ok 782\n";
2388 print $UPPER =~ m/$lower/i ? "ok 783\n" : "not ok 783\n";
2389 print $lower =~ m/[$UPPER]/i ? "ok 784\n" : "not ok 784\n";
2390 print $UPPER =~ m/[$lower]/i ? "ok 785\n" : "not ok 785\n";
2395 use charnames ':full';
2397 print "# GREEK CAPITAL LETTER SIGMA vs COMBINING GREEK PERISPOMENI\n";
2399 my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}";
2400 my $char = "\N{COMBINING GREEK PERISPOMENI}";
2402 # Before #13843 this was failing by matching falsely.
2403 print "_:$char:_" =~ m/_:$SIGMA:_/i ? "not ok 786\n" : "ok 786\n";
2409 use charnames ':full';
2411 print "a!" =~ /^(\X)!/ && $1 eq "a" ?
2412 "ok 787\n" : "not ok 787 # $1\n";
2413 print "\xDF!" =~ /^(\X)!/ && $1 eq "\xDF" ?
2414 "ok 788\n" : "not ok 788 # $1\n";
2415 print "\x{100}!" =~ /^(\X)!/ && $1 eq "\x{100}" ?
2416 "ok 789\n" : "not ok 789 # $1\n";
2417 print "\x{100}\x{300}!" =~ /^(\X)!/ && $1 eq "\x{100}\x{300}" ?
2418 "ok 790\n" : "not ok 790 # $1\n";
2419 print "\N{LATIN CAPITAL LETTER E}!" =~ /^(\X)!/ &&
2420 $1 eq "\N{LATIN CAPITAL LETTER E}" ?
2421 "ok 791\n" : "not ok 791 # $1\n";
2422 print "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}!" =~
2424 $1 eq "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}" ?
2425 "ok 792\n" : "not ok 792 # $1\n";
2429 print "#\\C and \\X\n";
2431 print "!abc!" =~ /a\Cc/ ? "ok 793\n" : "not ok 793\n";
2432 print "!abc!" =~ /a\Xc/ ? "ok 794\n" : "not ok 794\n";
2436 print "# FINAL SIGMA\n";
2438 my $SIGMA = "\x{03A3}"; # CAPITAL
2439 my $Sigma = "\x{03C2}"; # SMALL FINAL
2440 my $sigma = "\x{03C3}"; # SMALL
2442 print $SIGMA =~ /$SIGMA/i ? "ok 795\n" : "not ok 795\n";
2443 print $SIGMA =~ /$Sigma/i ? "ok 796\n" : "not ok 796\n";
2444 print $SIGMA =~ /$sigma/i ? "ok 797\n" : "not ok 797\n";
2446 print $Sigma =~ /$SIGMA/i ? "ok 798\n" : "not ok 798\n";
2447 print $Sigma =~ /$Sigma/i ? "ok 799\n" : "not ok 799\n";
2448 print $Sigma =~ /$sigma/i ? "ok 800\n" : "not ok 800\n";
2450 print $sigma =~ /$SIGMA/i ? "ok 801\n" : "not ok 801\n";
2451 print $sigma =~ /$Sigma/i ? "ok 802\n" : "not ok 802\n";
2452 print $sigma =~ /$sigma/i ? "ok 803\n" : "not ok 803\n";
2454 print $SIGMA =~ /[$SIGMA]/i ? "ok 804\n" : "not ok 804\n";
2455 print $SIGMA =~ /[$Sigma]/i ? "ok 805\n" : "not ok 805\n";
2456 print $SIGMA =~ /[$sigma]/i ? "ok 806\n" : "not ok 806\n";
2458 print $Sigma =~ /[$SIGMA]/i ? "ok 807\n" : "not ok 807\n";
2459 print $Sigma =~ /[$Sigma]/i ? "ok 808\n" : "not ok 808\n";
2460 print $Sigma =~ /[$sigma]/i ? "ok 809\n" : "not ok 809\n";
2462 print $sigma =~ /[$SIGMA]/i ? "ok 810\n" : "not ok 810\n";
2463 print $sigma =~ /[$Sigma]/i ? "ok 811\n" : "not ok 811\n";
2464 print $sigma =~ /[$sigma]/i ? "ok 812\n" : "not ok 812\n";
2468 print "# parlez-vous?\n";
2470 use charnames ':full';
2472 print "fran\N{LATIN SMALL LETTER C}ais" =~
2475 "ok 813\n" : "not ok 813\n";
2477 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2479 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2480 "ok 814\n" : "not ok 814\n";
2482 print "fran\N{LATIN SMALL LETTER C}ais" =~
2485 "ok 815\n" : "not ok 815\n";
2487 print "franc\N{COMBINING CEDILLA}ais" =~
2488 /franc\C\Cais/ ? # COMBINING CEDILLA is two bytes when encoded
2489 "ok 816\n" : "not ok 816\n";
2491 print "fran\N{LATIN SMALL LETTER C}ais" =~
2494 "ok 817\n" : "not ok 817\n";
2496 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2498 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2499 "ok 818\n" : "not ok 818\n";
2501 print "franc\N{COMBINING CEDILLA}ais" =~
2503 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2504 "ok 819\n" : "not ok 819\n";
2506 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2507 /fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais/ &&
2508 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2509 "ok 820\n" : "not ok 820\n";
2511 print "franc\N{COMBINING CEDILLA}ais" =~
2512 /franc\N{COMBINING CEDILLA}ais/ &&
2513 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2514 "ok 821\n" : "not ok 821\n";
2516 print "fran\N{LATIN SMALL LETTER C}ais" =~
2517 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2519 "ok 822\n" : "not ok 822\n";
2521 print "fran\N{LATIN SMALL LETTER C}ais" =~
2522 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2524 "ok 823\n" : "not ok 823\n";
2526 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2527 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2528 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2529 "ok 824\n" : "not ok 824\n";
2531 print "franc\N{COMBINING CEDILLA}ais" =~
2532 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2533 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2534 "ok 825\n" : "not ok 825\n";
2538 print "# Does lingering (and useless) UTF8 flag mess up /i matching?\n";
2541 my $regex = "ABcde";
2542 my $string = "abcDE\x{100}";
2544 if ($string =~ m/$regex/i) {
2547 print "not ok 826\n";
2552 my $regex = "ABcde\x{100}";
2553 my $string = "abcDE";
2555 if ($string =~ m/$regex/i) {
2558 print "not ok 827\n";
2563 my $regex = "ABcde\x{100}";
2564 my $string = "abcDE\x{100}";
2567 if ($string =~ m/$regex/i) {
2570 print "not ok 828\n";
2576 print "# more SIGMAs\n";
2578 my $SIGMA = "\x{03A3}"; # CAPITAL
2579 my $Sigma = "\x{03C2}"; # SMALL FINAL
2580 my $sigma = "\x{03C3}"; # SMALL
2582 my $S3 = "$SIGMA$Sigma$sigma";
2584 print ":$S3:" =~ /:(($SIGMA)+):/i && $1 eq $S3 && $2 eq $sigma ?
2585 "ok 829\n" : "not ok 829\n";
2586 print ":$S3:" =~ /:(($Sigma)+):/i && $1 eq $S3 && $2 eq $sigma ?
2587 "ok 830\n" : "not ok 830\n";
2588 print ":$S3:" =~ /:(($sigma)+):/i && $1 eq $S3 && $2 eq $sigma ?
2589 "ok 831\n" : "not ok 831\n";
2591 print ":$S3:" =~ /:(([$SIGMA])+):/i && $1 eq $S3 && $2 eq $sigma ?
2592 "ok 832\n" : "not ok 832\n";
2593 print ":$S3:" =~ /:(([$Sigma])+):/i && $1 eq $S3 && $2 eq $sigma ?
2594 "ok 833\n" : "not ok 833\n";
2595 print ":$S3:" =~ /:(([$sigma])+):/i && $1 eq $S3 && $2 eq $sigma ?
2596 "ok 834\n" : "not ok 834\n";
2600 print "# LATIN SMALL LETTER SHARP S\n";
2602 use charnames ':full';
2606 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /\N{LATIN SMALL LETTER SHARP S}/);
2607 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /\N{LATIN SMALL LETTER SHARP S}/i);
2609 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /[\N{LATIN SMALL LETTER SHARP S}]/);
2610 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i);
2612 ok("ss" =~ /\N{LATIN SMALL LETTER SHARP S}/i);
2613 ok("SS" =~ /\N{LATIN SMALL LETTER SHARP S}/i);
2614 ok("ss" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i);
2615 ok("SS" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i);
2617 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /ss/i);
2618 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /SS/i);
2622 print "# more whitespace: U+0085, U+2028, U+2029\n";
2624 # U+0085 needs to be forced to be Unicode, the \x{100} does that.
2626 print "<\x{100}\x{0085}>" =~ /<\x{100}e>/ ? "ok 845\n" : "not ok 845\n";
2628 print "<\x{100}\x{0085}>" =~ /<\x{100}\s>/ ? "ok 845\n" : "not ok 845\n";
2630 print "<\x{2028}>" =~ /<\s>/ ? "ok 846\n" : "not ok 846\n";
2631 print "<\x{2029}>" =~ /<\s>/ ? "ok 847\n" : "not ok 847\n";
2635 print "# . with /s should work on characters, as opposed to bytes\n";
2637 my $s = "\x{e4}\x{100}";
2639 # This is not expected to match: the point is that
2640 # neither should we get "Malformed UTF-8" warnings.
2641 print $s =~ /\G(.+?)\n/gcs ?
2642 "not ok 848\n" : "ok 848\n";
2646 while ($s =~ /\G(.)/gs) {
2650 print join("", @c) eq $s ? "ok 849\n" : "not ok 849\n";
2652 my $t1 = "Q003\n\n\x{e4}\x{f6}\n\nQ004\n\n\x{e7}"; # test only chars < 256
2654 while ($t1 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2658 my $t2 = $t1 . "\x{100}"; # repeat with a larger char
2660 while ($t2 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2664 print $r1 eq $r2 ? "ok 850\n" : "not ok 850\n";
2668 print "# Unicode lookbehind\n";
2670 print "A\x{100}B" =~ /(?<=A.)B/ ? "ok 851\n" : "not ok 851\n";
2671 print "A\x{200}\x{300}B" =~ /(?<=A..)B/ ? "ok 852\n" : "not ok 852\n";
2672 print "\x{400}AB" =~ /(?<=\x{400}.)B/ ? "ok 853\n" : "not ok 853\n";
2673 print "\x{500\x{600}}B" =~ /(?<=\x{500}.)B/ ? "ok 854\n" : "not ok 854\n";
2677 print "# UTF-8 hash keys and /\$/\n";
2678 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-01/msg01327.html
2681 my $v = substr($u,0,1);
2682 my $w = substr($u,1,1);
2683 my %u = ( $u => $u, $v => $v, $w => $w );
2686 my $m1 = /^\w*$/ ? 1 : 0;
2687 my $m2 = $u{$_}=~/^\w*$/ ? 1 : 0;
2688 print $m1 == $m2 ? "ok $i\n" : "not ok $i # $m1 $m2\n";
2694 print "# [ID 20020124.005]\n";
2697 for my $char ("a", "\x{df}", "\x{100}"){
2698 $x = "$char b $char";
2703 print substr($x,0,1) eq substr($x,-1,1) ?
2704 "ok $i\n" : "not ok $i # debug: $x\n";
2710 print "# SEGV in s/// and UTF-8\n";
2711 $s = "s#\x{100}" x 4;
2713 print $s eq "s \x{100}" x 4 ? "ok 861\n" : "not ok 861\n";
2717 print "# UTF-8 bug (maybe alreayd known?)\n";
2721 $u =~ s/./\x{100}/g;
2722 print $u eq "\x{100}\x{100}\x{100}" ? "ok 862\n" : "not ok 862\n";
2725 $u =~ s/[ao]/\x{100}/g;
2726 print $u eq "f\x{100}\x{100}b\x{100}r" ? "ok 863\n" : "not ok 863\n";
2728 $u =~ s/\x{100}/e/g;
2729 print $u eq "feeber" ? "ok 864\n" : "not ok 864\n";
2733 print "# UTF-8 bug with s///\n";
2734 # check utf8/non-utf8 mixtures
2735 # try to force all float/anchored check combinations
2740 "xx.*$c", "x.*$c$c", "$c.*xx", "$c$c.*x", "xx.*(?=$c)", "(?=$c).*xx",
2742 print "xxx" =~ /$re/ ? "not ok $test\n" : "ok $test\n";
2744 print +($subst = "xxx") =~ s/$re// ? "not ok $test\n" : "ok $test\n";
2747 for my $re ("xx.*$c*", "$c*.*xx") {
2748 print "xxx" =~ /$re/ ? "ok $test\n" : "not ok $test\n";
2750 ($subst = "xxx") =~ s/$re//;
2751 print $subst eq '' ? "ok $test\n" : "not ok $test\t# $subst\n";
2754 for my $re ("xxy*", "y*xx") {
2755 print "xx$c" =~ /$re/ ? "ok $test\n" : "not ok $test\n";
2757 ($subst = "xx$c") =~ s/$re//;
2758 print $subst eq $c ? "ok $test\n" : "not ok $test\n";
2760 print "xy$c" =~ /$re/ ? "not ok $test\n" : "ok $test\n";
2762 print +($subst = "xy$c") =~ /$re/ ? "not ok $test\n" : "ok $test\n";
2765 for my $re ("xy$c*z", "x$c*yz") {
2766 print "xyz" =~ /$re/ ? "ok $test\n" : "not ok $test\n";
2768 ($subst = "xyz") =~ s/$re//;
2769 print $subst eq '' ? "ok $test\n" : "not ok $test\n";
2775 print "# qr/.../x\n";
2778 my $R = qr/ A B C # D E/x;
2780 print eval {"ABCDE" =~ $R} ? "ok $test\n" : "not ok $test\n";
2783 print eval {"ABCDE" =~ m/$R/} ? "ok $test\n" : "not ok $test\n";
2786 print eval {"ABCDE" =~ m/($R)/} ? "ok $test\n" : "not ok $test\n";
2791 print "# illegal Unicode properties\n";
2794 print eval { "a" =~ /\pq / } ? "not ok $test\n" : "ok $test\n";
2797 print eval { "a" =~ /\p{qrst} / } ? "not ok $test\n" : "ok $test\n";
2802 print "# [ID 20020412.005] wrong pmop flags checked when empty pattern\n";
2803 # requires reuse of last successful pattern
2811 printf "not ok %s\t# 'match once' %s on %s iteration\n", $test,
2812 $match ? 'succeeded' : 'failed', $_ ? 'second' : 'first';
2817 my $result = join '', $test =~ //g;
2818 if ($result eq $test) {
2821 printf "not ok %s\t# expected '%s', got '%s'\n", $test, $test, $result;
2826 print "# user-defined character properties\n";
2860 print "\x{3040}" =~ /\p{InKana1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2861 print "\x{303F}" =~ /\P{InKana1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2863 print "\x{3040}" =~ /\p{InKana2}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2864 print "\x{303F}" =~ /\P{InKana2}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2866 print "\x{3041}" =~ /\p{InKana3}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2867 print "\x{3040}" =~ /\P{InKana3}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2869 print "\x{3040}" =~ /\p{InNotKana}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2870 print "\x{3041}" =~ /\P{InNotKana}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2872 sub InConsonant { # Not EBCDIC-aware.
2883 print "d" =~ /\p{InConsonant}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2884 print "e" =~ /\P{InConsonant}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2887 print "# [ID 20020630.002] utf8 regex only matches 32k\n";
2889 for ([ 'byte', "\x{ff}" ], [ 'utf8', "\x{1ff}" ]) {
2890 my($type, $char) = @$_;
2891 for my $len (32000, 32768, 33000) {
2892 my $s = $char . "f" x $len;
2893 my $r = $s =~ /$char([f]*)/gc;
2894 print $r ? "ok $test\n" : "not ok $test\t# <$type x $len> fail\n";
2896 print +(!$r or pos($s) == $len + 1) ? "ok $test\n"
2897 : "not ok $test\t# <$type x $len> pos @{[ pos($s) ]}\n";
2905 $a = bless qr/foo/, 'Foo';
2906 print(('goodfood' =~ $a ? '' : 'not '),
2907 "ok $test\t# reblessed qr// matches\n");
2910 print(($a eq '(?-xism:foo)' ? '' : 'not '),
2911 "ok $test\t# reblessed qr// stringizes\n");
2915 $z=$y = "\317\276"; # $y is byte representation of $x
2918 print(($x =~ $a ? '' : 'not '), "ok $test - utf8 interpolation in qr//\n");
2921 print(("a$a" =~ $x ? '' : 'not '),
2922 "ok $test - stringifed qr// preserves utf8\n");
2925 print(("a$x" =~ /^a$a\z/ ? '' : 'not '),
2926 "ok $test - interpolated qr// preserves utf8\n");
2929 print(("a$x" =~ /^a(??{$a})\z/ ? '' : 'not '),
2930 "ok $test - postponed interpolation of qr// preserves utf8\n");
2933 print((length(qr/##/x) == 12 ? '' : 'not '),
2934 "ok $test - ## in qr// doesn't corrupt memory [perl #17776]\n");
2939 print(("$x$x" =~ /^$x(??{$x})\z/ ? '' : 'not '),
2940 "ok $test - postponed utf8 string in utf8 re matches utf8\n");
2943 print(("$y$x" =~ /^$y(??{$x})\z/ ? '' : 'not '),
2944 "ok $test - postponed utf8 string in non-utf8 re matches utf8\n");
2947 print(("$y$x" !~ /^$y(??{$y})\z/ ? '' : 'not '),
2948 "ok $test - postponed non-utf8 string in non-utf8 re doesn't match utf8\n");
2951 print(("$x$x" !~ /^$x(??{$y})\z/ ? '' : 'not '),
2952 "ok $test - postponed non-utf8 string in utf8 re doesn't match utf8\n");
2955 print(("$y$y" =~ /^$y(??{$y})\z/ ? '' : 'not '),
2956 "ok $test - postponed non-utf8 string in non-utf8 re matches non-utf8\n");
2959 print(("$x$y" =~ /^$x(??{$y})\z/ ? '' : 'not '),
2960 "ok $test - postponed non-utf8 string in utf8 re matches non-utf8\n");
2962 $y = $z; # reset $y after upgrade
2964 print(("$x$y" !~ /^$x(??{$x})\z/ ? '' : 'not '),
2965 "ok $test - postponed utf8 string in utf8 re doesn't match non-utf8\n");
2967 $y = $z; # reset $y after upgrade
2969 print(("$y$y" !~ /^$y(??{$x})\z/ ? '' : 'not '),
2970 "ok $test - postponed utf8 string in non-utf8 re doesn't match non-utf8\n");
2975 print "# more user-defined character properties\n";
2984 ok("\x{0712}" =~ /\p{IsSyriac1}/, '\x{0712}, \p{IsSyriac1}');
2985 ok("\x{072F}" =~ /\P{IsSyriac1}/, '\x{072F}, \P{IsSyriac1}');
2994 ok("\x{0712}" =~ /\p{Syriac1}/, '\x{0712}, \p{Syriac1}');
2995 ok("\x{072F}" =~ /\P{Syriac1}/, '\x{072F}, \p{Syriac1}');
2997 print "# user-defined character properties may lack \\n at the end\n";
2998 sub InGreekSmall { return "03B1\t03C9" }
2999 sub InGreekCapital { return "0391\t03A9\n-03A2" }
3001 ok("\x{03C0}" =~ /\p{InGreekSmall}/, "Small pi");
3002 ok("\x{03C2}" =~ /\p{InGreekSmall}/, "Final sigma");
3003 ok("\x{03A0}" =~ /\p{InGreekCapital}/, "Capital PI");
3004 ok("\x{03A2}" =~ /\P{InGreekCapital}/, "Reserved");
3006 sub AsciiHexAndDash {
3008 +utf8::ASCII_Hex_Digit
3013 ok("-" =~ /\p{Dash}/, "'-' is Dash");
3014 ok("A" =~ /\p{ASCII_Hex_Digit}/, "'A' is ASCII_Hex_Digit");
3015 ok("-" =~ /\p{AsciiHexAndDash}/, "'-' is AsciiHexAndDash");
3016 ok("A" =~ /\p{AsciiHexAndDash}/, "'A' is AsciiHexAndDash");
3019 print "# Change #18179\n";
3020 # previously failed with "panic: end_shift
3021 my $s = "\x{100}" x 5;
3022 my $ok = $s =~ /(\x{100}{4})/;
3023 my($ord, $len) = (ord $1, length $1);
3024 print +($ok && $ord == 0x100 && $len == 4)
3025 ? "ok $test\n" : "not ok $test\t# [#18179] $ok/$ord/$len\n";
3030 print "# [perl #15763]\n";
3033 chop $a; # but leaves the UTF-8 flag
3034 $a .= "y"; # 1 byte before "y"
3036 ok($a =~ /^\C/, 'match one \C on 1-byte UTF-8');
3037 ok($a =~ /^\C{1}/, 'match \C{1}');
3039 ok($a =~ /^\Cy/, 'match \Cy');
3040 ok($a =~ /^\C{1}y/, 'match \C{1}y');
3042 $a = "\x{100}y"; # 2 bytes before "y"
3044 ok($a =~ /^\C/, 'match one \C on 2-byte UTF-8');
3045 ok($a =~ /^\C{1}/, 'match \C{1}');
3046 ok($a =~ /^\C\C/, 'match two \C');
3047 ok($a =~ /^\C{2}/, 'match \C{2}');
3049 ok($a =~ /^\C\C\C/, 'match three \C on 2-byte UTF-8 and a byte');
3050 ok($a =~ /^\C{3}/, 'match \C{3}');
3052 ok($a =~ /^\C\Cy/, 'match two \C');
3053 ok($a =~ /^\C{2}y/, 'match \C{2}');
3055 ok($a !~ /^\C\C\Cy/, q{don't match three \Cy});
3056 ok($a !~ /^\C{2}\Cy/, q{don't match \C{3}y});
3058 $a = "\x{1000}y"; # 3 bytes before "y"
3060 ok($a =~ /^\C/, 'match one \C on three-byte UTF-8');
3061 ok($a =~ /^\C{1}/, 'match \C{1}');
3062 ok($a =~ /^\C\C/, 'match two \C');
3063 ok($a =~ /^\C{2}/, 'match \C{2}');
3064 ok($a =~ /^\C\C\C/, 'match three \C');
3065 ok($a =~ /^\C{3}/, 'match \C{3}');
3067 ok($a =~ /^\C\C\C\C/, 'match four \C on three-byte UTF-8 and a byte');
3068 ok($a =~ /^\C{4}/, 'match \C{4}');
3070 ok($a =~ /^\C\C\Cy/, 'match three \Cy');
3071 ok($a =~ /^\C{3}y/, 'match \C{3}y');
3073 ok($a !~ /^\C\C\C\C\y/, q{don't match four \Cy});
3074 ok($a !~ /^\C{4}y/, q{don't match \C{4}y});
3078 utf8::upgrade($_); chop $_; $\="\n";
3079 ok(/[^\s]+/, "m/[^\s]/ utf8");
3080 ok(/[^\d]+/, "m/[^\d]/ utf8");
3081 ok(($a = $_, $_ =~ s/[^\s]+/./g), "s/[^\s]/ utf8");
3082 ok(($a = $_, $a =~ s/[^\d]+/./g), "s/[^\s]/ utf8");
3084 ok("\x{100}" =~ /\x{100}/, "[perl #15397]");
3085 ok("\x{100}" =~ /(\x{100})/, "[perl #15397]");
3086 ok("\x{100}" =~ /(\x{100}){1}/, "[perl #15397]");
3087 ok("\x{100}\x{100}" =~ /(\x{100}){2}/, "[perl #15397]");
3088 ok("\x{100}\x{100}" =~ /(\x{100})(\x{100})/, "[perl #15397]");
3092 ok(!defined $1, "[perl #7471]");
3096 ok(!defined $1, "[perl #7471]");
3098 $pattern = "^(b+?|a){1,2}c";
3099 ok("bac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3100 ok("bbac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3101 ok("bbbac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3102 ok("bbbbac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3107 ok( $1 eq "\x{100}", '$1 is utf-8 [perl #18232]' );
3109 ok( $1 eq "\x{100}", '$1 is still utf-8' );
3110 ok( $1 ne "\xC4\x80", '$1 is not non-utf-8' );
3115 my $attr = 'Name-1' ;
3117 my $NormalChar = qr/[\p{IsDigit}\p{IsLower}\p{IsUpper}]/;
3118 my $NormalWord = qr/${NormalChar}+?/;
3119 my $PredNameHyphen = qr/^${NormalWord}(\-${NormalWord})*?$/;
3122 ok( $attr =~ $PredNameHyphen, "[perl #19767] original test" );
3128 ok ( "0" =~ /\p{N}+\z/, "[perl #19767] variant test" );
3135 $p++ if /(??{ $p })/
3137 ok ($p == 5, "[perl #20683] (??{ }) returns stale values");
3138 { package P; $a=1; sub TIESCALAR { bless[] } sub FETCH { $a++ } }
3143 ok ( $p == 5, "(??{ }) returns stale values");
3147 # Subject: Odd regexp behavior
3148 # From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
3149 # Date: Wed, 26 Feb 2003 16:53:12 +0000
3150 # Message-Id: <E18o4nw-0008Ly-00@wisbech.cl.cam.ac.uk>
3151 # To: perl-unicode@perl.org
3153 $x = "\x{2019}\nk"; $x =~ s/(\S)\n(\S)/$1 $2/sg;
3154 ok($x eq "\x{2019} k", "Markus Kuhn 2003-02-26");
3156 $x = "b\nk"; $x =~ s/(\S)\n(\S)/$1 $2/sg;
3157 ok($x eq "b k", "Markus Kuhn 2003-02-26");
3159 ok("\x{2019}" =~ /\S/, "Markus Kuhn 2003-02-26");
3164 ok('-1-3-5-' eq join('', split /((??{$i++}))/, '-1-3-5-'),
3165 "[perl #21411] (??{ .. }) corrupts split's stack");
3166 split /(?{'WOW'})/, 'abc';
3167 ok('a|b|c' eq join ('|', @_),
3168 "[perl #21411] (?{ .. }) version of the above");
3172 # XXX DAPM 13-Apr-06. Recursive split is still broken. It's only luck it
3173 # hasn't been crashing. Disable this test until it is fixed properly.
3174 # XXX also check what it returns rather than just doing ok(1,...)
3175 # split /(?{ split "" })/, "abc";
3176 ok(1,'cache_re & "(?{": it dumps core in 5.6.1 & 5.8.0');
3180 ok("\x{100}\n" =~ /\x{100}\n$/, "UTF8 length cache and fbm_compile");
3185 use overload q/""/ => sub { ${$_[0]}; };
3186 sub new { my ($c, $v) = @_; bless \$v, $c; }
3189 $_ = Str->new("a\x{100}/\x{100}b");
3190 ok(join(":", /\b(.)\x{100}/g) eq "a:/", "re_intuit_start and PL_bostr");
3194 $_ = "code: 'x' { '...' }\n"; study;
3195 my @x; push @x, $& while m/'[^\']*'/gx;
3196 ok(join(":", @x) eq "'x':'...'",
3197 "[perl #17757] Parse::RecDescent triggers infinite loop");
3201 my $re = qq/^([^X]*)X/;
3203 ok("\x{100}X" =~ /$re/, "S_cl_and ANYOF_UNICODE & ANYOF_INVERTED");
3208 ok( "a\nb" !~ /^b/, $_[0] );
3209 ok( "a\nb" =~ /^b/m, "$_[0] - with /m" );
3212 $_ = "x"; s/x/func "in subst"/e;
3213 $_ = "x"; s/x/func "in multiline subst"/em;
3214 #$_ = "x"; /x(?{func "in regexp"})/;
3215 #$_ = "x"; /x(?{func "in multiline regexp"})/m;
3220 ok("abcde" eq "$`", 'RT#19049 - global match not setting $`');
3222 ok("123\x{100}" =~ /^.*1.*23\x{100}$/, 'uft8 + multiple floating substr');
3224 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
3225 ok(" \x{101}" =~ qr/\x{100}/i,
3226 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3228 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
3229 ok(" \x{1E01}" =~ qr/\x{1E00}/i,
3230 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3232 # DESERET SMALL/CAPITAL LETTER LONG I
3233 ok(" \x{10428}" =~ qr/\x{10400}/i,
3234 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3236 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
3237 ok(" \x{1E01}x" =~ qr/\x{1E00}X/i,
3238 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3241 # [perl #23769] Unicode regex broken on simple example
3242 # regrepeat() didn't handle UTF-8 EXACT case right.
3244 my $s = "\x{a0}\x{a0}\x{a0}\x{100}"; chop $s;
3246 ok($s =~ /\x{a0}/, "[perl #23769]");
3247 ok($s =~ /\x{a0}+/, "[perl #23769]");
3248 ok($s =~ /\x{a0}\x{a0}/, "[perl #23769]");
3250 ok("aaa\x{100}" =~ /(a+)/, "[perl #23769] easy invariant");
3251 ok($1 eq "aaa", "[perl #23769]");
3253 ok("\xa0\xa0\xa0\x{100}" =~ /(\xa0+)/, "[perl #23769] regrepeat invariant");
3254 ok($1 eq "\xa0\xa0\xa0", "[perl #23769]");
3256 ok("ababab\x{100} " =~ /((?:ab)+)/, "[perl #23769] hard invariant");
3257 ok($1 eq "ababab", "[perl #23769]");
3259 ok("\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+)/, "[perl #23769] hard variant");
3260 ok($1 eq "\xa0\xa1\xa0\xa1\xa0\xa1", "[perl #23769]");
3262 ok("aaa\x{100} " =~ /(a+?)/, "[perl #23769] easy invariant");
3263 ok($1 eq "a", "[perl #23769]");
3265 ok("\xa0\xa0\xa0\x{100} " =~ /(\xa0+?)/, "[perl #23769] regrepeat variant");
3266 ok($1 eq "\xa0", "[perl #23769]");
3268 ok("ababab\x{100} " =~ /((?:ab)+?)/, "[perl #23769] hard invariant");
3269 ok($1 eq "ab", "[perl #23769]");
3271 ok("\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+?)/, "[perl #23769] hard variant");
3272 ok($1 eq "\xa0\xa1", "[perl #23769]");
3274 ok("\xc4\xc4\xc4" !~ /(\x{100}+)/, "[perl #23769] don't match first byte of utf8 representation");
3275 ok("\xc4\xc4\xc4" !~ /(\x{100}+?)/, "[perl #23769] don't match first byte of utf8 representation");
3279 my $head = 'x' x $_;
3280 for my $tail ('\x{0061}', '\x{1234}') {
3282 eval qq{ "$head$tail" =~ /$head$tail/ },
3283 '\x{...} misparsed in regexp near 127 char EXACT limit'
3288 # perl #25269: panic: pp_match start/end pointers
3290 my($x, $y) = "bca" =~ /^(?=.*(a)).*(bc)/;
3292 }, 'captures can move backwards in string');
3294 # perl #27940: \cA not recognized in character classes
3295 ok("a\cAb" =~ /\cA/, '\cA in pattern');
3296 ok("a\cAb" =~ /[\cA]/, '\cA in character class');
3297 ok("a\cAb" =~ /[\cA-\cB]/, '\cA in character class range');
3298 ok("abc" =~ /[^\cA-\cB]/, '\cA in negated character class range');
3299 ok("a\cBb" =~ /[\cA-\cC]/, '\cB in character class range');
3300 ok("a\cCbc" =~ /[^\cA-\cB]/, '\cC in negated character class range');
3301 ok("a\cAb" =~ /(??{"\cA"})/, '\cA in ??{} pattern');
3302 ok("ab" !~ /a\cIb/x, '\cI in pattern');
3304 # perl #28532: optional zero-width match at end of string is ignored
3305 ok(("abc" =~ /^abc(\z)?/) && defined($1),
3306 'optional zero-width match at end of string');
3307 ok(("abc" =~ /^abc(\z)??/) && !defined($1),
3308 'optional zero-width match at end of string');
3314 "words"=~/(word|word|word)(?{push @got,$1})s$/;
3315 ok(@got==1,"TRIE optimation is working") or warn "# @got";
3317 "words"=~/(word|word|word)(?{push @got,$1})s$/i;
3318 ok(@got==1,"TRIEF optimisation is working") or warn "# @got";
3320 my @nums=map {int rand 1000} 1..100;
3321 my $re="(".(join "|",@nums).")";
3325 ok($_=~/$re/,"Trie nums");
3329 push @got,$1 while /$re/g;
3332 $count{$_}++ for @got;
3335 $ok=0 if --$count{$_}<0;
3337 ok($ok,"Trie min count matches");
3342 # LATIN SMALL/CAPITAL LETTER A WITH MACRON
3343 ok(("foba \x{101}foo" =~ qr/(foo|\x{100}foo|bar)/i) && $1 eq "\x{101}foo",
3344 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH MACRON");
3346 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
3347 ok(("foba \x{1E01}foo" =~ qr/(foo|\x{1E00}foo|bar)/i) && $1 eq "\x{1E01}foo",
3348 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW");
3350 # DESERET SMALL/CAPITAL LETTER LONG I
3351 ok(("foba \x{10428}foo" =~ qr/(foo|\x{10400}foo|bar)/i) && $1 eq "\x{10428}foo",
3352 "TRIEF + DESERET SMALL/CAPITAL LETTER LONG I");
3354 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
3355 ok(("foba \x{1E01}xfoo" =~ qr/(foo|\x{1E00}Xfoo|bar)/i) && $1 eq "\x{1E01}xfoo",
3356 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'");
3360 use charnames ':full';
3362 $s="\N{LATIN SMALL LETTER SHARP S}";
3363 ok(("foba ba$s" =~ qr/(foo|Ba$s|bar)/i)
3365 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3366 ok(("foba ba$s" =~ qr/(Ba$s|foo|bar)/i)
3368 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3369 ok(("foba ba$s" =~ qr/(foo|bar|Ba$s)/i)
3371 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3373 ok(("foba ba$s" =~ qr/(foo|Bass|bar)/i)
3375 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3377 ok(("foba ba$s" =~ qr/(foo|BaSS|bar)/i)
3379 "TRIEF + LATIN SMALL LETTER SHARP S =~ SS");
3381 ok(("foba ba${s}pxySS$s$s" =~ qr/(b(?:a${s}t|a${s}f|a${s}p)[xy]+$s*)/i)
3382 && $1 eq "ba${s}pxySS$s$s",
3383 "COMMON PREFIX TRIEF + LATIN SMALL LETTER SHARP S");
3390 if (!$ENV{PERL_SKIP_PSYCHO_TEST}){
3391 my @normal=qw(these are some normal words);
3392 my $psycho=join "|",@normal,map chr $_,255..20000;
3393 ok(('these'=~/($psycho)/) && $1 eq 'these','Pyscho');
3395 ok(1,'Skipped Psycho');
3398 # [perl #36207] mixed utf8 / latin-1 and case folding
3401 my $utf8 = "\xe9\x{100}"; chop $utf8;
3402 my $latin1 = "\xe9";
3404 ok($utf8 =~ /\xe9/i, "utf8/latin");
3405 ok($utf8 =~ /$latin1/i, "utf8/latin runtime");
3406 ok($utf8 =~ /(abc|\xe9)/i, "utf8/latin trie");
3407 ok($utf8 =~ /(abc|$latin1)/i, "utf8/latin trie runtime");
3409 ok("\xe9" =~ /$utf8/i, "# TODO latin/utf8");
3410 ok("\xe9" =~ /(abc|$utf8)/i, "# latin/utf8 trie");
3411 ok($latin1 =~ /$utf8/i, "# TODO latin/utf8 runtime");
3412 ok($latin1 =~ /(abc|$utf8)/i, "# latin/utf8 trie runtime");
3415 # [perl #37038] Global regular matches generate invalid pointers
3423 "# assigning to original string should not corrupt match vars");
3433 my $aeek = bless {}, 'wooosh';
3434 eval {$aeek->gloople() =~ /(.)/g;};
3435 ok($@ eq "", "//g match against return value of sub") or print "# $@\n";
3442 eval {gloople() =~ /(.)/g;};
3443 ok($@ eq "", "# 26410 didn't affect sub calls for some reason")
3450 sub variable : lvalue { $var }
3453 my $o = bless [], "lv";
3455 eval { for (1..2) { $f .= $1 if $o->variable =~ /(.)/g } };
3456 ok($f eq "ab", "pos retained between calls # TODO") or print "# $@\n";
3461 sub variable : lvalue { $var }
3464 eval { for (1..2) { $f .= $1 if variable() =~ /(.)/g } };
3465 ok($f eq "ab", "pos retained between calls # TODO") or print "# $@\n";
3468 # [perl #37836] Simple Regex causes SEGV when run on specific data
3470 print "ok $test # Skip: in EBCDIC\n"; $test++;
3473 $_ = pack('U0C2', 0xa2, 0xf8); # ill-formed UTF-8
3475 eval { $ret = s/[\0]+//g };
3476 ok($ret == 0, "ill-formed UTF-8 doesn't match NUL in class");
3479 { # [perl #38293] chr(65535) should be allowed in regexes
3480 no warnings 'utf8'; # to allow non-characters
3485 ok($c eq "", "U+FFFF, parsed as atom");
3490 ok($c eq "", "U+FFFF backslashed, parsed as atom");
3494 ok($c eq "", "U+FFFF, parsed in class");
3499 ok($c eq "", "U+FFFF backslashed, parsed in class");
3502 $s =~ s/\x{ffff}//i;
3503 ok($s eq "AB", "U+FFFF, EXACTF");
3507 ok($s eq "\x{ffff}", "U+FFFF, BOUND");
3511 ok($s eq "\x{ffff}", "U+FFFF, NBOUND");
3512 } # non-characters end
3515 # https://rt.perl.org/rt3/Ticket/Display.html?id=39583
3517 # The printing characters
3518 my @chars = ("A".."Z");
3520 my $size = 32771 - 4;
3523 # create some random junk. Inefficient, but it works.
3524 for ($i = 0 ; $i < $size ; $i++) {
3525 $str .= $chars[int(rand(@chars))];
3528 $str .= ($delim x 4);
3531 if ($str =~ s/^(.*?)${delim}{4}//s) {
3535 ok($matched,'pattern matches');
3536 ok(length($str)==0,"Empty string");
3537 ok(defined($res) && length($res)==$size,"\$1 is correct size");
3540 { # related to [perl #27940]
3541 ok("\0-A" =~ /\c@-A/, '@- should not be interpolated in a pattern');
3542 ok("\0\0A" =~ /\c@+A/, '@+ should not be interpolated in a pattern');
3543 ok("X\@-A" =~ /X@-A/, '@- should not be interpolated in a pattern');
3544 ok("X\@\@A" =~ /X@+A/, '@+ should not be interpolated in a pattern');
3546 ok("X\0A" =~ /X\c@?A/, '\c@?');
3547 ok("X\0A" =~ /X\c@*A/, '\c@*');
3548 ok("X\0A" =~ /X\c@(A)/, '\c@(');
3549 ok("X\0A" =~ /X(\c@)A/, '\c@)');
3550 ok("X\0A" =~ /X\c@|ZA/, '\c@|');
3552 ok("X\@A" =~ /X@?A/, '@?');
3553 ok("X\@A" =~ /X@*A/, '@*');
3554 ok("X\@A" =~ /X@(A)/, '@(');
3555 ok("X\@A" =~ /X(@)A/, '@)');
3556 ok("X\@A" =~ /X@|ZA/, '@|');
3558 local $" = ','; # non-whitespace and non-RE-specific
3559 ok('abc' =~ /(.)(.)(.)/, 'the last successful match is bogus');
3560 ok("A@+B" =~ /A@{+}B/, 'interpolation of @+ in /@{+}/');
3561 ok("A@-B" =~ /A@{-}B/, 'interpolation of @- in /@{-}/');
3562 ok("A@+B" =~ /A@{+}B/x, 'interpolation of @+ in /@{+}/x');
3563 ok("A@-B" =~ /A@{-}B/x, 'interpolation of @- in /@{-}/x');
3570 ok('fooB'=~/\N{foo}[\N{B}\N{b}]/,"Passthrough charname");
3571 $test=1233; my $handle=make_must_warn('Ignoring excess chars from');
3572 $handle->('q(xxWxx) =~ /[\N{WARN}]/');
3576 local $SIG{__WARN__} = sub { $w.=shift };
3577 eval($code=<<'EOFTEST') or die "$@\n$code\n";
3582 ok("\0" !~ /[\N{EMPTY-STR}XY]/,
3583 "Zerolength charname in charclass doesnt match \0");
3587 ok($w=~/Ignoring zero length/,
3588 "Got expected zero length warning");
3592 $handle= make_must_warn('Ignoring zero length');
3593 $handle->('qq(\\0) =~ /[\N{EMPTY-STR}XY]/');
3594 ok('AB'=~/(\N{EVIL})/ && $1 eq 'A',"Charname caching $1");
3595 ok('ABC'=~/(\N{EVIL})/,"Charname caching $1");
3596 ok('xy'=~/x\N{EMPTY-STR}y/, 'Empty string charname produces NOTHING node');
3597 ok(''=~/\N{EMPTY-STR}/, 'Empty string charname produces NOTHING node 2');
3601 print "# MORE LATIN SMALL LETTER SHARP S\n";
3603 use charnames ':full';
3606 ok("ss" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i,
3607 "unoptimized named sequence in class 1");
3608 ok("SS" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i,
3609 "unoptimized named sequence in class 2");
3610 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/,
3611 "unoptimized named sequence in class 3");
3612 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i,
3613 "unoptimized named sequence in class 4");
3615 ok('aabc' !~ /a\N{PLUS SIGN}b/,'/a\N{PLUS SIGN}b/ against aabc');
3616 ok('a+bc' =~ /a\N{PLUS SIGN}b/,'/a\N{PLUS SIGN}b/ against a+bc');
3617 ok('a+bc' =~ /a\N{PLUS SIGN}b/,'/a\N{PLUS SIGN}b/ against a+bc');
3619 ok(' A B'=~/\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
3620 'Intermixed named and unicode escapes 1');
3621 ok("\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}"=~
3622 /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
3623 'Intermixed named and unicode escapes 2');
3624 ok("\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042} 3"=~
3625 /[\N{SPACE}\N{U+0041}][\N{SPACE}\N{U+0042}]/,
3626 'Intermixed named and unicode escapes');
3629 { (?> [^{}]+ | (??{ $brackets }) )* }
3631 ok("{b{c}d" !~ m/^((??{ $brackets }))/, "bracket mismatch");
3643 <<stuff1>and<stuff2>><<<<right>>>>
3646 local $_='<<<stuff1>and<stuff2>><<<<right>>>>>';
3647 ok(/^(<((?:(?>[^<>]+)|(?1))*)>(?{push @stack, $2 }))$/,
3648 "Recursion should match");
3650 or skip("Won't test individual results as count isn't equal",
3652 foreach my $idx (@expect) {
3653 ok($expect[$idx] eq $stack[$idx],
3654 "Expecting '$expect' at stack pos #$idx");
3660 $s=~s/(?<digits>\d+)\k<digits>/$+{digits}/;
3661 ok($s eq '123456','Named capture (angle brackets) s///');
3663 $s=~s/(?'digits'\d+)\k'digits'/$+{digits}/;
3664 ok($s eq '123456','Named capture (single quotes) s///');
3669 pack('U', 0x00F1), # n-tilde
3670 '_'.pack('U', 0x00F1), # _ + n-tilde
3671 'c'.pack('U', 0x0327), # c + cedilla
3672 pack('U*', 0x00F1, 0x0327), # n-tilde + cedilla
3673 'a'.pack('U', 0x00B2), # a + superscript two
3674 pack('U', 0x0391), # ALPHA
3675 pack('U', 0x0391).'2', # ALPHA + 2
3676 pack('U', 0x0391).'_', # ALPHA + _
3678 for my $uni (@ary) {
3679 my ($r1, $c1, $r2, $c2) = eval qq{
3681 scalar("..foo foo.." =~ /(?'${uni}'foo) \\k'${uni}'/),
3683 scalar("..bar bar.." =~ /(?<${uni}>bar) \\k<${uni}>/),
3686 ok($r1, "Named capture UTF (?'')");
3687 ok(defined $c1 && $c1 eq 'foo', "Named capture UTF \%+");
3688 ok($r2, "Named capture UTF (?<>)");
3689 ok(defined $c2 && $c2 eq 'bar', "Named capture UTF \%+");
3694 my ( $got, $expect, $name)=@_;
3696 $_=defined($_) ? "'$_'" : "undef"
3699 my $ok= $got eq $expect;
3701 printf "%sok %d - %s\n", ($ok ? "" : "not "), $test,
3702 ($name||$Message)."\tLine ".((caller)[2]);
3704 printf "# Failed test at line %d\n".
3707 (caller)[2], $expect, $got
3714 my $s='foo bar baz';
3715 my (@k,@v,@fetch,$res);
3717 my @names=qw($+{A} $+{B} $+{C});
3718 if ($s=~/(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz)/) {
3719 while (my ($k,$v)=each(%+)) {
3733 iseq($fetch[$_][0],$fetch[$_][1],$names[$_]);
3738 iseq($res,1,"$s~=/(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz)/");
3739 iseq($count,3,"Got 3 keys in %+ via each");
3740 iseq(0+@k, 3, 'Got 3 keys in %+ via keys');
3741 iseq("@k","A B C", "Got expected keys");
3742 iseq("@v","bar baz foo", "Got expected values");
3744 print for $+{this_key_doesnt_exist};
3746 ok(!$@,'lvalue $+{...} should not throw an exception');
3749 my $s='foo bar baz';
3751 if ('1234'=~/(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) {
3752 foreach my $name (sort keys(%-)) {
3753 my $ary = $-{$name};
3754 foreach my $idx (0..$#$ary) {
3755 push @res,"$name:$idx:$ary->[$idx]";
3759 my @expect=qw(A:0:1 A:1:3 B:0:2 B:1:4);
3760 iseq("@res","@expect","Check %-");
3762 print for $-{this_key_doesnt_exist};
3764 ok(!$@,'lvalue $-{...} should not throw an exception');
3766 # stress test CURLYX/WHILEM.
3768 # This test includes varying levels of nesting, and according to
3769 # profiling done against build 28905, exercises every code line in the
3770 # CURLYX and WHILEM blocks, except those related to LONGJMP, the
3771 # super-linear cache and warnings. It executes about 0.5M regexes
3773 if ($ENV{PERL_SKIP_PSYCHO_TEST}){
3774 printf "ok %d Skip: No psycho tests\n", $test++;
3811 my $msg = "CURLYX stress test";
3813 for my $a ("x","a","aa") {
3814 for my $b ("x","bbb","bbbb") {
3816 for my $c ("x","c","cc") {
3818 for my $d ("x","d","dd") {
3820 for my $e ("x","e","ee") {
3822 for my $f ("x","f","ff") {
3824 for my $g ("x","g","gg") {
3826 for my $h ("x","h","hh") {
3828 for my $i ("x","i","ii") {
3830 for my $j ("x","j","jj") {
3832 for my $k ("x","k","kk") {
3834 for my $l ("x","l","ll") {
3838 $msg .= ": unexpected match for [$ls]";
3842 my $cap = "$1$2$3$4$5$6$7$8$9$10$11$12";
3843 unless ($ls eq $cap) {
3844 $msg .= ": capture: [$ls], got [$cap]";
3850 unless ($ls =~ /x/) {
3851 $msg = ": failed for [$ls]";
3872 ok("xaaay" !~ /xa{3\,4}y/, "\, in a pattern");
3873 ok("xa{3,4}y" =~ /xa{3\,4}y/, "\, in a pattern");
3876 ok("x\c_y" !~ /x\c\_y/, "\_ in a pattern");
3877 ok("x\c\_y" =~ /x\c\_y/, "\_ in a pattern");
3879 # \c\ followed by other characters
3880 for my $c ("z", "\0", "!", chr(254), chr(256)) {
3881 my $targ = "a\034$c";
3882 my $reg = "a\\c\\$c";
3883 ok(eval("qq/$targ/ =~ /$reg/"), "\\c\\ in pattern");
3891 while ($str=~/b/g) { $mval=$#-; $pval=$#+; $count++ }
3892 iseq($mval,0,"\@- should be empty [RT#36046]");
3893 iseq($pval,0,"\@+ should be empty [RT#36046]");
3894 iseq($count,1,"should have matched once only [RT#36046]");
3897 { # Test the (*PRUNE) pattern
3899 'aaab'=~/a+b?(?{$count++})(*FAIL)/;
3900 iseq($count,9,"expect 9 for no (*PRUNE)");
3902 'aaab'=~/a+b?(*PRUNE)(?{$count++})(*FAIL)/;
3903 iseq($count,3,"expect 3 with (*PRUNE)");
3906 1 while /.(*PRUNE)(?{$count++})(*FAIL)/g;
3907 iseq($count,4,"/.(*PRUNE)/");
3909 'aaab'=~/a+b?(??{'(*PRUNE)'})(?{$count++})(*FAIL)/;
3910 iseq($count,3,"expect 3 with (*PRUNE)");
3913 1 while /.(??{'(*PRUNE)'})(?{$count++})(*FAIL)/g;
3914 iseq($count,4,"/.(*PRUNE)/");
3916 { # Test the \v form of the (*PRUNE) pattern
3918 'aaab'=~/a+b?(?{$count++})(*FAIL)/;
3919 iseq($count,9,"expect 9 for no \\v");
3921 'aaab'=~/a+b?\v(?{$count++})(*FAIL)/;
3922 iseq($count,3,"expect 3 with \\v");
3925 1 while /.\v(?{$count++})(*FAIL)/g;
3926 iseq($count,4,"/.\\v/");
3928 'aaab'=~/a+b?(??{'\v'})(?{$count++})(*FAIL)/;
3929 iseq($count,3,"expect 3 with \\v");
3932 1 while /.(??{'\v'})(?{$count++})(*FAIL)/g;
3933 iseq($count,4,"/.\\v/");
3935 { # Test the (*SKIP) pattern
3937 'aaab'=~/a+b?(*SKIP)(?{$count++})(*FAIL)/;
3938 iseq($count,1,"expect 1 with (*SKIP)");
3941 1 while /.(*SKIP)(?{$count++})(*FAIL)/g;
3942 iseq($count,4,"/.(*SKIP)/");
3946 1 while /(a+b?)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
3947 iseq($count,2,"Expect 2 with (*SKIP)" );
3948 iseq("@res","aaab aaab","adjacent (*SKIP) works as expected" );
3950 { # Test the \V form of the (*SKIP) pattern
3952 'aaab'=~/a+b?\V(?{$count++})(*FAIL)/;
3953 iseq($count,1,"expect 1 with \\V");
3956 1 while /.\V(?{$count++})(*FAIL)/g;
3957 iseq($count,4,"/.\\V/");
3961 1 while /(a+b?)\V(?{$count++; push @res,$1})(*FAIL)/g;
3962 iseq($count,2,"Expect 2 with \\V" );
3963 iseq("@res","aaab aaab","adjacent \\V works as expected" );
3965 { # Test the (*SKIP) pattern
3967 'aaab'=~/a+b?(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/;
3968 iseq($count,1,"expect 1 with (*SKIP)");
3971 1 while /.(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/g;
3972 iseq($count,4,"/.(*SKIP)/");
3976 1 while /(a+b?)(*MARK:foo)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
3977 iseq($count,2,"Expect 2 with (*SKIP)" );
3978 iseq("@res","aaab aaab","adjacent (*SKIP) works as expected" );
3980 { # Test the (*SKIP) pattern
3982 'aaab'=~/a*(*MARK:a)b?(*MARK:b)(*SKIP:a)(?{$count++})(*FAIL)/;
3983 iseq($count,3,"expect 3 with *MARK:a)b?(*MARK:b)(*SKIP:a)");
3984 local $_='aaabaaab';
3987 1 while /(a*(*MARK:a)b?)(*MARK:x)(*SKIP:a)(?{$count++; push @res,$1})(*FAIL)/g;
3988 iseq($count,5,"Expect 5 with (*MARK:a)b?)(*MARK:x)(*SKIP:a)" );
3989 iseq("@res","aaab b aaab b ","adjacent (*MARK:a)b?)(*MARK:x)(*SKIP:a) works as expected" );
3991 { # Test the (*COMMIT) pattern
3993 'aaabaaab'=~/a+b?(*COMMIT)(?{$count++})(*FAIL)/;
3994 iseq($count,1,"expect 1 with (*COMMIT)");
3997 1 while /.(*COMMIT)(?{$count++})(*FAIL)/g;
3998 iseq($count,1,"/.(*COMMIT)/");
4002 1 while /(a+b?)(*COMMIT)(?{$count++; push @res,$1})(*FAIL)/g;
4003 iseq($count,1,"Expect 1 with (*COMMIT)" );
4004 iseq("@res","aaab","adjacent (*COMMIT) works as expected" );
4007 # Test named commits and the $REGERROR var
4009 for my $name ('',':foo')
4011 for my $pat ("(*PRUNE$name)",
4012 ($name? "(*MARK$name)" : "")
4016 for my $suffix ('(*FAIL)','')
4018 'aaaab'=~/a+b$pat$suffix/;
4021 ($suffix ? ($name ? 'foo' : "1") : ""),
4022 "Test $pat and \$REGERROR $suffix"
4029 # Test named commits and the $REGERROR var
4032 for my $name ('',':foo')
4034 for my $pat ("(*PRUNE$name)",
4035 ($name? "(*MARK$name)" : "")
4039 for my $suffix ('(*FAIL)','')
4041 'aaaab'=~/a+b$pat$suffix/;
4044 ($suffix ? ($name ? 'foo' : "1") : ""),
4045 "Test $pat and \$REGERROR $suffix"
4052 # Test named commits and the $REGERROR var
4053 local $Message = "\$REGERROR";
4055 for $word (qw(bar baz bop)) {
4057 "aaaaa$word"=~/a+(?:bar(*COMMIT:bar)|baz(*COMMIT:baz)|bop(*COMMIT:bop))(*FAIL)/;
4058 iseq($REGERROR,$word);
4061 { #Regression test for perlbug 40684
4062 local $Message = "RT#40684 tests:";
4064 my $rex = qr'^abc$'m;
4066 ok($s =~ m/^abc$/m);
4069 #Mindnumbingly simple test of (*THEN)
4071 ok(/A (*THEN) X | B (*THEN) C/x,"Simple (*THEN) test");
4076 local $Message = "Relative Recursion";
4077 my $parens=qr/(\((?:[^()]++|(?-1))*+\))/;
4078 local $_='foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))';
4079 my ($all,$one,$two)=('','','');
4080 if (/foo $parens \s* \+ \s* bar $parens/x) {
4085 iseq($one, '((2*3)+4-3)');
4086 iseq($two, '(2*(3+4)-1*(2-3))');
4087 iseq($all, 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))');
4092 local $_=join 'bar',$spaces,$spaces;
4094 s/(?>\s+bar)(?{$count++})//g;
4095 iseq($_,$spaces,"SUSPEND final string");
4096 iseq($count,1,"Optimiser should have prevented more than one match");
4099 local $Message = "RT#36909 test";
4103 ok('x foofoo y' =~ m{
4104 (foo) # $^R correctly set
4105 (?{ "last regexp code result" })
4107 iseq($^R,'last regexp code result');
4109 iseq($^R,'Nothing');
4113 ok('x foofoo y' =~ m{
4114 (?:foo|bar)+ # $^R correctly set
4115 (?{"last regexp code result"})
4117 iseq($^R,'last regexp code result');
4119 iseq($^R,'Nothing');
4123 ok('x foofoo y' =~ m{
4124 (foo|bar)\1+ # $^R undefined
4125 (?{"last regexp code result"})
4127 iseq($^R,'last regexp code result');
4129 iseq($^R,'Nothing');
4133 ok('x foofoo y' =~ m{
4134 (foo|bar)\1 # this time without the +
4135 (?{"last regexp code result"})
4137 iseq($^R,'last regexp code result');
4139 iseq($^R,'Nothing');
4142 local $Message="RT#22395";
4144 for my $l (10,100,1000) {
4146 ('a' x $l) =~ /(.*)(?{$count++})[bc]/;
4147 iseq( $count, $l + 1, "# TODO Should be L+1 not L*(L+3)/2 (L=$l)");
4151 local $Message = "RT#22614";
4154 /(.){1,}(?{push @len,0+@-})(.){1,}(?{})^/;
4155 iseq("@len","2 2 2");
4158 local $Message = "RT#18209";
4159 my $text = ' word1 word2 word3 word4 word5 word6 ';
4161 my @words = ('word1', 'word3', 'word5');
4163 foreach my $word (@words){
4164 $text =~ s/$word\s//gi; # Leave a space to seperate words in the resultant str.
4165 # The following block is not working.
4172 iseq($text,' word2 word4 word6 ');
4176 local $_= qq(A\nB\nC\n);
4178 while (m#(\G|\n)([^\n]*)\n#gsx)
4183 iseq("@res","A B C","RT#6893: /g pattern shouldn't infinite loop");
4187 # From Message-ID: <877ixs6oa6.fsf@k75.linux.bogus>
4188 my $dow_name= "nada";
4189 my $parser = "(\$dow_name) = \$time_string =~ /(D\x{e9}\\ C\x{e9}adaoin|D\x{e9}\\ Sathairn|\\w+|\x{100})/";
4190 my $time_string = "D\x{e9} C\x{e9}adaoin";
4192 ok(!$@,"Test Eval worked");
4193 iseq($dow_name,$time_string,"UTF8 trie common prefix extraction");
4198 ($v='bar')=~/(\w+)/g;
4200 iseq("$1",'bar','$1 is safe after /g - may fail due to specialized config in pp_hot.c')
4203 local $Message = "http://nntp.perl.org/group/perl.perl5.porters/118663";
4204 my $qr_barR1 = qr/(bar)\g-1/;
4205 ok("foobarbarxyz" =~ $qr_barR1);
4206 ok("foobarbarxyz" =~ qr/foo${qr_barR1}xyz/);
4207 ok("foobarbarxyz" =~ qr/(foo)${qr_barR1}xyz/);
4208 ok("foobarbarxyz" =~ qr/(foo)(bar)\g{-1}xyz/);
4209 ok("foobarbarxyz" =~ qr/(foo${qr_barR1})xyz/);
4210 ok("foobarbarxyz" =~ qr/(foo(bar)\g{-1})xyz/);
4213 local $Message = "RT#41010";
4214 my @tails=('','(?(1))','(|)','()?');
4215 my @quants=('*','+');
4219 for my $pat (@$pats) {
4220 for my $quant (@quants) {
4221 for my $tail (@tails) {
4222 my $re = "($pat$quant\$)$tail";
4223 ok(/$re/ && $1 eq $_,"'$_'=~/$re/");
4224 ok(/$re/m && $1 eq $_,"'$_'=~/$re/m");
4234 '(1|[23]|4|[56]|[78]|[90])',
4235 '(?:1|[23]|4|[56]|[78]|[90])',
4236 '(1|2|3|4|5|6|7|8|9|0)',
4237 '(?:1|2|3|4|5|6|7|8|9|0)',
4239 my @spats=('[ ]',' ','( |\t)','(?: |\t)','[ \t]','\s');
4241 my @dstrs=('12345');
4242 $doit->(\@spats,@sstrs);
4243 $doit->(\@dpats,@dstrs);
4246 local $Message = "\$REGMARK";
4248 ok('foofoo' =~ /foo (*MARK:foo) (?{push @r,$REGMARK}) /x);
4250 iseq($REGMARK,"foo");
4251 ok('foofoo' !~ /foo (*MARK:foo) (*FAIL) /x);
4253 iseq($REGERROR,'foo');
4257 $x = "abc.def.ghi.jkl";
4259 ok($x eq "abc.def.ghi");
4261 $x = "one two three four";
4262 $x =~ s/o+ \Kthree//g;
4263 ok($x eq "one two four");
4267 ok($x eq "aabbccddee");
4271 return '4' if $_[0] eq '09028623';
4274 { # Nested EVAL using PL_curpm (via $1 or friends)
4276 our $grabit = qr/ ([0-6][0-9]{7}) (??{ kt $1 }) [890] /x;
4277 $re = qr/^ ( (??{ $grabit }) ) $ /x;
4278 my @res = '0902862349' =~ $re;
4279 iseq(join("-",@res),"0902862349",
4280 'PL_curpm is set properly on nested eval');
4282 our $qr = qr/ (o) (??{ $1 }) /x;
4283 ok( 'boob'=~/( b (??{ $qr }) b )/x && 1,
4284 "PL_curpm, nested eval");
4288 use charnames ":full";
4289 ok("\N{ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "I =~ Alphabetic");
4290 ok("\N{ROMAN NUMERAL ONE}" =~ /\p{Uppercase}/, "I =~ Uppercase");
4291 ok("\N{ROMAN NUMERAL ONE}" !~ /\p{Lowercase}/, "I !~ Lowercase");
4292 ok("\N{ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "I =~ ID_Start");
4293 ok("\N{ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "I =~ ID_Continue");
4294 ok("\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "i =~ Alphabetic");
4295 ok("\N{SMALL ROMAN NUMERAL ONE}" !~ /\p{Uppercase}/, "i !~ Uppercase");
4296 ok("\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Lowercase}/, "i =~ Lowercase");
4297 ok("\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "i =~ ID_Start");
4298 ok("\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "i =~ ID_Continue");
4302 # requirement of Unicode Technical Standard #18, 1.7 Code Points
4303 # cf. http://www.unicode.org/reports/tr18/#Supplementary_Characters
4304 for my $u (0x7FF, 0x800, 0xFFFF, 0x10000) {
4305 no warnings 'utf8'; # oops
4307 my $x = sprintf '%04X', $u;
4308 ok( "A${c}B" =~ /A[\0-\x{10000}]B/, "unicode range - $x");
4315 if ('1' =~ /(?|(?<digit>1)|(?<digit>2))/) {
4316 $res = "@{$- {digit}}";
4319 "Check that (?|...) doesnt cause dupe entries in the names array");
4322 if ('11' =~ /(?|(?<digit>1)|(?<digit>2))(?&digit)/) {
4323 $res = "@{$- {digit}}";
4326 "Check that (?&..) to a buffer inside a (?|...) goes to the leftmost");
4331 local $Message = "ASCII pattern that really is utf8";
4333 local $SIG{__WARN__}=sub{push @w,"@_"};
4335 ok($c=~/${c}|\x{100}/);
4339 local $Message = "corruption of match results of qr// across scopes";
4340 my $qr=qr/(fo+)(ba+r)/;
4342 iseq("$1$2","foobar");
4344 'foooooobaaaaar'=~/$qr/;
4345 iseq("$1$2",'foooooobaaaaar');
4347 iseq("$1$2","foobar");
4349 # Test counter is at bottom of file. Put new tests above here.
4350 #-------------------------------------------------------------------
4351 # Keep the following tests last -- they may crash perl
4353 # RT#19049 / RT#38869
4355 'ab cdef', # matches regex
4356 ( 'e' x 40000 ) .'ab c' # matches not, but 'ab c' matches part of it
4361 m/ab(.+)cd/i; # the ignore-case seems to be important
4362 $y = $1; # use $1, which might not be from the last match!
4363 $x = substr($list[0],$-[0],$+[0]-$-[0]);
4366 'pattern in a loop, failure should not affect previous success');
4368 'pattern in a loop, failure should not affect previous success');
4371 ok(("a" x (2**15 - 10)) =~ /^()(a|bb)*$/, "Recursive stack cracker: #24274")
4372 or print "# Unexpected outcome: should pass or crash perl\n";
4374 ok((q(a)x 100) =~ /^(??{'(.)'x 100})/,
4375 "Regexp /^(??{'(.)'x 100})/ crashes older perls")
4376 or print "# Unexpected outcome: should pass or crash perl\n";
4379 ok($@=~/\QSequence \k... not terminated in regex;\E/);
4382 local $Message = "substitution with lookahead (possible segv)";
4385 iseq($_,"ns_1ns_1ns_1");
4390 s/(?=\d+)|(?<=\d)/!Bang!/g;
4391 iseq($_,"!Bang!1!Bang!2!Bang!3!Bang!");
4394 # test for keys in %+ and %-
4397 /(?<foo>a)|(?<foo>b)/;
4398 iseq( (join ",", sort keys %+), "foo" );
4399 iseq( (join ",", sort keys %-), "foo" );
4400 iseq( (join ",", sort values %+), "a" );
4401 iseq( (join ",", sort map "@$_", values %-), "a " );
4402 /(?<bar>a)(?<bar>b)(?<quux>.)/;
4403 iseq( (join ",", sort keys %+), "bar,quux" );
4404 iseq( (join ",", sort keys %-), "bar,quux" );
4405 iseq( (join ",", sort values %+), "a,c" ); # leftmost
4406 iseq( (join ",", sort map "@$_", values %-), "a b,c" );
4407 /(?<un>a)(?<deux>c)?/; # second buffer won't capture
4408 iseq( (join ",", sort keys %+), "un" );
4409 iseq( (join ",", sort keys %-), "deux,un" );
4410 iseq( (join ",", sort values %+), "a" );
4411 iseq( (join ",", sort map "@$_", values %-), ",a" );
4414 # length() on captures, these end up in Perl_magic_len
4416 my $_ = "aoeu \xe6var ook";
4417 /^ \w+ \s (?<eek>\S+)/x;
4419 iseq( length($`), 0, 'length $`' );
4420 iseq( length($'), 4, q[length $'] );
4421 iseq( length($&), 9, 'length $&' );
4422 iseq( length($1), 4, 'length $1' );
4423 iseq( length($+{eek}), 4, 'length $+{eek} == length $1' );
4426 # Put new tests above the dotted line about a page above this comment
4427 iseq(0+$::test,$::TestCount,"Got the right number of tests!");
4428 # Don't forget to update this!
4430 $::TestCount = 1663;
4431 print "1..$::TestCount\n";