X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F32-hash.t;h=863905369642f14b014b353ff40e8326fec367e9;hb=4bd887f284d695d973ce89a5f40e6528561b2d6d;hp=483d9671e93bfed7e4ac1935f0d6c85740293f14;hpb=14f66d40970bef63105be046a109c1a32859a8a0;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/32-hash.t b/t/32-hash.t index 483d967..8639053 100644 --- a/t/32-hash.t +++ b/t/32-hash.t @@ -3,78 +3,102 @@ use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 18; -use Variable::Magic qw/wizard cast dispell/; +use Variable::Magic qw/wizard cast dispell MGf_COPY VMG_UVAR/; -my @c = (0) x 5; -my @x = (0) x 5; +my @c = (0) x 12; +my @x = (0) x 12; sub check { - for (0 .. 4) { return 0 unless $c[$_] == $x[$_]; } - return 1; + is join(':', map { (defined) ? $_ : 'u' } @c[0 .. 11]), + join(':', map { (defined) ? $_ : 'u' } @x[0 .. 11]), + $_[0]; } my $wiz = wizard get => sub { ++$c[0] }, set => sub { ++$c[1] }, len => sub { ++$c[2]; $_[2] }, clear => sub { ++$c[3] }, - free => sub { ++$c[4] }; -ok(check(), 'hash : create wizard'); + 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] }; +check('hash : create wizard'); my %n = map { $_ => int rand 1000 } qw/foo bar baz qux/; my %a = %n; cast %a, $wiz; -ok(check(), 'hash : cast'); +check('hash : cast'); my $b = $a{foo}; -ok(check(), 'hash : assign element to'); +++$x[5] if MGf_COPY; +++$x[8] if VMG_UVAR; +check('hash : assign element to'); my %b = %a; -ok(check(), 'hash : assign to'); +check('hash : assign to'); $b = "X%{a}Y"; -ok(check(), 'hash : interpolate'); +check('hash : interpolate'); $b = \%a; -ok(check(), 'hash : reference'); +check('hash : reference'); my @b = @a{qw/bar qux/}; -ok(check(), 'hash : slice'); +$x[5] += 2 if MGf_COPY; +$x[8] += 2 if VMG_UVAR; +check('hash : slice'); + +%a = (a => 1, d => 3); +++$x[3]; +$x[5] += 2 if VMG_UVAR; +$x[9] += 2 if VMG_UVAR; +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; +check('hash : assign from map'); $a{d} = 2; -ok(check(), 'hash : assign old element'); +++$x[5] if MGf_COPY; +++$x[9] if VMG_UVAR; +check('hash : assign old element'); $a{c} = 3; -ok(check(), 'hash : assign new element'); +++$x[5] if MGf_COPY; +++$x[9] if VMG_UVAR; +check('hash : assign new element'); $b = %a; -ok(check(), 'hash : buckets'); +check('hash : buckets'); @b = keys %a; -ok(check(), 'hash : keys'); +check('hash : keys'); @b = values %a; -ok(check(), 'hash : values'); +check('hash : values'); while (my ($k, $v) = each %a) { } -ok(check(), 'hash : each'); +check('hash : each'); { my %b = %n; cast %b, $wiz; } ++$x[4]; -ok(check(), 'hash : scope end'); +check('hash : scope end'); undef %a; ++$x[3]; -ok(check(), 'hash : undef'); +check('hash : undef'); dispell %a, $wiz; -ok(check(), 'hash : dispel'); +check('hash : dispel');