From: Abigail Date: Thu, 7 Feb 2008 17:53:30 +0000 (+0100) Subject: Re: [perl #50496] Bug Report: 'keys %+' does not return the correct keys. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=66072c921436c766269e73c39b5681133d44af1c;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #50496] Bug Report: 'keys %+' does not return the correct keys. Message-ID: <20080207165330.GA25617@abigail.be> with tweaks (one more test marked TODO) p4raw-id: //depot/perl@33313 --- diff --git a/t/op/pat.t b/t/op/pat.t index d2bc85a..3c446e0 100755 --- a/t/op/pat.t +++ b/t/op/pat.t @@ -3761,6 +3761,46 @@ sub iseq($$;$) { ok(!$@,'lvalue $+{...} should not throw an exception'); } { + # + # Almost the same as the block above, except that the capture is nested. + # + my $s = 'foo bar baz'; + my (@k,@v,@fetch,$res); + my $count = 0; + my @names = qw($+{A} $+{B} $+{C} $+{D}); + if ($s = ~/(?(?foo)\s+(?bar)?\s+(?baz))/) { + while (my ($k,$v) = each(%+)) { + $count++; + } + @k = sort keys(%+); + @v = sort values(%+); + $res = 1; + push @fetch, + [ "$+{A}", "$2" ], + [ "$+{B}", "$3" ], + [ "$+{C}", "$4" ], + [ "$+{D}", $1 ], + ; + } + foreach (0..3) { + if ($fetch[$_]) { + local $TODO = $_ == 3; + iseq($fetch[$_][0],$fetch[$_][1],$names[$_]); + } else { + ok(0, $names[$_]); + } + } + iseq($res,1,"$s~=/(?(?foo)\s+(?bar)?\s+(?baz))/"); + iseq($count,4,"Got 4 keys in %+ via each # TODO bug 50496"); + iseq(0+@k, 4, 'Got 4 keys in %+ via keys # TODO bug 50496'); + iseq("@k","A B C D", "Got expected keys # TODO bug 50496"); + iseq("@v","bar baz foo foo bar baz", "Got expected values # TODO bug = 50496"); + eval' + print for $+{this_key_doesnt_exist}; + '; + ok(!$@,'lvalue $+{...} should not throw an exception'); +} +{ my $s='foo bar baz'; my @res; if ('1234'=~/(?1)(?2)(?3)(?4)/) { @@ -4619,7 +4659,7 @@ iseq(0+$::test,$::TestCount,"Got the right number of tests!"); # Don't forget to update this! BEGIN { - $::TestCount = 4019; + $::TestCount = 4029; print "1..$::TestCount\n"; }