]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/32-hash.t
Show copy_key in wizard()'s synopsys
[perl/modules/Variable-Magic.git] / t / 32-hash.t
index d04c366a3a1688f38baa4eff3ff307291a8941c1..164c6ed51091e97a18b9ad2e8f836fc8ff38f079 100644 (file)
@@ -3,7 +3,7 @@
 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/;
 
@@ -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';
@@ -37,21 +40,20 @@ check { @b = @h{qw/bar qux/} }
                   # (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';