X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F32-hash.t;h=164c6ed51091e97a18b9ad2e8f836fc8ff38f079;hb=2aeba77195a5533f86ad063f8e61c1d698c2f830;hp=4686d27dbdaa75547a71594e692bb92392946990;hpb=997fe5643a5c203315ff26f4e4bf7840fb33a9d8;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/32-hash.t b/t/32-hash.t index 4686d27..164c6ed 100644 --- a/t/32-hash.t +++ b/t/32-hash.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 2 * 19 + 5 + 1; +use Test::More tests => 2 * 20 + 6 + 1; use Variable::Magic qw/cast dispell MGf_COPY VMG_UVAR/; @@ -11,7 +11,7 @@ use lib 't/lib'; use Variable::Magic::TestWatcher; my $wiz = init - [ qw/get set len free dup local fetch store exists delete/ ], # clear copy + [ qw/get set len free copy dup local fetch store exists delete/ ], # clear 'hash'; my %n = map { $_ => int rand 1000 } qw/foo bar baz qux/; @@ -25,6 +25,9 @@ check { $s = $h{foo} } +{ (fetch => 1) x VMG_UVAR }, 'assign element to'; is $s, $n{foo}, 'hash: assign element to correctly'; +$s = check { exists $h{foo} } +{ (exists => 1) x VMG_UVAR }, 'exists'; +ok $s, 'hash: exists correctly'; + my %b; check { %b = %h } { }, 'assign to'; is_deeply \%b, \%n, 'hash: assign to correctly'; @@ -40,20 +43,17 @@ is_deeply \@b, [ @n{qw/bar qux/} ], 'hash: slice correctly'; check { %h = () } { }, 'empty in list context'; # clear => 1 check { %h = (a => 1, d => 3); () } - +{ (store => 2) x VMG_UVAR }, - # clear => 1, (copy => 2) x VMG_UVAR + +{ (store => 2, copy => 2) x VMG_UVAR }, # clear => 1 'assign from list in void context'; check { %h = map { $_ => 1 } qw/a b d/; } - +{ (exists => 3, store => 3) x VMG_UVAR }, - # clear => 1, (copy => 3) x VMG_UVAR + +{ (exists => 3, store => 3, copy => 3) x VMG_UVAR }, # clear =>1 'assign from map in list context'; check { $h{d} = 2; () } +{ (store => 1) x VMG_UVAR }, 'assign old element'; -check { $h{c} = 3; () } +{ (store => 1) x VMG_UVAR }, - # (copy => 1) x VMG_UVAR # maybe also if clear magic +check { $h{c} = 3; () } +{ (store => 1, copy => 1) x VMG_UVAR }, 'assign new element'; check { $s = %h } { }, 'buckets';