3 # The tests are in a separate file 't/op/re_tests'.
4 # Each line in that file is a separate test.
5 # There are five columns, separated by tabs.
7 # Column 1 contains the pattern, optionally enclosed in C<''>.
8 # Modifiers can be put after the closing C<'>.
10 # Column 2 contains the string to be matched.
12 # Column 3 contains the expected result:
17 # Columns 4 and 5 are used only if column 3 contains C<y> or C<c>.
19 # Column 4 contains a string, usually C<$&>.
21 # Column 5 contains the expected result of double-quote
22 # interpolating that string after the match.
24 open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
25 || die "Can't open re_tests";
33 print "1..$numtests\n";
36 ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_);
37 $input = join(':',$pat,$subject,$result,$repl,$expect);
38 $pat = "'$pat'" unless $pat =~ /^[:']/;
39 for $study ("", "study \$subject") {
40 eval "$study; \$match = (\$subject =~ m$pat); \$got = \"$repl\";";
42 if ($@ !~ m!^\Q$expect!) { print "not ok $.\n"; next TEST }
43 last; # no need to study a syntax error
45 elsif ($result eq 'n') {
46 if ($match) { print "not ok $. $input => $got\n"; next TEST }
49 if (!$match || $got ne $expect) {
50 print "not ok $. $input => $got\n";