From: Ruslan Zakirov Date: Mon, 8 Oct 2012 18:48:52 +0000 (+0400) Subject: make sure hash assignment is proper lvalue X-Git-Tag: upstream/5.20.0~4512^2~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=96e574609cc4b7f8d8969f8da065712307311f41;p=platform%2Fupstream%2Fperl.git make sure hash assignment is proper lvalue --- diff --git a/t/op/hashassign.t b/t/op/hashassign.t index a0b8cf9..a362f96 100644 --- a/t/op/hashassign.t +++ b/t/op/hashassign.t @@ -8,7 +8,7 @@ BEGIN { # use strict; -plan tests => 238; +plan tests => 244; my @comma = ("key", "value"); @@ -368,4 +368,26 @@ SKIP: { ok( eq_hash( \%h, {1 => undef} ), "correct value stored" ); } +# lvaluedness of list context +{ + my %h; my $x; + $_++ foreach %h = (1,2,3,4); + ok( eq_hash( \%h, {1 => 3, 3 => 5} ), "aassign in list context returns lvalues" ); + + $_++ foreach %h = (1,2,1,4); + ok( eq_hash( \%h, {1 => 5} ), "the same for assignment with duplicates" ); + + $x = 0; + $_++ foreach %h = ($x,$x); + is($x, 0, "returned values are not binded to RHS of the assignment operation"); + + $_++ foreach ($x, %h) = (0,1,2,3,4); + is( $x, 1, "... and leading scalar" ); + ok( eq_hash( \%h, {1 => 3, 3 => 5} ), "... scalar followed by hash" ); + + no warnings 'misc'; + $_++ foreach %h = (1,2,3); + ok( eq_hash( \%h, {1 => 3, 3 => 1} ), "odd elements also lvalued" ); +} +