This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Change 30276 wasn't meant do mess with t/lib/common.pl. Oops.
[perl5.git] / t / op / regexp_kmod.t
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 = (
13     # /k     Pattern   PRE     MATCH   POST
14     [ 'k',   "456",    "123-", "456",  "-789"],
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) {
27     my ($k, $pat,$l,$m,$r) = @$test;
28     my $test_name = "/$pat/$k";
29     my $ok = ok($k ? /$pat/k : /$pat/, $test_name);
30     SKIP: {
31         skip "/$pat/$k failed to match", 3
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");
39 ok(!defined ${^MATCH}, "No /k in scope so ^MATCH is undef");