From: Hans Mulder Date: Wed, 11 Jun 1997 00:00:00 +0000 (+1200) Subject: More simple regexp tests and test docs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ad4f75a617e142cf0d567ad25c1dbd4439093580;p=p5sagit%2Fp5-mst-13.2.git More simple regexp tests and test docs --- diff --git a/t/op/re_tests b/t/op/re_tests index c20fb89..77d97e2 100644 --- a/t/op/re_tests +++ b/t/op/re_tests @@ -301,3 +301,6 @@ a(?:b|c|d)*(.) ace y $1 e a(?:b|c|d)+?(.) ace y $1 e a(?:b|(c|e){1,2}?|d)+?(.) ace y $1$2 ce ^(.+)?B AB y $1 A +'([a-z]+)\s\1'i Aa aa y $&-$1 Aa aa-Aa +'([a-z]+)\s\1'i Ab ab y $&-$1 Ab ab-Ab +foo\w*\d{4}baz foobar1234baz y $& foobar1234baz diff --git a/t/op/regexp.t b/t/op/regexp.t index c696924..ea470f8 100755 --- a/t/op/regexp.t +++ b/t/op/regexp.t @@ -1,5 +1,26 @@ #!./perl +# 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. +# +# 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"; @@ -15,7 +36,7 @@ while () { ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_); $input = join(':',$pat,$subject,$result,$repl,$expect); $pat = "'$pat'" unless $pat =~ /^'/; - for $study ("", "study \$match") { + for $study ("", "study \$subject") { eval "$study; \$match = (\$subject =~ m$pat); \$got = \"$repl\";"; if ($result eq 'c') { if ($@ eq '') { print "not ok $.\n"; next TEST }