6 use Test::More tests => 52;
10 use_ok('MooseX::AttributeHelpers');
18 metaclass => 'Collection::Array',
20 isa => 'ArrayRef[Str]',
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',
31 'clear' => 'clear_options',
34 'push' => ['add_options_with_speed', 'funrolls', 'funbuns'],
35 'unshift' => ['prepend_prerequisites_along_with', 'first', 'second']
40 my $stuff = Stuff->new(options => [ 10, 12 ]);
41 isa_ok($stuff, 'Stuff');
43 can_ok($stuff, $_) for qw[
55 is_deeply($stuff->options, [10, 12], '... got options');
57 ok($stuff->has_options, '... we have options');
58 is($stuff->num_options, 2, '... got 2 options');
60 is($stuff->remove_last_option, 12, '... removed the last option');
61 is($stuff->remove_first_option, 10, '... removed the last option');
63 is_deeply($stuff->options, [], '... no options anymore');
65 ok(!$stuff->has_options, '... no options');
66 is($stuff->num_options, 0, '... got no options');
69 $stuff->add_options(1, 2, 3);
70 } '... set the option okay';
72 is_deeply($stuff->options, [1, 2, 3], '... got options now');
74 ok($stuff->has_options, '... no options');
75 is($stuff->num_options, 3, '... got 3 options');
77 is($stuff->get_option_at(0), 1, '... get option at index 0');
78 is($stuff->get_option_at(1), 2, '... get option at index 1');
79 is($stuff->get_option_at(2), 3, '... get option at index 2');
82 $stuff->set_option_at(1, 100);
83 } '... set the option okay';
85 is($stuff->get_option_at(1), 100, '... get option at index 1');
88 $stuff->add_options(10, 15);
89 } '... set the option okay';
91 is_deeply($stuff->options, [1, 100, 3, 10, 15], '... got more options now');
93 is($stuff->num_options, 5, '... got 5 options');
95 is($stuff->remove_last_option, 15, '... removed the last option');
97 is($stuff->num_options, 4, '... got 4 options');
98 is_deeply($stuff->options, [1, 100, 3, 10], '... got diff options now');
101 $stuff->insert_options(10, 20);
102 } '... set the option okay';
104 is($stuff->num_options, 6, '... got 6 options');
105 is_deeply($stuff->options, [10, 20, 1, 100, 3, 10], '... got diff options now');
107 is($stuff->get_option_at(0), 10, '... get option at index 0');
108 is($stuff->get_option_at(1), 20, '... get option at index 1');
109 is($stuff->get_option_at(3), 100, '... get option at index 3');
111 is($stuff->remove_first_option, 10, '... getting the first option');
113 is($stuff->num_options, 5, '... got 5 options');
114 is($stuff->get_option_at(0), 20, '... get option at index 0');
116 $stuff->clear_options;
117 is_deeply( $stuff->options, [], "... clear options" );
120 $stuff->add_options('tree');
121 } '... set the options okay';
124 $stuff->add_options_with_speed('compatible', 'safe');
125 } '... add options with speed okay';
127 is_deeply($stuff->options, [qw/tree funrolls funbuns compatible safe/]);
130 $stuff->prepend_prerequisites_along_with();
131 } '... add prerequisite options okay';
136 # $stuff->insert_options(undef);
137 #} '... could not add an undef where a string is expected';
140 # $stuff->set_option(5, {});
141 #} '... could not add a hash ref where a string is expected';
144 Stuff->new(options => [ undef, 10, undef, 20 ]);
145 } '... bad constructor params';
149 my $options = $stuff->meta->get_attribute('options');
150 isa_ok($options, 'MooseX::AttributeHelpers::Collection::Array');
152 is_deeply($options->provides, {
153 'push' => 'add_options',
154 'pop' => 'remove_last_option',
155 'shift' => 'remove_first_option',
156 'unshift' => 'insert_options',
157 'get' => 'get_option_at',
158 'set' => 'set_option_at',
159 'count' => 'num_options',
160 'empty' => 'has_options',
161 'clear' => 'clear_options',
162 }, '... got the right provies mapping');
164 is($options->type_constraint->type_parameter, 'Str', '... got the right container type');