13 # /p Pattern PRE MATCH POST
14 [ '/p', "345", "012-", "345", "-6789"],
15 [ '/$r/p',"345", "012-", "345", "-6789"],
16 [ '(?p)', "345", "012-", "345", "-6789"],
17 [ '(?p:)',"345", "012-", "345", "-6789"],
18 [ '', "(345)", undef, undef, undef ],
19 [ '', "345", undef, undef, undef ],
22 plan tests => 14 * @tests + 4;
25 $SIG{__WARN__} = sub { $W.=join("",@_); };
26 sub _u($$) { "$_[0] is ".(defined $_[1] ? "'$_[1]'" : "undef") }
28 foreach my $test (@tests) {
29 my ($p, $pat,$l,$m,$r) = @$test;
32 my $test_name = $p eq '/p' ? "/$pat/p"
34 : $p eq '(?p)' ? "/(?p)$pat/"
35 : $p eq '(?p:)'? "/(?p:$pat)/"
37 $test_name = "s$test_name" if $sub;
40 # Cannot use if/else due to the scope invalidating ${^MATCH} and friends.
45 ( $p eq '/p' ? s/$pat/abc/p
46 : $p eq '/$r/p'? s/$qr/abc/p
47 : $p eq '(?p)' ? s/(?p)$pat/abc/
48 : $p eq '(?p:)'? s/(?p:$pat)/abc/
52 ( $p eq '/p' ? /$pat/p
53 : $p eq '/$r/p'? /$qr/p
54 : $p eq '(?p)' ? /(?p)$pat/
55 : $p eq '(?p:)'? /(?p:$pat)/
60 skip "/$pat/$p failed to match", 6
62 is(${^PREMATCH}, $l,_u "$test_name: ^PREMATCH",$l);
63 is(${^MATCH}, $m,_u "$test_name: ^MATCH",$m );
64 is(${^POSTMATCH}, $r,_u "$test_name: ^POSTMATCH",$r );
65 is(length ${^PREMATCH}, length $l, "$test_name: ^PREMATCH length");
66 is(length ${^MATCH}, length $m, "$test_name: ^MATCH length");
67 is(length ${^POSTMATCH},length $r, "$test_name: ^POSTMATCH length");
71 is($W,"","No warnings should be produced");
72 ok(!defined ${^MATCH}, "No /p in scope so ^MATCH is undef");
78 ok("a"=~ /(?p:a(?{ $m = ${^MATCH} }))/, '(?{})');
79 is($m, 'a', '(?{}) ^MATCH');