From: Jason May Date: Wed, 2 Jul 2008 15:50:01 +0000 (+0000) Subject: add tests for coderef support in the currying feature X-Git-Tag: 0.16~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=72d4751272b884d1383c1656b183cefcae0eda89;p=gitmo%2FMooseX-AttributeHelpers.git add tests for coderef support in the currying feature --- diff --git a/t/005_basic_list.t b/t/005_basic_list.t index 8a90719..d4a49b7 100644 --- a/t/005_basic_list.t +++ b/t/005_basic_list.t @@ -7,7 +7,7 @@ use Test::More; use Test::Exception; BEGIN { - plan tests => 28; + plan tests => 29; } BEGIN { @@ -42,6 +42,21 @@ BEGIN { 'join' => {dashify => [ '-' ]} } ); + + has animals => ( + is => 'rw', + isa => 'ArrayRef[Str]', + metaclass => 'Collection::List', + curries => { + grep => { + double_length_of => sub { + my ($self, $body, $arg) = @_; + + $body->($self, sub { length($_) == length($arg) * 2 }); + } + } + } + ) } my $stuff = Stuff->new(options => [ 1 .. 10 ]); @@ -92,6 +107,15 @@ is_deeply([ $stuff->up_by_one() ], [2 .. 11]); is($stuff->dashify, '1-2-3-4-5-6-7-8-9-10'); +$stuff->animals([ qw/cat duck horse cattle gorilla elephant flamingo kangaroo/ ]); + +# 4 * 2 = 8 +is_deeply( + [ sort $stuff->double_length_of('fish') ], + [ sort qw/elephant flamingo kangaroo/ ], + 'returns all elements with double length of string "fish"' +); + ## test the meta my $options = $stuff->meta->get_attribute('_options');