make sure hash assignment is proper lvalue
authorRuslan Zakirov <ruz@bestpractical.com>
Mon, 8 Oct 2012 18:48:52 +0000 (22:48 +0400)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 11 Dec 2012 16:59:40 +0000 (08:59 -0800)
t/op/hashassign.t

index a0b8cf9..a362f96 100644 (file)
@@ -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" );
+}
+