6 use Test::More no_plan => 1;
9 use_ok('MooseX::AttributeHelpers');
17 metaclass => 'Collection::Array',
19 isa => 'ArrayRef[Int]',
20 default => sub { [] },
22 'push' => 'add_options',
23 'pop' => 'remove_last_option',
24 'shift' => 'remove_first_option',
25 'unshift' => 'insert_options',
26 'get' => 'get_option_at',
27 'set' => 'set_option_at',
28 'count' => 'num_options',
29 'empty' => 'has_options',
34 my $stuff = Stuff->new();
35 isa_ok($stuff, 'Stuff');
37 can_ok($stuff, $_) for qw[
48 is_deeply($stuff->options, [], '... no options yet');
50 ok(!$stuff->has_options, '... no options');
51 is($stuff->num_options, 0, '... got no options');
53 $stuff->add_options(1, 2, 3);
54 is_deeply($stuff->options, [1, 2, 3], '... got options now');
56 ok($stuff->has_options, '... no options');
57 is($stuff->num_options, 3, '... got 3 options');
59 is($stuff->get_option_at(0), 1, '... get option at index 0');
60 is($stuff->get_option_at(1), 2, '... get option at index 1');
61 is($stuff->get_option_at(2), 3, '... get option at index 2');
63 $stuff->set_option_at(1, 100);
65 is($stuff->get_option_at(1), 100, '... get option at index 1');
67 $stuff->add_options(10, 15);
68 is_deeply($stuff->options, [1, 100, 3, 10, 15], '... got more options now');
70 is($stuff->num_options, 5, '... got 5 options');
72 is($stuff->remove_last_option, 15, '... removed the last option');
74 is($stuff->num_options, 4, '... got 4 options');
75 is_deeply($stuff->options, [1, 100, 3, 10], '... got diff options now');
77 $stuff->insert_options(10, 20);
79 is($stuff->num_options, 6, '... got 6 options');
80 is_deeply($stuff->options, [10, 20, 1, 100, 3, 10], '... got diff options now');
82 is($stuff->get_option_at(0), 10, '... get option at index 0');
83 is($stuff->get_option_at(1), 20, '... get option at index 1');
84 is($stuff->get_option_at(3), 100, '... get option at index 3');
86 is($stuff->remove_first_option, 10, '... getting the first option');
88 is($stuff->num_options, 5, '... got 5 options');
89 is($stuff->get_option_at(0), 20, '... get option at index 0');
93 my $options = $stuff->meta->get_attribute('options');
94 isa_ok($options, 'MooseX::AttributeHelpers::Collection::Array');
96 is_deeply($options->provides, {
97 'push' => 'add_options',
98 'pop' => 'remove_last_option',
99 'shift' => 'remove_first_option',
100 'unshift' => 'insert_options',
101 'get' => 'get_option_at',
102 'set' => 'set_option_at',
103 'count' => 'num_options',
104 'empty' => 'has_options',
105 }, '... got the right provies mapping');