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',
35 add_options_with_speed => ['funrolls', 'funbuns']
38 prepend_prerequisites_along_with => ['first', 'second']
44 my $stuff = Stuff->new(options => [ 10, 12 ]);
45 isa_ok($stuff, 'Stuff');
47 can_ok($stuff, $_) for qw[
59 is_deeply($stuff->options, [10, 12], '... got options');
61 ok($stuff->has_options, '... we have options');
62 is($stuff->num_options, 2, '... got 2 options');
64 is($stuff->remove_last_option, 12, '... removed the last option');
65 is($stuff->remove_first_option, 10, '... removed the last option');
67 is_deeply($stuff->options, [], '... no options anymore');
69 ok(!$stuff->has_options, '... no options');
70 is($stuff->num_options, 0, '... got no options');
73 $stuff->add_options(1, 2, 3);
74 } '... set the option okay';
76 is_deeply($stuff->options, [1, 2, 3], '... got options now');
78 ok($stuff->has_options, '... no options');
79 is($stuff->num_options, 3, '... got 3 options');
81 is($stuff->get_option_at(0), 1, '... get option at index 0');
82 is($stuff->get_option_at(1), 2, '... get option at index 1');
83 is($stuff->get_option_at(2), 3, '... get option at index 2');
86 $stuff->set_option_at(1, 100);
87 } '... set the option okay';
89 is($stuff->get_option_at(1), 100, '... get option at index 1');
92 $stuff->add_options(10, 15);
93 } '... set the option okay';
95 is_deeply($stuff->options, [1, 100, 3, 10, 15], '... got more options now');
97 is($stuff->num_options, 5, '... got 5 options');
99 is($stuff->remove_last_option, 15, '... removed the last option');
101 is($stuff->num_options, 4, '... got 4 options');
102 is_deeply($stuff->options, [1, 100, 3, 10], '... got diff options now');
105 $stuff->insert_options(10, 20);
106 } '... set the option okay';
108 is($stuff->num_options, 6, '... got 6 options');
109 is_deeply($stuff->options, [10, 20, 1, 100, 3, 10], '... got diff options now');
111 is($stuff->get_option_at(0), 10, '... get option at index 0');
112 is($stuff->get_option_at(1), 20, '... get option at index 1');
113 is($stuff->get_option_at(3), 100, '... get option at index 3');
115 is($stuff->remove_first_option, 10, '... getting the first option');
117 is($stuff->num_options, 5, '... got 5 options');
118 is($stuff->get_option_at(0), 20, '... get option at index 0');
120 $stuff->clear_options;
121 is_deeply( $stuff->options, [], "... clear options" );
124 $stuff->add_options('tree');
125 } '... set the options okay';
128 $stuff->add_options_with_speed('compatible', 'safe');
129 } '... add options with speed okay';
131 is_deeply($stuff->options, [qw/tree funrolls funbuns compatible safe/]);
134 $stuff->prepend_prerequisites_along_with();
135 } '... add prerequisite options okay';
140 # $stuff->insert_options(undef);
141 #} '... could not add an undef where a string is expected';
144 # $stuff->set_option(5, {});
145 #} '... could not add a hash ref where a string is expected';
148 Stuff->new(options => [ undef, 10, undef, 20 ]);
149 } '... bad constructor params';
153 my $options = $stuff->meta->get_attribute('options');
154 isa_ok($options, 'MooseX::AttributeHelpers::Collection::Array');
156 is_deeply($options->provides, {
157 'push' => 'add_options',
158 'pop' => 'remove_last_option',
159 'shift' => 'remove_first_option',
160 'unshift' => 'insert_options',
161 'get' => 'get_option_at',
162 'set' => 'set_option_at',
163 'count' => 'num_options',
164 'empty' => 'has_options',
165 'clear' => 'clear_options',
166 }, '... got the right provies mapping');
168 is($options->type_constraint->type_parameter, 'Str', '... got the right container type');