Sys::Syslog patch to allow unix domain sockets
[p5sagit/p5-mst-13.2.git] / t / op / regexp.t
index af8a666..ea470f8 100755 (executable)
@@ -1,35 +1,58 @@
 #!./perl
 
-# $RCSfile: regexp.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:20 $
+# The tests are in a separate file 't/op/re_tests'.
+# Each line in that file is a separate test.
+# There are five columns, separated by tabs.
+#
+# Column 1 contains the pattern, optionally enclosed in C<''>.
+# Modifiers can be put after the closing C<'>.
+#
+# Column 2 contains the string to be matched.
+#
+# Column 3 contains the expected result:
+#      y       expect a match
+#      n       expect no match
+#      c       expect an error
+#
+# Columns 4 and 5 are used only of column 3 contains C<y>.
+#
+# Column 4 contains a string, usually C<$&>.
+#
+# Column 5 contains the expected result of double-quote
+# interpolating that string after the match.
 
 open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
     || die "Can't open re_tests";
+
 while (<TESTS>) { }
 $numtests = $.;
-close(TESTS);
+seek(TESTS,0,0);
+$. = 0;
 
-print "1..$numtests\n";
-open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
-    || die "Can't open re_tests";
 $| = 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 =~ /^'/;
-    eval "\$match = (\$subject =~ m$pat); \$got = \"$repl\";";
-    if ($result eq 'c') {
-       if ($@ ne '') {print "ok $.\n";} else {print "not ok $.\n";}
-    }
-    elsif ($result eq 'n') {
-       if (!$match) {print "ok $.\n";} else {print "not ok $. $input => $got\n";}
-    }
-    else {
-       if ($match && $got eq $expect) {
-           print "ok $.\n";
+    for $study ("", "study \$subject") {
+       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 {
-           print "not ok $. $input => $got\n";
+           if (!$match || $got ne $expect) {
+               print "not ok $. $input => $got\n";
+               next TEST;
+           }
        }
     }
+    print "ok $.\n";
 }
+
 close(TESTS);