6 use Test::More no_plan => 1;
10 use_ok('MooseX::AttributeHelpers');
18 metaclass => 'Collection::Array',
20 isa => 'ArrayRef[Int]',
21 default => sub { [] },
23 'push' => 'add_options',
24 'pop' => 'remove_last_option',
25 'shift' => 'remove_first_option',
26 'unshift' => 'insert_options',
27 'get' => 'get_option_at',
28 'set' => 'set_option_at',
29 'count' => 'num_options',
30 'empty' => 'has_options',
35 my $stuff = Stuff->new();
36 isa_ok($stuff, 'Stuff');
38 can_ok($stuff, $_) for qw[
49 is_deeply($stuff->options, [], '... no options yet');
51 ok(!$stuff->has_options, '... no options');
52 is($stuff->num_options, 0, '... got no options');
55 $stuff->add_options(1, 2, 3);
56 } '... set the option okay';
58 is_deeply($stuff->options, [1, 2, 3], '... got options now');
60 ok($stuff->has_options, '... no options');
61 is($stuff->num_options, 3, '... got 3 options');
63 is($stuff->get_option_at(0), 1, '... get option at index 0');
64 is($stuff->get_option_at(1), 2, '... get option at index 1');
65 is($stuff->get_option_at(2), 3, '... get option at index 2');
68 $stuff->set_option_at(1, 100);
69 } '... set the option okay';
71 is($stuff->get_option_at(1), 100, '... get option at index 1');
74 $stuff->add_options(10, 15);
75 } '... set the option okay';
77 is_deeply($stuff->options, [1, 100, 3, 10, 15], '... got more options now');
79 is($stuff->num_options, 5, '... got 5 options');
81 is($stuff->remove_last_option, 15, '... removed the last option');
83 is($stuff->num_options, 4, '... got 4 options');
84 is_deeply($stuff->options, [1, 100, 3, 10], '... got diff options now');
87 $stuff->insert_options(10, 20);
88 } '... set the option okay';
90 is($stuff->num_options, 6, '... got 6 options');
91 is_deeply($stuff->options, [10, 20, 1, 100, 3, 10], '... got diff options now');
93 is($stuff->get_option_at(0), 10, '... get option at index 0');
94 is($stuff->get_option_at(1), 20, '... get option at index 1');
95 is($stuff->get_option_at(3), 100, '... get option at index 3');
97 is($stuff->remove_first_option, 10, '... getting the first option');
99 is($stuff->num_options, 5, '... got 5 options');
100 is($stuff->get_option_at(0), 20, '... get option at index 0');
105 $stuff->add_options([]);
106 } '... could not add an array ref where an int is expected';
109 $stuff->insert_options(undef);
110 } '... could not add an undef where an int is expected';
113 $stuff->set_option(5, {});
114 } '... could not add a hash ref where an int is expected';
118 my $options = $stuff->meta->get_attribute('options');
119 isa_ok($options, 'MooseX::AttributeHelpers::Collection::Array');
121 is_deeply($options->provides, {
122 'push' => 'add_options',
123 'pop' => 'remove_last_option',
124 'shift' => 'remove_first_option',
125 'unshift' => 'insert_options',
126 'get' => 'get_option_at',
127 'set' => 'set_option_at',
128 'count' => 'num_options',
129 'empty' => 'has_options',
130 }, '... got the right provies mapping');
132 is($options->container_type, 'Int', '... got the right container type');