add method provider currying support
[gitmo/MooseX-AttributeHelpers.git] / t / 002_basic_array.t
index 479269e..8e81b10 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More no_plan => 1;
+use Test::More tests => 52;
 use Test::Exception;
 
 BEGIN {
@@ -17,7 +17,7 @@ BEGIN {
     has 'options' => (
         metaclass => 'Collection::Array',
         is        => 'ro',
-        isa       => 'ArrayRef[Int]',
+        isa       => 'ArrayRef[Str]',
         default   => sub { [] },
         provides  => {
             'push'    => 'add_options',
@@ -28,11 +28,16 @@ BEGIN {
             'set'     => 'set_option_at',
             'count'   => 'num_options',
             'empty'   => 'has_options',        
+            'clear'   => 'clear_options',        
+        },
+        curries   => {
+            'push'       => ['add_options_with_speed', 'funrolls', 'funbuns'],
+            'unshift'    => ['prepend_prerequisites_along_with', 'first', 'second']
         }
     );
 }
 
-my $stuff = Stuff->new();
+my $stuff = Stuff->new(options => [ 10, 12 ]);
 isa_ok($stuff, 'Stuff');
 
 can_ok($stuff, $_) for qw[
@@ -43,10 +48,19 @@ can_ok($stuff, $_) for qw[
     get_option_at
     set_option_at
     num_options
+    clear_options
     has_options
 ];
 
-is_deeply($stuff->options, [], '... no options yet');
+is_deeply($stuff->options, [10, 12], '... got options');
+
+ok($stuff->has_options, '... we have options');
+is($stuff->num_options, 2, '... got 2 options');
+
+is($stuff->remove_last_option, 12, '... removed the last option');
+is($stuff->remove_first_option, 10, '... removed the last option');
+
+is_deeply($stuff->options, [], '... no options anymore');
 
 ok(!$stuff->has_options, '... no options');
 is($stuff->num_options, 0, '... got no options');
@@ -99,19 +113,36 @@ is($stuff->remove_first_option, 10, '... getting the first option');
 is($stuff->num_options, 5, '... got 5 options');
 is($stuff->get_option_at(0), 20, '... get option at index 0');
 
-## check some errors
+$stuff->clear_options;
+is_deeply( $stuff->options, [], "... clear options" );
 
-dies_ok {
-    $stuff->add_options([]);
-} '... could not add an array ref where an int is expected';
+lives_ok {
+    $stuff->add_options('tree');
+} '... set the options okay';
 
-dies_ok {
-    $stuff->insert_options(undef);
-} '... could not add an undef where an int is expected';
+lives_ok { 
+    $stuff->add_options_with_speed('compatible', 'safe');
+} '... add options with speed okay';
+
+is_deeply($stuff->options, [qw/tree funrolls funbuns compatible safe/]);
+
+lives_ok {
+    $stuff->prepend_prerequisites_along_with();
+} '... add prerequisite options okay';
+
+## check some errors
+
+#dies_ok {
+#    $stuff->insert_options(undef);
+#} '... could not add an undef where a string is expected';
+#
+#dies_ok {
+#    $stuff->set_option(5, {});
+#} '... could not add a hash ref where a string is expected';
 
 dies_ok {
-    $stuff->set_option(5, {});
-} '... could not add a hash ref where an int is expected';
+    Stuff->new(options => [ undef, 10, undef, 20 ]);
+} '... bad constructor params';
 
 ## test the meta
 
@@ -127,6 +158,7 @@ is_deeply($options->provides, {
     'set'     => 'set_option_at',
     'count'   => 'num_options',
     'empty'   => 'has_options',    
+    'clear'   => 'clear_options',    
 }, '... got the right provies mapping');
 
-is($options->container_type, 'Int', '... got the right container type');
+is($options->type_constraint->type_parameter, 'Str', '... got the right container type');