Commit | Line | Data |
cde0cee5 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | require './test.pl'; |
7 | } |
8 | |
9 | use strict; |
10 | use warnings; |
11 | |
12 | our @tests = ( |
87e95b7f |
13 | # /p Pattern PRE MATCH POST |
14 | [ 'p', "456", "123-", "456", "-789"], |
cde0cee5 |
15 | [ '', "(456)", "123-", "456", "-789"], |
16 | [ '', "456", undef, undef, undef ], |
17 | ); |
18 | |
19 | plan tests => 4 * @tests + 2; |
20 | my $W = ""; |
21 | |
22 | $SIG{__WARN__} = sub { $W.=join("",@_); }; |
23 | sub _u($$) { "$_[0] is ".(defined $_[1] ? "'$_[1]'" : "undef") } |
24 | |
25 | $_ = '123-456-789'; |
26 | foreach my $test (@tests) { |
87e95b7f |
27 | my ($p, $pat,$l,$m,$r) = @$test; |
28 | my $test_name = "/$pat/$p"; |
29 | my $ok = ok($p ? /$pat/p : /$pat/, $test_name); |
cde0cee5 |
30 | SKIP: { |
87e95b7f |
31 | skip "/$pat/$p failed to match", 3 |
cde0cee5 |
32 | unless $ok; |
33 | is(${^PREMATCH}, $l,_u "$test_name: ^PREMATCH",$l); |
34 | is(${^MATCH}, $m,_u "$test_name: ^MATCH",$m ); |
35 | is(${^POSTMATCH}, $r,_u "$test_name: ^POSTMATCH",$r ); |
36 | } |
37 | } |
38 | is($W,"","No warnings should be produced"); |
87e95b7f |
39 | ok(!defined ${^MATCH}, "No /p in scope so ^MATCH is undef"); |