All unit tests passing with refactored stuff, documentation updated significantly.
[gitmo/MooseX-AttributeHelpers.git] / t / 002_basic_array.t
index 27520ee..450b2bf 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 51;
+use Test::More tests => 54;
 use Test::Exception;
 
 BEGIN {
@@ -20,15 +20,16 @@ BEGIN {
         isa       => 'ArrayRef[Int]',
         default   => sub { [] },
         provides  => {
-            'push'    => 'add_options',
-            'pop'     => 'remove_last_option',    
-            'shift'   => 'remove_first_option',
-            'unshift' => 'insert_options',
-            'get'     => 'get_option_at',
-            'set'     => 'set_option_at',
-            'count'   => 'num_options',
-            'empty'   => 'has_options',        
-            'clear'   => 'clear_options',        
+            'push'      => 'add_options',
+            'pop'       => 'remove_last_option',    
+            'shift'     => 'remove_first_option',
+            'unshift'   => 'insert_options',
+            'get'       => 'get_option_at',
+            'set'       => 'set_option_at',
+            'count'     => 'num_options',
+            'is_empty'  => 'no_options',        
+            'has_items' => 'has_options',
+            'clear'     => 'clear_options',        
         }
     );
 }
@@ -46,6 +47,7 @@ can_ok($stuff, $_) for qw[
     num_options
     clear_options
     has_options
+    no_options
 ];
 
 is_deeply($stuff->options, [10, 12], '... got options');
@@ -58,7 +60,7 @@ is($stuff->remove_first_option, 10, '... removed the last option');
 
 is_deeply($stuff->options, [], '... no options anymore');
 
-ok(!$stuff->has_options, '... no options');
+ok($stuff->no_options, '... no options');
 is($stuff->num_options, 0, '... got no options');
 
 lives_ok {
@@ -67,7 +69,7 @@ lives_ok {
 
 is_deeply($stuff->options, [1, 2, 3], '... got options now');
 
-ok($stuff->has_options, '... no options');
+ok($stuff->has_options, '... have options');
 is($stuff->num_options, 3, '... got 3 options');
 
 is($stuff->get_option_at(0), 1, '... get option at index 0');
@@ -112,6 +114,16 @@ is($stuff->get_option_at(0), 20, '... get option at index 0');
 $stuff->clear_options;
 is_deeply( $stuff->options, [], "... clear options" );
 
+lives_ok {
+    $stuff->set_option_at([0..2], 10, 20, 30);
+} '... set multiple options';
+
+is_deeply(
+    [$stuff->get_option_at(0..2)], 
+    [10,20,30], 
+    '... and got what we set'
+);
+
 ## check some errors
 
 dies_ok {
@@ -136,15 +148,16 @@ my $options = $stuff->meta->get_attribute('options');
 isa_ok($options, 'MooseX::AttributeHelpers::Collection::Array');
 
 is_deeply($options->provides, {
-    'push'    => 'add_options',
-    'pop'     => 'remove_last_option',    
-    'shift'   => 'remove_first_option',
-    'unshift' => 'insert_options',
-    'get'     => 'get_option_at',
-    'set'     => 'set_option_at',
-    'count'   => 'num_options',
-    'empty'   => 'has_options',    
-    'clear'   => 'clear_options',    
-}, '... got the right provies mapping');
+    'push'      => 'add_options',
+    'pop'       => 'remove_last_option',    
+    'shift'     => 'remove_first_option',
+    'unshift'   => 'insert_options',
+    'get'       => 'get_option_at',
+    'set'       => 'set_option_at',
+    'count'     => 'num_options',
+    'is_empty'  => 'no_options',    
+    'has_items' => 'has_options', 
+    'clear'     => 'clear_options',    
+}, '... got the right provides mapping');
 
 is($options->type_constraint->type_parameter, 'Int', '... got the right container type');