Acme-Perl-VM

 view release on metacpan or  search on metacpan

t/09_hash.t  view on Meta::CPAN

#!perl -w

use strict;
use Test::More tests => 24;

use Acme::Perl::VM;
use Acme::Perl::VM qw(:perl_h);

sub Dump{
    require Data::Dumper;
    diag(Data::Dumper::Dumper(@_));
}

my $x = run_block{
    my %h;
};
ok !$x;

$x = run_block{
    my %h = (key => 10);
};
ok $x;

my %hash = run_block{
    my %h = (foo => 10, bar => 20);
};
is_deeply(\%hash, { foo => 10, bar => 20 }) or Dump(\%hash);

%hash = run_block{
    our %h = (foo => 10, bar => 20);
};
is_deeply(\%hash, { foo => 10, bar => 20 }) or Dump(\%hash);

%hash = run_block{
    my %h = (foo => 10, foo => 20, bar => 30);
};
is_deeply \%hash, { foo => 20, bar => 30 } or Dump($x);

%hash = run_block{
    my %h = (a => 1, foo => 10, b => 2, foo => 20, c => 3);
};
is_deeply \%hash, { a => 1, foo => 10, b => 2, foo => 20, c => 3 };

$x = run_block{
    my %h = (foo => 10, bar => 20);
    return \%h;
};
is_deeply $x, { foo => 10, bar => 20 } or Dump($x);

$x = run_block{
    my %h = (foo => 10, bar => 20);
    $h{foo} = $h{bar} + 1;
    return \%h;
};
is_deeply $x, { foo => 21, bar => 20 } or Dump($x);

$x = run_block{
    my %h = (foo => 10, bar => 20);
    return $h{foo};
};
is_deeply $x, 10;

$x = run_block{
    our %h = (foo => 10, bar => 20);
    return $h{foo};
};
is_deeply $x, 10;
$x = run_block{
    our %h = (foo => 10, bar => 20);
    return \$h{foo};
};



( run in 0.435 second using v1.01-cache-2.11-cpan-96521ef73a4 )