This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix spelling errors in comments.
[perl5.git] / t / op / reg_pmod.t
CommitLineData
cde0cee5
YO
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
9use strict;
10use warnings;
11
12our @tests = (
f7819f85
A
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 ],
cde0cee5
YO
18);
19
20plan tests => 4 * @tests + 2;
21my $W = "";
22
23$SIG{__WARN__} = sub { $W.=join("",@_); };
24sub _u($$) { "$_[0] is ".(defined $_[1] ? "'$_[1]'" : "undef") }
25
26$_ = '123-456-789';
27foreach my $test (@tests) {
87e95b7f 28 my ($p, $pat,$l,$m,$r) = @$test;
f7819f85
A
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;
cde0cee5 40 SKIP: {
87e95b7f 41 skip "/$pat/$p failed to match", 3
cde0cee5
YO
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}
48is($W,"","No warnings should be produced");
87e95b7f 49ok(!defined ${^MATCH}, "No /p in scope so ^MATCH is undef");