This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove the port to MiNT. It's a dead platform that hasn't had any love since 5.005
[perl5.git] / t / op / reg_pmod.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     # /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 ],
18 );
19
20 plan tests => 4 * @tests + 2;
21 my $W = "";
22
23 $SIG{__WARN__} = sub { $W.=join("",@_); };
24 sub _u($$) { "$_[0] is ".(defined $_[1] ? "'$_[1]'" : "undef") }
25
26 $_ = '123-456-789';
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/"
31                   :                "/$pat/";
32
33     #
34     # Cannot use if/else due to the scope invalidating ${^MATCH} and friends.
35     #
36     my $ok = ok $p eq '/p'   ? /$pat/p
37               : $p eq '(?p)' ? /(?p)$pat/
38               :                /$pat/
39               => $test_name;
40     SKIP: {
41         skip "/$pat/$p failed to match", 3
42             unless $ok;
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 );
46     }
47 }
48 is($W,"","No warnings should be produced");
49 ok(!defined ${^MATCH}, "No /p in scope so ^MATCH is undef");