Re: [ID 20010618.006] some end-anchored regexps hang when using study
[p5sagit/p5-mst-13.2.git] / t / op / study.t
CommitLineData
378cc40b 1#!./perl
2
79072805 3# $RCSfile: study.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:30 $
378cc40b 4
4870b8cd 5print "1..26\n";
378cc40b 6
7$x = "abc\ndef\n";
8study($x);
9
10if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
11if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
12
13$* = 1;
14if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
15$* = 0;
16
17$_ = '123';
18study;
19if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
20
21if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
22if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
23
24if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
25if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
26
27study($x);
28if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
29if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
30
31if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
32if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
33
34$_ = 'aaabbbccc';
35study;
36if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
37 print "ok 13\n";
38} else {
39 print "not ok 13\n";
40}
41if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
42 print "ok 14\n";
43} else {
44 print "not ok 14\n";
45}
46
47if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
48
49$_ = 'aaabccc';
50study;
51if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
52if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
53
54$_ = 'aaaccc';
55study;
56if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
57if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
58
59$_ = 'abcdef';
60study;
61if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
62if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
63
64if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
65
66if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
67
68$* = 1; # test 3 only tested the optimized version--this one is for real
69if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
4870b8cd 70
71# [ID 20010618.006] these two may loop
72{
73 local $SIG{ALRM} = sub { die "timeout\n" };
74 $_ = 'FGF';
75 study;
76 my $ok = eval { alarm(2); my $match = /G.F$/; alarm(0); !$match };
77 if ($ok && !$@) {
78 print "ok 25\n";
79 } elsif ($@) {
80 print "not ok 25\t# $@";
81 } else {
82 print "not ok 25\t# should not match\n";
83 }
84 $ok = eval { alarm(2); my $match = /[F]F$/; alarm(0); !$match };
85 if ($ok && !$@) {
86 print "ok 26\n";
87 } elsif ($@) {
88 print "not ok 26\t# $@";
89 } else {
90 print "not ok 26\t# should not match\n";
91 }
92}