X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F32-hash.t;h=572f5e668e42fe18033cd0765ba7e4ef652bc152;hb=9e65e9bfbd5fa2ee747e865d1471b26ec229383c;hp=74eabb81ab038980349add35fc474a56eae7e036;hpb=77a84f75f33e3ee44e61182dec76699e23025375;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/32-hash.t b/t/32-hash.t index 74eabb8..572f5e6 100644 --- a/t/32-hash.t +++ b/t/32-hash.t @@ -1,14 +1,17 @@ #!perl -T -use Test::More tests => 17; +use strict; +use warnings; -use Variable::Magic qw/wizard cast dispell/; +use Test::More tests => 18; -my @c = (0) x 5; -my @x = (0) x 5; +use Variable::Magic qw/wizard cast dispell MGf_COPY VMG_UVAR/; + +my @c = (0) x 12; +my @x = (0) x 12; sub check { - for (0 .. 4) { return 0 unless $c[$_] == $x[$_]; } + for (0 .. 11) { return 0 unless $c[$_] == $x[$_]; } return 1; } @@ -16,7 +19,14 @@ my $wiz = wizard get => sub { ++$c[0] }, set => sub { ++$c[1] }, len => sub { ++$c[2]; $_[2] }, clear => sub { ++$c[3] }, - free => sub { ++$c[4] }; + free => sub { ++$c[4] }, + copy => sub { ++$c[5] }, + dup => sub { ++$c[6] }, + local => sub { ++$c[7] }, + fetch => sub { ++$c[8] }, + store => sub { ++$c[9] }, + 'exists' => sub { ++$c[10] }, + 'delete' => sub { ++$c[11] }; ok(check(), 'hash : create wizard'); my %n = map { $_ => int rand 1000 } qw/foo bar baz qux/; @@ -26,6 +36,8 @@ cast %a, $wiz; ok(check(), 'hash : cast'); my $b = $a{foo}; +++$x[5] if MGf_COPY; +++$x[8] if VMG_UVAR; ok(check(), 'hash : assign element to'); my %b = %a; @@ -38,16 +50,30 @@ $b = \%a; ok(check(), 'hash : reference'); my @b = @a{qw/bar qux/}; +$x[5] += 2 if MGf_COPY; +$x[8] += 2 if VMG_UVAR; ok(check(), 'hash : slice'); +%a = (a => 1, d => 3); +++$x[3]; +$x[5] += 2 if VMG_UVAR; +$x[9] += 2 if VMG_UVAR; +ok(check(), 'hash : assign from list'); + %a = map { $_ => 1 } qw/a b d/; ++$x[3]; -ok(check(), 'hash : assign'); +$x[5] += 3 if VMG_UVAR; +$x[9] += 3 if VMG_UVAR; +ok(check(), 'hash : assign from map'); $a{d} = 2; +++$x[5] if MGf_COPY; +++$x[9] if VMG_UVAR; ok(check(), 'hash : assign old element'); $a{c} = 3; +++$x[5] if MGf_COPY; +++$x[9] if VMG_UVAR; ok(check(), 'hash : assign new element'); $b = %a; @@ -64,9 +90,9 @@ ok(check(), 'hash : each'); { my %b = %n; -# cast %b, $wiz; + cast %b, $wiz; } -#++$x[4]; +++$x[4]; ok(check(), 'hash : scope end'); undef %a;