pat.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
#
# This is a home for regular expression tests that don't fit into
print "1..233\n";
BEGIN {
chdir 't' if -d 't';
}
eval 'use Config'; # Defaults assumed if this fails
$x = "abc\ndef\n";
$* = 1;
$* = 0;
$_ = '123';
if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
$_ = 'aaabbbccc';
print "ok 13\n";
} else {
print "not ok 13\n";
}
print "ok 14\n";
} else {
print "not ok 14\n";
}
if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
$_ = 'aaabccc';
if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
$_ = 'aaaccc';
if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
$_ = 'abcdef';
if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
$* = 1; # test 3 only tested the optimized version--this one is for real
if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
$* = 0;
?(.*)? && (print $1,"\n");
}
print "not ok 27\n";
exit;
}
print "ok 27\n";
'cde' =~ /[^ab]*/;
'xyz' =~ //;
$foo = '[^ab]*';
'cde' =~ /$foo/;
'xyz' =~ //;
$foo = '[^ab]*';
'cde' =~ /$foo/;
'xyz' =~ /$null/;
$_ = 'abcdefghi';
/def/; # optimized up to cmd
/cde/ + 0; # optimized only to spat
/[d][e][f]/; # not optimized
$_ = 'now is the {time for all} good men to come to.';
/ {([^}]*)}/;
$_ = 'xxx {3,4} yyy zzz';
print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
$_ = "now is the time for all good men to come to.";
@words = /(\w+)/g;
? "ok 44\n"
: "not ok 44\n";
@words = ();
while (/\w+/g) {
}
? "ok 45\n"
: "not ok 45\n";
@words = ();
pos = 0;
while (/to/g) {
}
? "ok 46\n"
pos $_ = 0;
@words = /to/g;
print join(':',@words) eq "to:to"
? "ok 47\n"
: "not ok 47 `@words'\n";
$pat1 = 'def';
$pat2 = '^def';
$pat3 = '.def.';
$pat4 = 'abc';
$pat5 = '^abc';
$pat6 = 'abc$';
$pat7 = 'ghi';
$pat8 = '\w*ghi';
$pat9 = 'ghi$';
for $iter (1..5) {
}
$xyz = 'xyz';
$x=/abc/g;
$x=/abc/g;
$x=/abc/g;
pos = 0;
pos = 0;
$x=/abc/g;
$x=/abc/g;
$_ .= '';
@x=/abc/g;
pos $_ = 2;
/\Gc/g;
$out = 1;
'abc' =~ m'a(?{ $out = 2 })b';
$out = 1;
'abc' =~ m'a(?{ $out = 3 })c';
$_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
@out = /(?<!foo)bar./g;
# Tests which depend on REG_INFTY
$reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
$reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
# As well as failing if the pattern matches do unexpected things, the
# next three tests will fail if you should have picked up a lower-than-
# default value for $reg_infty from Config.pm, but have not.
undef $@;
undef $@;
undef $@;
undef $@;
if $@ !~ m%^\QQuantifier in {,} bigger than%;
undef $@;
# Poke a couple more parse failures
$context = 'x' x 256;
# removed test
# Long Monsters
$test = 73;
for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
$a = 'a' x $l;
print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
$test++;
print "not " if "b$a=" =~ /a$a=/;
$test++;
}
# 20000 nodes, each taking 3 words per string, and 1 per branch
'ax13876y25677mcb' => 0, # not b.
'ax13876y35677nbc' => 0, # Num too big
'ax13876y25677y21378obc' => 1,
'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
'ax13876y25677y21378y21378kbc' => 1,
'ax13876y25677y21378y21378kcb' => 0, # Not b.
'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
);
print "# const-len `$_' not => $ans{$_}\nnot "
if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
print "ok $test\n";
$test++;
if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
$test++;
}
sub matchit {
m/
(
\(
(?{ $c = 1 }) # Initialize
(?:
(?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
(?!
) # Fail: will unwind one iteration back
)
(?:
[^()]+ # Match a big chunk
(?=
[()]
) # Do not try to match subchunks
|
\(
(?{ ++$c })
|
\)
(?{ --$c })
)
)+ # This may not match with different subblocks
)
(?(?{ $c != 0 })
(?!
) # Fail
) # Otherwise the chunk 1 may succeed with $c>0
/xg;
}
@ans = ();
print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
$test++;
$test++;
$test++;
my $matched;
$test++;
$test++;
$test++;
$test++;
$blah = 12;
$test++;
$blah = 12;
} else {
}
$test++;
}
$blah = 12;
$test++;
$blah = 12;
$test++;
$x = 'banana';
$x =~ /.a/g;
$test++;
$test++;
sub f {
my $p = $_[0];
return $p;
}
$x =~ /.a/g;
$test++;
$x = $^R = 67;
$test++;
$x = $^R = 67;
$test++;
$x = $^R = 67;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$_ = 'xabcx';
/(?<=(?=a)..)((?=c)|.)/g;
$test++;
}
$_ = 'a';
/^|a|$/g;
$test++;
}
sub prefixify {
$v =~ s/\Q$a\E/$b/;
$test++;
}
$_ = 'var="foo"';
/(\")/;
$test++;
$b = 7;
/$a$a/;
$test++;
$c="$a";
/$a$a/;
$test++;
{
/$a$c$a/;
$test++;
local $lex_a = 2;
my $lex_a = 43;
my $lex_b = 17;
my $lex_c = 27;
$test++;
$test++;
$test++;
$match = eval { /$a$c$a/ };
print "not "
$test++;
}
{
local $lex_a = 2;
my $lex_a = 43;
my $lex_b = 17;
my $lex_c = 27;
$test++;
$test++;
$test++;
}
{
$c = 2;
$::c = 3;
'' =~ /(?{ $c = 4 })/;
}
$test++;
$test++;
sub must_warn_pat {
my $warn_pat = shift;
}
sub must_warn {
local %SIG;
$test++;
}
sub make_must_warn {
my $warn_pat = shift;
}
#&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
#&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
# test if failure of patterns returns empty list
$_ = 'aaa';
@_ = /bbb/;
print "not " if @_;
$test++;
@_ = /bbb/g;
print "not " if @_;
$test++;
print "not " if @_;
$test++;
print "not " if @_;
$test++;
/a(?=.$)/;
$test++;
$test++;
print "not "
$test++;
/a(a)(a)/;
$test++;
$test++;
$test++;
$test++;
print "not "
$test++;
/.(a)(b)?(a)/;
$test++;
$test++;
$test++;
$test++;
print "not "
$test++;
/.(a)/;
$test++;
$test++;
$test++;
print "not "
$test++;
eval { $+[0] = 13; };
print "not "
if $@ !~ /^Modification of a read-only value attempted/;
$test++;
eval { $-[0] = 13; };
print "not "
if $@ !~ /^Modification of a read-only value attempted/;
$test++;
eval { @+ = (7, 6, 5); };
print "not "
if $@ !~ /^Modification of a read-only value attempted/;
$test++;
print "not "
if $@ !~ /^Modification of a read-only value attempted/;
$test++;
$test++;
$_ = 'aaa';
pos = 1;
@a = /\Ga/g;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$_ = $str;
$test++;
$test++;
$test++;
$_ = 'abcde|abcde';
$test++;
# List context:
$_ = 'abcde|abcde';
print "#'@res' '$_'\nnot "
$test++;
print "#'@res' '$_'\nnot "
"'' 'ab' 'cde|abcde' " .
"'' 'abc' 'de|abcde' " .
"'abcd' 'e|' 'abcde' " .
"'abcde|' 'ab' 'cde' " .
"'abcde|' 'abc' 'de'" ;
$test++;
#Some more \G anchor checks
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$_='123x123';
$test++;
# see if matching against temporaries (created via pp_helem()) is safe
print "$1\n";
$test++;
# See if $i work inside (?{}) in the presense of saved substrings and
# changing $_
@b = ();
$test++;
$test++;
}x;
"{{}" =~ $brackets;
$test++;
"something { long { and } hairy" =~ $brackets;
$test++;
$test++;
$_ = "a-a\nxbb";
pos=1;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
$test++;
# see if backtracking optimization works correctly
$test++;
$test++;
$test++;
$test++;
eval << 'EOE';
{
package S;
}
$test++;
# test result of match used as match (!)
$test++;
$test++;
$w = 0;
{
local $^W = 1;
$w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
}
$test++;
# There's no \v but the vertical tabulator seems miraculously
# be 11 both in ASCII and EBCDIC.
false => "space" );
$test++;
$test++;
$test++;
# bugid 20001021.005 - this caused a SEGV
$test++;
{
# japhy -- added 03/03/2001
$test++;
}
$_ = "foo";
/f
o\r
o
\$
$test++;
/f
o
o
\$\r
$test++;