add contains method to MethodProvider/List
[gitmo/MooseX-AttributeHelpers.git] / t / 005_basic_list.t
index d4a49b7..f8a16c9 100644 (file)
@@ -7,7 +7,7 @@ use Test::More;
 use Test::Exception;
 
 BEGIN {
-    plan tests => 29;
+    plan tests => 36;
 }
 
 BEGIN {
@@ -35,6 +35,7 @@ BEGIN {
             'get'      => 'get_option_at',
             'first'    => 'get_first_option',
             'last'     => 'get_last_option',
+            'contains' => 'options_contains',
         },
         curries   => {
             'grep'     => {less_than_five => [ sub { $_ < 5 } ]},
@@ -72,6 +73,7 @@ can_ok($stuff, $_) for qw[
     options
     join_options
     get_option_at
+    options_contains
 ];
 
 is_deeply($stuff->_options, [1 .. 10], '... got options');
@@ -100,6 +102,16 @@ is_deeply([ $stuff->options ], [1 .. 10], '... got the list of options');
 
 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]);
 
@@ -131,7 +143,8 @@ is_deeply($options->provides, {
     'join'     => 'join_options',
     'get'      => 'get_option_at',
     'first'    => 'get_first_option',
-    'last'     => 'get_last_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');