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