]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/32-hash.t
Test loop ops
[perl/modules/Variable-Magic.git] / t / 32-hash.t
index c2697d54d0d0ad835ed2023627db8553bfaf4f93..bf01b3dccfd522dda858c59b9a818677525257dd 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 2 * 19 + 5 + 1;
+use Test::More tests => 2 * 21 + 7 + 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 copy dup local fetch store exists delete/ ], # clear
+        [ qw/get set len clear free copy dup local fetch store exists delete/ ],
         'hash';
 
 my %n = map { $_ => int rand 1000 } qw/foo bar baz qux/;
@@ -19,32 +19,33 @@ my %h = %n;
 
 check { cast %h, $wiz } { }, 'cast';
 
-my $s;
-check { $s = $h{foo} } +{ (fetch => 1) x VMG_UVAR },
-                       # (copy => 1) x MGf_COPY # if clear magic
+my $s = check { $h{foo} } +{ (fetch => 1) x VMG_UVAR },
                        'assign element to';
 is $s, $n{foo}, 'hash: assign element to correctly';
 
+for (1 .. 2) {
+ $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';
 
-check { $s = \%h } { }, 'reference';
+$s = check { \%h } { }, 'reference';
 
-my @b;
-check { @b = @h{qw/bar qux/} }
+my @b = check { @h{qw/bar qux/} }
                   +{ (fetch => 2) x VMG_UVAR }, 'slice';
-                  # (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 = () } { clear => 1 }, 'empty in list context';
 
 check { %h = (a => 1, d => 3); () }
-               +{ (store => 2, copy => 2) x VMG_UVAR }, # clear => 1
+               +{ (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, copy => 3) x VMG_UVAR }, # clear =>1
+               +{ (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 },
@@ -53,12 +54,12 @@ check { $h{d} = 2; () } +{ (store => 1) x VMG_UVAR },
 check { $h{c} = 3; () } +{ (store => 1, copy => 1) x VMG_UVAR },
                     'assign new element';
 
-check { $s = %h } { }, 'buckets';
+$s = check { %h } { }, 'buckets';
 
-check { @b = keys %h } { }, 'keys';
+@b = check { keys %h } { }, 'keys';
 is_deeply [ sort @b ], [ qw/a b c d/ ], 'hash: keys correctly';
 
-check { @b = values %h } { }, 'values';
+@b = check { values %h } { }, 'values';
 is_deeply [ sort { $a <=> $b } @b ], [ 1, 1, 2, 3 ], 'hash: values correctly';
 
 check { while (my ($k, $v) = each %h) { } } { }, 'each';
@@ -68,6 +69,6 @@ check {
  check { cast %b, $wiz } { }, 'cast 2';
 } { free => 1 }, 'scope end';
 
-check { undef %h } { }, 'undef'; # clear => 1
+check { undef %h } { clear => 1 }, 'undef';
 
 check { dispell %h, $wiz } { }, 'dispell';