X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F32-hash.t;h=703bcd3df82b5f4c30e1b7495fc24accfe5f1d46;hb=ae4a0a994e98c604732190116636b349e7779311;hp=5cc5e1f2a6ad4ce9c322344c7cd26646176d01f1;hpb=b34eec5b227be170f3cf8efdb8aaae400370960b;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/32-hash.t b/t/32-hash.t index 5cc5e1f..703bcd3 100644 --- a/t/32-hash.t +++ b/t/32-hash.t @@ -3,9 +3,13 @@ use strict; use warnings; -use Test::More tests => (2 * 22 + 7) + (2 * 5 + 5) + 1; +use Test::More tests => (2 * 27 + 9) + (2 * 5 + 5) + 1; -use Variable::Magic qw; +use Variable::Magic qw< + cast dispell + VMG_UVAR + VMG_COMPAT_HASH_DELETE_NOUVAR_VOID +>; use lib 't/lib'; use Variable::Magic::TestWatcher; @@ -23,11 +27,6 @@ my $s = watch { $h{foo} } +{ (fetch => 1) x VMG_UVAR }, 'assign element to'; is $s, $n{foo}, 'hash: assign element to correctly'; -for (1 .. 2) { - $s = watch { exists $h{foo} } +{ (exists => 1) x VMG_UVAR }, "exists ($_)"; - ok $s, "hash: exists correctly ($_)"; -} - my %b; watch { %b = %h } { }, 'assign to'; is_deeply \%b, \%n, 'hash: assign to correctly'; @@ -38,8 +37,37 @@ my @b = watch { @h{qw} } +{ (fetch => 2) x VMG_UVAR }, 'slice'; is_deeply \@b, [ @n{qw} ], 'hash: slice correctly'; +# exists + +watch { exists $h{bar} } +{ (exists => 1) x VMG_UVAR },'exists in void context'; + +for (1 .. 2) { + $s = watch { exists $h{bar} } +{ (exists => 1) x VMG_UVAR }, + "exists in scalar context ($_)"; + ok $s, "hash: exists correctly ($_)"; +} + +# delete + +watch { delete $h{bar} } +{ + ((delete => 1) x !VMG_COMPAT_HASH_DELETE_NOUVAR_VOID, copy => 1) x VMG_UVAR +}, 'delete in void context'; + +for (1 .. 2) { + $s = watch { delete $h{baz} } +{ (delete => 1, copy => 1) x VMG_UVAR }, + "delete in scalar context ($_)"; + my $exp = $_ == 1 ? $n{baz} : undef; + is $s, $exp, "hash: delete correctly ($_)"; +} + +# clear + watch { %h = () } { clear => 1 }, 'empty in list context'; +watch { $h{a} = -1; %h = (b => $h{a}) } + +{ (fetch => 1, store => 2, copy => 2) x VMG_UVAR, clear => 1 }, + 'empty and set in void context'; + watch { %h = (a => 1, d => 3) } +{ (store => 2, copy => 2) x VMG_UVAR, clear => 1 }, 'assign from list in void context';