use strict;
use warnings;
-use Test::More tests => 25;
+use Test::More;
use Test::Exception;
-use DateTime;
-use DateTime::Format::Strptime;
+
+BEGIN {
+ plan tests => 36;
+}
BEGIN {
use_ok('MooseX::AttributeHelpers');
'find' => 'find_option',
'elements' => 'options',
'join' => 'join_options',
+ 'get' => 'get_option_at',
+ 'first' => 'get_first_option',
+ 'last' => 'get_last_option',
+ 'contains' => 'options_contains',
},
curries => {
'grep' => {less_than_five => [ sub { $_ < 5 } ]},
}
);
- has datetimes => (
+ has animals => (
+ is => 'rw',
+ isa => 'ArrayRef[Str]',
metaclass => 'Collection::List',
- is => 'rw',
- isa => 'ArrayRef[DateTime]',
curries => {
- grep => {
- times_with_day => sub {
- my ($self, $body, $datetime) = @_;
- $body->($self, sub { $_->ymd eq $datetime->ymd });
- },
- },
- },
- );
+ grep => {
+ double_length_of => sub {
+ my ($self, $body, $arg) = @_;
+
+ $body->($self, sub { length($_) == length($arg) * 2 });
+ }
+ }
+ }
+ )
}
my $stuff = Stuff->new(options => [ 1 .. 10 ]);
find_option
options
join_options
+ get_option_at
+ options_contains
];
is_deeply($stuff->_options, [1 .. 10], '... got options');
ok($stuff->has_options, '... we have options');
is($stuff->num_options, 10, '... got 2 options');
+cmp_ok($stuff->get_option_at(0), '==', 1, '... get option 0');
+cmp_ok($stuff->get_first_option, '==', 1, '... get first');
+cmp_ok($stuff->get_last_option, '==', 10, '... get first');
is_deeply(
[ $stuff->filter_options(sub { $_[0] % 2 == 0 }) ],
is($stuff->join_options(':'), '1:2:3:4:5:6:7:8:9:10', '... joined the list of options by :');
+is($stuff->options_contains(), 0 ,'... does not contain undef');
+is($stuff->options_contains(5), 1 ,'... contains "5"');
+is($stuff->options_contains(11), 0 ,'... does not contain "11"');
+
+push @{$stuff->_options}, undef;
+is($stuff->options_contains(undef), 1 ,'... does contain undef');
+
+push @{$stuff->_options}, 5;
+is($stuff->options_contains(5), 2 ,'... contains returns count');
+
+splice @{$stuff->_options}, -2;
+is_deeply($stuff->_options, [1 .. 10], '... reset list for regression');
+
# test the currying
is_deeply([ $stuff->less_than_five() ], [1 .. 4]);
is($stuff->dashify, '1-2-3-4-5-6-7-8-9-10');
-$stuff->datetimes([
- DateTime->now->subtract(days => 1),
- DateTime->now->subtract(days => 1),
- DateTime->now,
- DateTime->now,
-]);
+$stuff->animals([ qw/cat duck horse cattle gorilla elephant flamingo kangaroo/ ]);
-my $my_time = DateTime->now;
-
-is($stuff->times_with_day($my_time), 2, 'check for currying with a coderef');
+# 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
'empty' => 'has_options',
'elements' => 'options',
'join' => 'join_options',
+ 'get' => 'get_option_at',
+ 'first' => 'get_first_option',
+ 'last' => 'get_last_option',
+ 'contains' => 'options_contains',
}, '... got the right provies mapping');
is($options->type_constraint->type_parameter, 'Int', '... got the right container type');