Commit | Line | Data |
---|---|---|
557a4468 NC |
1 | #!./perl -w |
2 | use strict; | |
3 | ||
4 | use Test::More; | |
5 | ||
1a1d29aa VF |
6 | my %hashes = ( |
7 | '+' => \%+, | |
8 | '-' => \%-, | |
9 | '{^CAPTURE}' => \%{^CAPTURE}, | |
10 | '{^CAPTURE_ALL}' => \%{^CAPTURE_ALL}, | |
11 | ); | |
557a4468 NC |
12 | |
13 | foreach (['plus1'], | |
14 | ['minus1', all => 1], | |
15 | ['plus2', all => 0], | |
16 | ['plus3', zlonk => 1], | |
17 | ['minus2', thwapp => 0, all => 1], | |
18 | ) { | |
19 | my $name = shift @$_; | |
20 | my $hash = $hashes{$name} = {}; | |
21 | isa_ok(tie(%$hash, 'Tie::Hash::NamedCapture', @$_), | |
22 | 'Tie::Hash::NamedCapture', "%$name"); | |
23 | } | |
24 | ||
25 | is("abcdef" =~ /(?<foo>[ab])*(?<bar>c)(?<foo>d)(?<bar>[ef]*)/, 1, | |
26 | "We matched"); | |
27 | ||
1a1d29aa | 28 | foreach my $name (qw(+ {^CAPTURE} plus1 plus2 plus3)) { |
557a4468 NC |
29 | my $hash = $hashes{$name}; |
30 | is_deeply($hash, { foo => 'b', bar => 'c' }, "%$name is as expected"); | |
31 | } | |
32 | ||
1a1d29aa | 33 | foreach my $name (qw(- {^CAPTURE_ALL} minus1 minus2)) { |
557a4468 NC |
34 | my $hash = $hashes{$name}; |
35 | is_deeply($hash, { foo => [qw(b d)], bar => [qw(c ef)] }, | |
36 | "%$name is as expected"); | |
37 | } | |
38 | ||
39 | done_testing(); |