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:
16 # B test exposes a known bug in Perl, should be skipped
17 # b test exposes a known bug in Perl, should be skipped if noamp
19 # Columns 4 and 5 are used only if column 3 contains C<y> or C<c>.
21 # Column 4 contains a string, usually C<$&>.
23 # Column 5 contains the expected result of double-quote
24 # interpolating that string after the match, or start of error message.
26 # Column 6, if present, contains a reason why the test is skipped.
27 # This is printed with "skipped", for harness to pick up.
29 # \n in the tests are interpolated, as are variables of the form ${\w+}.
31 # If you want to add a regular expression test that can't be expressed
32 # in this format, don't add it here: put it in op/pat.t instead.
39 $iters = shift || 1; # Poor man performance suite, 10000 is OK.
41 open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests') || open(TESTS,':op:re_tests') ||
42 die "Can't open re_tests";
49 $bang = sprintf "\\%03o", ord "!"; # \41 would not be portable.
50 $ffff = chr(0xff) x 2;
52 $OP = $qr ? 'qr' : 'm';
55 print "1..$numtests\n# $iters iterations\n";
60 ($pat, $subject, $result, $repl, $expect, $reason) = split(/\t/,$_,6);
61 $input = join(':',$pat,$subject,$result,$repl,$expect);
63 infty_subst(\$expect);
64 $pat = "'$pat'" unless $pat =~ /^[:']/;
65 $pat =~ s/(\$\{\w+\})/$1/eeg;
67 $subject =~ s/(\$\{\w+\})/$1/eeg;
68 $subject =~ s/\\n/\n/g;
69 $expect =~ s/(\$\{\w+\})/$1/eeg;
70 $expect =~ s/\\n/\n/g;
71 $expect = $repl = '-' if $skip_amp and $input =~ /\$[&\`\']/;
72 $skip = ($skip_amp ? ($result =~ s/B//i) : ($result =~ s/B//));
73 $reason = 'skipping $&' if $reason eq '' && $skip_amp;
74 $result =~ s/B//i unless $skip;
75 for $study ('', 'study \$subject') {
77 eval "$study; \$match = (\$subject =~ $OP$pat) while \$c--; \$got = \"$repl\";";
80 if ($err !~ m!^\Q$expect!) { print "not ok $. (compile) $input => `$err'\n"; next TEST }
81 last; # no need to study a syntax error
84 print "ok $. # skipped", length($reason) ? " $reason" : '', "\n";
88 print "not ok $. $input => error `$err'\n"; next TEST;
90 elsif ($result eq 'n') {
91 if ($match) { print "not ok $. ($study) $input => false positive\n"; next TEST }
94 if (!$match || $got ne $expect) {
95 print "not ok $. ($study) $input => `$got', match=$match\n";
105 sub infty_subst # Special-case substitution
106 { # of $reg_infty and friends
108 $$tp =~ s/,\$reg_infty_m}/,$reg_infty_m}/o;
109 $$tp =~ s/,\$reg_infty_p}/,$reg_infty_p}/o;
110 $$tp =~ s/,\$reg_infty}/,$reg_infty}/o;