1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require './test.pl';
6    set_up_inc('../lib');
7}
8
9use strict;
10use warnings;
11
12plan tests => 25;
13
14# Some /qr/ tests
15my $re = qr/(.*) b c d/;
16ok("a b c d" =~ /$re/n, "/n still matches");
17is($1, "a", "Outer /n doesn't affect inner qr//");
18
19$re = qr/(.*) b c d/n;
20ok("a b c d" =~ /$re/, "qr//n matches");
21is($1, undef, "qr//n prevents capturing");
22
23ok("a b c d" =~ $re, "qr// out of // matches");
24is($1, undef, "qr//n prevents capturing");
25
26# Some // tests
27ok("a b c d" =~ /(a) b c d/n, "//n matches");
28is($1, undef, "/n prevents capture");
29
30ok("a b c d" =~ /(a) (b) c d/n, "//n matches with multiple ()");
31is($1, undef, "/n prevents capture in \$1");
32is($2, undef, "/n prevents capture in \$2");
33
34# ?n
35ok("a b c d" =~ /(?n:a) b c (d)/, "?n matches");
36is($1, 'd', "?n: blocked capture");
37
38# ?-n:()
39ok("a b c d" =~ /(?-n:(a)) b c (d)/n, "?-n matches");
40is($1, 'a', "?-n:() disabled nocapture");
41
42ok("a b c d" =~ /(?<a>.) (?<b>.) (.*)/n, "named capture...");
43is($1, 'a', "named capture allows $1 with /n");
44is($2, 'b', "named capture allows $2 with /n");
45is($3, undef, "(.*) didn't capture with /n");
46
47SKIP: {
48    skip "no %+ under miniperl", 2 if is_miniperl();
49    no strict 'refs';
50    is(${"+"}{a}, 'a', "\$+{a} is correct");
51    is(${"+"}{b}, 'b', "\$+{b} is correct");
52}
53
54is(qr/(what)/n,     '(?^n:(what))',
55  'qr//n stringified is correct');
56
57is(qr/(?n:what)/,   '(?^:(?n:what))',
58  'qr/(?n:...)/ stringified is correct');
59
60is(qr/(?-n:what)/,  '(?^:(?-n:what))',
61  'qr/(?-n:...)/ stringified is correct');
62
63is(qr/(?-n:what)/n, '(?^n:(?-n:what))',
64  'qr/(?-n:...)/n stringified is correct');
65
66