Permalink
Browse files

Added tests for keys and values. Patched so that it returns a list in…

… list context (fixes RT 45421)
  • Loading branch information...
1 parent 4d67fdc commit 5b47268132a23068f4123aa357e5b0163707dfb4 @brunoV brunoV committed Mar 6, 2010
Showing with 29 additions and 2 deletions.
  1. +2 −2 Core.pm
  2. +13 −0 t/keys.t
  3. +14 −0 t/values.t
View
@@ -847,8 +847,8 @@ use Carp 'croak';
sub delete (\%@) { my $hash = CORE::shift; my @res = (); CORE::foreach(@_) { push @res, CORE::delete $hash->{$_}; } CORE::wantarray ? @res : \@res }
sub exists (\%$) { my $hash = CORE::shift; CORE::exists $hash->{$_[0]}; }
-sub keys (\%) { [ CORE::keys %{$_[0]} ] }
-sub values (\%) { [ CORE::values %{$_[0]} ] }
+sub keys (\%) { wantarray ? CORE::keys %{$_[0]} : [ CORE::keys %{$_[0]} ] }
+sub values (\%) { wantarray ? CORE::values %{$_[0]} : [ CORE::values %{$_[0]} ] }
sub at (\%@) { $_[0]->{@_[1..$#_]}; }
sub get(\%@) { $_[0]->{@_[1..$#_]}; }
View
@@ -0,0 +1,13 @@
+use Test::More qw(no_plan);
+use strict;
+use warnings;
+
+use autobox::Core;
+
+my %hash = ( foo => 1, bar => 2, baz => 3 );
+
+is_deeply [ sort %hash->keys ], [ qw( bar baz foo ) ];
+
+my $arrayref = %hash->keys;
+
+is ref $arrayref, 'ARRAY', "Returns arrayref in scalar context";
View
@@ -0,0 +1,14 @@
+use Test::More qw(no_plan);
+use strict;
+use warnings;
+
+use autobox::Core;
+
+my %hash = ( foo => 1, bar => 2, baz => 3 );
+
+is_deeply [ sort %hash->values ], [ qw( 1 2 3 ) ];
+
+my $arrayref = %hash->values;
+
+is ref $arrayref, 'ARRAY', "Returns arrayref in scalar context";
+

0 comments on commit 5b47268

Please sign in to comment.