This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
%{^CAPTURE_ALL} was intended to be an alias for %-; make it so.
[perl5.git] / ext / Tie-Hash-NamedCapture / t / tiehash.t
CommitLineData
557a4468
NC
1#!./perl -w
2use strict;
3
4use Test::More;
5
1a1d29aa
VF
6my %hashes = (
7 '+' => \%+,
8 '-' => \%-,
9 '{^CAPTURE}' => \%{^CAPTURE},
10 '{^CAPTURE_ALL}' => \%{^CAPTURE_ALL},
11);
557a4468
NC
12
13foreach (['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
25is("abcdef" =~ /(?<foo>[ab])*(?<bar>c)(?<foo>d)(?<bar>[ef]*)/, 1,
26 "We matched");
27
1a1d29aa 28foreach 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 33foreach 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
39done_testing();