use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 54;
use Test::Exception;
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',
+ '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',
}
);
}
-my $stuff = Stuff->new();
+my $stuff = Stuff->new(options => [ 10, 12 ]);
isa_ok($stuff, 'Stuff');
can_ok($stuff, $_) for qw[
get_option_at
set_option_at
num_options
+ clear_options
has_options
+ no_options
];
-is_deeply($stuff->options, [], '... no options yet');
+is_deeply($stuff->options, [10, 12], '... got options');
-ok(!$stuff->has_options, '... no 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->no_options, '... no options');
is($stuff->num_options, 0, '... got no options');
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');
is($stuff->num_options, 5, '... got 5 options');
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 {
$stuff->set_option(5, {});
} '... could not add a hash ref where an int is expected';
+dies_ok {
+ Stuff->new(options => [ 'Foo', 10, 'Bar', 20 ]);
+} '... bad constructor params';
+
## test the meta
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',
-}, '... got the right provies mapping');
-
-is($options->container_type, 'Int', '... got the right container type');
+ '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');