Skip to content

Commit

Permalink
more grep tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 3, 2012
1 parent 1585084 commit 21b9832
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/Mojo/Collection.pm
Expand Up @@ -36,8 +36,7 @@ sub first {
# I can get by with one."
sub grep {
my ($self, $cb) = @_;
return $self->new(grep { $_->$cb } @$self) if ref $cb eq 'CODE';
return $self->new(grep { $_ =~ $cb } @$self);
return $self->new(grep { $_ ~~ $cb } @$self);
}

sub join {
Expand Down
6 changes: 5 additions & 1 deletion t/mojo/collection.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 50;
use Test::More tests => 52;

# "'What are you lookin at?' - the innocent words of a drunken child."
use Mojo::Collection 'c';
Expand Down Expand Up @@ -37,6 +37,10 @@ is $collection->first(sub { defined $_ }), undef, 'no result';
# grep
$collection = c(1, 2, 3, 4, 5, 6, 7, 8, 9);
is_deeply [$collection->grep(qr/[6-9]/)->each], [6, 7, 8, 9], 'right elements';
is_deeply [$collection->grep(sub {/[6-9]/})->each], [6, 7, 8, 9],
'right elements';
is_deeply [$collection->grep(sub { $_ > 5 })->each], [6, 7, 8, 9],
'right elements';
is_deeply [$collection->grep(sub { $_ < 5 })->each], [1, 2, 3, 4],
'right elements';
is_deeply [$collection->grep(sub { shift == 5 })->each], [5], 'right elements';
Expand Down

0 comments on commit 21b9832

Please sign in to comment.