c6969240fcdaaa33fc61a4e9471892b9c13242b0
[p5sagit/p5-mst-13.2.git] / t / op / regexp.t
1 #!./perl
2
3 open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
4     || die "Can't open re_tests";
5
6 while (<TESTS>) { }
7 $numtests = $.;
8 seek(TESTS,0,0);
9 $. = 0;
10
11 $| = 1;
12 print "1..$numtests\n";
13 TEST:
14 while (<TESTS>) {
15     ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_);
16     $input = join(':',$pat,$subject,$result,$repl,$expect);
17     $pat = "'$pat'" unless $pat =~ /^'/;
18     for $study ("", "study \$match") {
19         eval "$study; \$match = (\$subject =~ m$pat); \$got = \"$repl\";";
20         if ($result eq 'c') {
21             if ($@ eq '') { print "not ok $.\n"; next TEST }
22             last;  # no need to study a syntax error
23         }
24         elsif ($result eq 'n') {
25             if ($match) { print "not ok $. $input => $got\n"; next TEST }
26         }
27         else {
28             if (!$match || $got ne $expect) {
29                 print "not ok $. $input => $got\n";
30                 next TEST;
31             }
32         }
33     }
34     print "ok $.\n";
35 }
36
37 close(TESTS);