summaryrefslogtreecommitdiff
path: root/t/op/regexp.t
blob: c6969240fcdaaa33fc61a4e9471892b9c13242b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!./perl

open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
    || die "Can't open re_tests";

while (<TESTS>) { }
$numtests = $.;
seek(TESTS,0,0);
$. = 0;

$| = 1;
print "1..$numtests\n";
TEST:
while (<TESTS>) {
    ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_);
    $input = join(':',$pat,$subject,$result,$repl,$expect);
    $pat = "'$pat'" unless $pat =~ /^'/;
    for $study ("", "study \$match") {
	eval "$study; \$match = (\$subject =~ m$pat); \$got = \"$repl\";";
	if ($result eq 'c') {
	    if ($@ eq '') { print "not ok $.\n"; next TEST }
	    last;  # no need to study a syntax error
	}
	elsif ($result eq 'n') {
	    if ($match) { print "not ok $. $input => $got\n"; next TEST }
	}
	else {
	    if (!$match || $got ne $expect) {
		print "not ok $. $input => $got\n";
		next TEST;
	    }
	}
    }
    print "ok $.\n";
}

close(TESTS);