use strict;
use warnings;
-use Test::More tests => 2 * 18 + 5 + 1;
+use Test::More tests => 2 * 20 + 6 + 1;
use Variable::Magic qw/cast dispell MGf_COPY VMG_UVAR/;
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/;
'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';
# (copy => 2) x MGf_COPY # if clear magic
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';