6 use Test::More tests => 2 * 18 + 5 + 1;
8 use Variable::Magic qw/cast dispell MGf_COPY VMG_UVAR/;
11 use Variable::Magic::TestWatcher;
14 [ qw/get set len free dup local fetch store exists delete/ ], # clear copy
17 my %n = map { $_ => int rand 1000 } qw/foo bar baz qux/;
20 check { cast %h, $wiz } { }, 'cast';
23 check { $s = $h{foo} } +{ (fetch => 1) x VMG_UVAR },
24 # (copy => 1) x MGf_COPY # if clear magic
26 is $s, $n{foo}, 'hash: assign element to correctly';
29 check { %b = %h } { }, 'assign to';
30 is_deeply \%b, \%n, 'hash: assign to correctly';
32 check { $s = \%h } { }, 'reference';
35 check { @b = @h{qw/bar qux/} }
36 +{ (fetch => 2) x VMG_UVAR }, 'slice';
37 # (copy => 2) x MGf_COPY # if clear magic
38 is_deeply \@b, [ @n{qw/bar qux/} ], 'hash: slice correctly';
40 check { %h = (a => 1, d => 3); () }
41 +{ (store => 2) x VMG_UVAR },
42 # clear => 1, (copy => 2) x VMG_UVAR
43 'assign from list in void context';
45 check { %h = map { $_ => 1 } qw/a b d/; }
46 +{ (exists => 3, store => 3) x VMG_UVAR },
47 # clear => 1, (copy => 3) x VMG_UVAR
48 'assign from map in list context';
50 check { $h{d} = 2; () } +{ (store => 1) x VMG_UVAR },
53 check { $h{c} = 3; () } +{ (store => 1) x VMG_UVAR },
54 # (copy => 1) x VMG_UVAR # maybe also if clear magic
57 check { $s = %h } { }, 'buckets';
59 check { @b = keys %h } { }, 'keys';
60 is_deeply [ sort @b ], [ qw/a b c d/ ], 'hash: keys correctly';
62 check { @b = values %h } { }, 'values';
63 is_deeply [ sort { $a <=> $b } @b ], [ 1, 1, 2, 3 ], 'hash: values correctly';
65 check { while (my ($k, $v) = each %h) { } } { }, 'each';
69 check { cast %b, $wiz } { }, 'cast 2';
70 } { free => 1 }, 'scope end';
72 check { undef %h } { }, 'undef'; # clear => 1
74 check { dispell %h, $wiz } { }, 'dispell';