summaryrefslogtreecommitdiff
path: root/t/op/hashassign.t
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-11-13 18:55:37 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-11-13 18:55:37 +0000
commitca65944e8ff8fff6e36ea7476ba807be16cfe2a9 (patch)
tree854c7a750e4e61d1b9844a003ba85cdb144270dd /t/op/hashassign.t
parenta9d9270b1989803b2cc2c5f6d551fe8565bcc2d0 (diff)
downloadperl-ca65944e8ff8fff6e36ea7476ba807be16cfe2a9.tar.gz
Fix bug [perl #24380] : assigning to a hash in list
or scalar context yielded a wrong value if the list contained duplicated keys for the hash. This is fixed by counting the number of duplicate keys and trimming the stack by the corresponding number of items. p4raw-id: //depot/perl@21714
Diffstat (limited to 't/op/hashassign.t')
-rw-r--r--t/op/hashassign.t20
1 files changed, 18 insertions, 2 deletions
diff --git a/t/op/hashassign.t b/t/op/hashassign.t
index a1c66c38dc..7058d75df1 100644
--- a/t/op/hashassign.t
+++ b/t/op/hashassign.t
@@ -8,7 +8,7 @@ BEGIN {
# use strict;
-plan tests => 206;
+plan tests => 213;
my @comma = ("key", "value");
@@ -272,4 +272,20 @@ foreach my $chr (60, 200, 600, 6000, 60000) {
}
-
+# now some tests for hash assignment in scalar and list context with
+# duplicate keys [perl #24380]
+{
+ my %h; my $x; my $ar;
+ is( (join ':', %h = (1) x 8), '1:1',
+ 'hash assignment in list context removes duplicates' );
+ is( scalar( %h = (1,2,1,3,1,4,1,5) ), 2,
+ 'hash assignment in scalar context' );
+ is( scalar( ($x,%h) = (0,1,2,1,3,1,4,1,5) ), 3,
+ 'scalar + hash assignment in scalar context' );
+ $ar = [ %h = (1,2,1,3,1,4,1,5) ];
+ is( $#$ar, 1, 'hash assignment in list context' );
+ is( "@$ar", "1 5", '...gets the last values' );
+ $ar = [ ($x,%h) = (0,1,2,1,3,1,4,1,5) ];
+ is( $#$ar, 2, 'scalar + hash assignment in list context' );
+ is( "@$ar", "0 1 5", '...gets the last values' );
+}