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, or start of error message.
24 # Columns 1, 2 and 5 are \n-interpolated.
26 # The variables $reg_infty, $reg_infty_m and $reg_infty_m in columns 1
27 # and 5 are replaced respectively with the configuration value reg_infty,
28 # reg_infty-1 and reg_infty+1, or if reg_infty is not defined in the
29 # configuration, default values. No other variables are substituted.
32 $iters = shift || 1; # Poor man performance suite, 10000 is OK.
36 eval 'use Config'; # Defaults assumed if this fails
37 $reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
38 $reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
40 open(TESTS,'op/re_tests') || die "Can't open re_tests";
48 print "1..$numtests\n# $iters iterations\n";
51 ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_);
52 $input = join(':',$pat,$subject,$result,$repl,$expect);
54 infty_subst(\$expect);
55 $pat = "'$pat'" unless $pat =~ /^[:']/;
57 $subject =~ s/\\n/\n/g;
58 $expect =~ s/\\n/\n/g;
59 $expect = $repl = '-' if $skip_amp and $input =~ /\$[&\`\']/;
60 for $study ("", "study \$subject") {
62 eval "$study; \$match = (\$subject =~ m$pat) while \$c--; \$got = \"$repl\";";
65 if ($err !~ m!^\Q$expect!) { print "not ok $. (compile) $input => `$err'\n"; next TEST }
66 last; # no need to study a syntax error
69 print "not ok $. $input => error `$err'\n"; next TEST;
71 elsif ($result eq 'n') {
72 if ($match) { print "not ok $. ($study) $input => false positive\n"; next TEST }
75 if (!$match || $got ne $expect) {
76 print "not ok $. ($study) $input => `$got', match=$match\n";
86 sub infty_subst # Special-case substitution
87 { # of $reg_infty and friends
89 $$tp =~ s/,\$reg_infty_m}/,$reg_infty_m}/o;
90 $$tp =~ s/,\$reg_infty_p}/,$reg_infty_p}/o;
91 $$tp =~ s/,\$reg_infty}/,$reg_infty}/o;