3 # $RCSfile: pat.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:12 $
9 if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
10 if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
13 if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
17 if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
19 if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
20 if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
22 if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
23 if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
25 if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
26 if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
28 if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
29 if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
32 if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
37 if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
43 if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
46 if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
47 if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
50 if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
51 if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
54 if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
55 if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
57 if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
59 if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
61 $* = 1; # test 3 only tested the optimized version--this one is for real
62 if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
69 @XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27');
70 while ($_ = shift(XXX)) {
71 ?(.*)? && (print $1,"\n");
73 /not ok 26/ && reset 'X';
76 while (($key,$val) = each(%XXX)) {
85 if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
90 if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
95 if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
98 /def/; # optimized up to cmd
99 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
101 /cde/ + 0; # optimized only to spat
102 if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
104 /[d][e][f]/; # not optimized
105 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
107 $_ = 'now is the {time for all} good men to come to.';
109 if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
111 $_ = 'xxx {3,4} yyy zzz';
112 print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
113 print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
114 print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
115 print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
116 print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
117 print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
118 print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
119 print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
120 print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
122 $_ = "now is the time for all good men to come to.";
124 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
132 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
141 print join(':',@words) eq "to:to"
143 : "not ok 46 `@words'\n";
147 print join(':',@words) eq "to:to"
149 : "not ok 47 `@words'\n";
163 $t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
177 $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
178 print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
181 print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
183 # perl 4.009 says "unmatched ()"
184 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
185 print $@ eq "" ? "ok 50\n" : "not ok 50\n";
186 print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
191 print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
193 print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
195 print $x == 0 ? "ok 54\n" : "not ok 54\n";
198 print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
200 print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
202 print $x == 0 ? "ok 57\n" : "not ok 57\n";
205 print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
207 print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
210 print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
215 print "not " if (pos $_) != 2;