Skip to content

Commit

Permalink
Fix the tests for %hash->get()
Browse files Browse the repository at this point in the history
Broken by 26e9cc0

%hash->get() returing an array ref in scalar context is a non starter because
then $val = %hash->get($key) would return an array ref which doesn't make sense.
%hash->get() should probalby be changed to just take one value and leave it to
slice to take multiple keys.
  • Loading branch information
schwern committed Jul 1, 2012
1 parent cac63b9 commit 67f6a8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/autobox/Core.pm
Expand Up @@ -1459,7 +1459,7 @@ sub values {

# local extensions

sub get { my @res = $_[0]->{@_[1..$#_]}; return wantarray ? @res : \@res }
sub get { @{$_[0]}{@_[1..$#_]}; }
*at = *get;

sub put {
Expand Down
17 changes: 9 additions & 8 deletions t/added.t
@@ -1,5 +1,4 @@
use Test::More;
BEGIN { plan tests => 73 };
use Test::More 'no_plan';
use autobox::Core;

#####################################################################
Expand Down Expand Up @@ -107,19 +106,21 @@ is_deeply \@a, [ reverse 1 .. 10 ];
# Hashes
#####################################################################
my $h = {a => 1, b => 2, c => 3};
ok($h->at('b') == 2);
is($h->at('b'), 2);

ok($h->get('c') == 3);
is($h->get('c'), 3);

$h->put('d' => 4, e=>5, f=>6);
ok($h->get('e') == 5);
is($h->get('e'), 5);
$h->put('g', 7);
ok($h->get('g') == 7);
is($h->get('g'), 7);

$h->set('h' => 8);
ok($h->get('h') == 8);
is($h->get('h'), 8);
$h->set('i', 9);
ok($h->get('i') == 9);
is($h->get('i'), 9);

is_deeply [$h->get(qw(a b c))], [1, 2, 3];

is_deeply(
[ sort $h->flatten ],
Expand Down

0 comments on commit 67f6a8a

Please sign in to comment.