diff options
author | Nicholas Clark <nick@ccl4.org> | 2021-07-21 11:55:57 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2021-07-26 07:06:00 +0000 |
commit | 745e94a0ed91f09322e8188e2b5b0df8cd9aeca8 (patch) | |
tree | 39fa6c4bace9d4d40a158a7113f1e7c45798493f /t | |
parent | 2517717a8902648de577d07f548caba6e3f2ecea (diff) | |
download | perl-745e94a0ed91f09322e8188e2b5b0df8cd9aeca8.tar.gz |
Tests for tied hashes in list context (keys, values and both).
These weren't explicitly tested before.
Diffstat (limited to 't')
-rw-r--r-- | t/op/tie.t | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/t/op/tie.t b/t/op/tie.t index bfcafce87a..565518c027 100644 --- a/t/op/tie.t +++ b/t/op/tie.t @@ -21,6 +21,48 @@ done_testing(); __END__ +######## +# tied hash in list context +use Tie::Hash; +my %tied; +tie %tied, "Tie::StdHash"; +%tied = qw(perl rules beer foamy); +my @a = %tied; +if ($a[0] eq 'beer') { + print "@a\n"; +} else { + # Must do this explicitly (not sort) to spot if keys and values are muddled + print "$a[2] $a[3] $a[0] $a[1]\n" +} + +EXPECT +beer foamy perl rules +######## +# tied hash keys in list context +use Tie::Hash; +my %tied; +tie %tied, "Tie::StdHash"; +%tied = qw(perl rules beer foamy); +my @a = keys %tied; +@a = sort @a; +print "@a\n"; + +EXPECT +beer perl +######## +# tied hash values in list context +use Tie::Hash; +my %tied; +tie %tied, "Tie::StdHash"; +%tied = qw(perl rules beer foamy); +my @a = values %tied; +@a = sort @a; +print "@a\n"; + +EXPECT +foamy rules +######## + # standard behaviour, without any extra references use Tie::Hash ; tie %h, Tie::StdHash; |