13 # /p Pattern PRE MATCH POST
14 [ '/p', "456", "123-", "456", "-789"],
15 [ '(?p)', "456", "123-", "456", "-789"],
16 [ '', "(456)", "123-", "456", "-789"],
17 [ '', "456", undef, undef, undef ],
20 plan tests => 4 * @tests + 2;
23 $SIG{__WARN__} = sub { $W.=join("",@_); };
24 sub _u($$) { "$_[0] is ".(defined $_[1] ? "'$_[1]'" : "undef") }
27 foreach my $test (@tests) {
28 my ($p, $pat,$l,$m,$r) = @$test;
29 my $test_name = $p eq '/p' ? "/$pat/p"
30 : $p eq '(?p)' ? "/(?p)$pat/"
34 # Cannot use if/else due to the scope invalidating ${^MATCH} and friends.
36 my $ok = ok $p eq '/p' ? /$pat/p
37 : $p eq '(?p)' ? /(?p)$pat/
41 skip "/$pat/$p failed to match", 3
43 is(${^PREMATCH}, $l,_u "$test_name: ^PREMATCH",$l);
44 is(${^MATCH}, $m,_u "$test_name: ^MATCH",$m );
45 is(${^POSTMATCH}, $r,_u "$test_name: ^POSTMATCH",$r );
48 is($W,"","No warnings should be produced");
49 ok(!defined ${^MATCH}, "No /p in scope so ^MATCH is undef");