home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / perl / regexp.t < prev    next >
Text File  |  1991-06-11  |  981b  |  36 lines

  1. #!./perl
  2.  
  3. # $RCSfile: regexp.t,v $$Revision: 4.0.1.1 $$Date: 91/06/10 01:30:29 $
  4.  
  5. open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
  6.     || die "Can't open re_tests";
  7. while (<TESTS>) { }
  8. $numtests = $.;
  9. close(TESTS);
  10.  
  11. print "1..$numtests\n";
  12. open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
  13.     || die "Can't open re_tests";
  14. $| = 1;
  15. while (<TESTS>) {
  16.     ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_);
  17.     $input = join(':',$pat,$subject,$result,$repl,$expect);
  18.     $pat = "'$pat'" unless $pat =~ /^'/;
  19.     eval "\$match = (\$subject =~ m$pat); \$got = \"$repl\";";
  20.     if ($result eq 'c') {
  21.     if ($@ ne '') {print "ok $.\n";} else {print "not ok $.\n";}
  22.     }
  23.     elsif ($result eq 'n') {
  24.     if (!$match) {print "ok $.\n";} else {print "not ok $. $input => $got\n";}
  25.     }
  26.     else {
  27.     if ($match && $got eq $expect) {
  28.         print "ok $.\n";
  29.     }
  30.     else {
  31.         print "not ok $. $input => $got\n";
  32.     }
  33.     }
  34. }
  35. close(TESTS);
  36.