2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
10 $TODO = q{Mouse is not yet completed};
12 use Test::Mouse 'does_ok';
24 isa => 'ArrayRef[Str]',
25 default => sub { [] },
27 'add_options' => 'push',
28 'remove_last_option' => 'pop',
29 'remove_first_option' => 'shift',
30 'insert_options' => 'unshift',
31 'get_option_at' => 'get',
32 'set_option_at' => 'set',
33 'num_options' => 'count',
34 'has_no_options' => 'is_empty',
35 'clear_options' => 'clear',
36 'splice_options' => 'splice',
37 'sort_options_in_place' => 'sort_in_place',
38 'option_accessor' => 'accessor',
39 'add_options_with_speed' =>
40 [ 'push' => 'funrolls', 'funbuns' ],
41 'prepend_prerequisites_along_with' =>
42 [ 'unshift' => 'first', 'second' ],
43 'descending_options' =>
44 [ 'sort_in_place' => ($sort = sub { $_[1] <=> $_[0] }) ],
49 my $stuff = Stuff->new( options => [ 10, 12 ] );
50 isa_ok( $stuff, 'Stuff' );
52 can_ok( $stuff, $_ ) for qw[
66 is_deeply( $stuff->options, [ 10, 12 ], '... got options' );
68 ok( !$stuff->has_no_options, '... we have options' );
69 is( $stuff->num_options, 2, '... got 2 options' );
71 is( $stuff->remove_last_option, 12, '... removed the last option' );
72 is( $stuff->remove_first_option, 10, '... removed the last option' );
74 is_deeply( $stuff->options, [], '... no options anymore' );
76 ok( $stuff->has_no_options, '... no options' );
77 is( $stuff->num_options, 0, '... got no options' );
80 $stuff->add_options( 1, 2, 3 );
82 '... set the option okay';
84 is_deeply( $stuff->options, [ 1, 2, 3 ], '... got options now' );
86 ok( !$stuff->has_no_options, '... has options' );
87 is( $stuff->num_options, 3, '... got 3 options' );
89 is( $stuff->get_option_at(0), 1, '... get option at index 0' );
90 is( $stuff->get_option_at(1), 2, '... get option at index 1' );
91 is( $stuff->get_option_at(2), 3, '... get option at index 2' );
94 $stuff->set_option_at( 1, 100 );
96 '... set the option okay';
98 is( $stuff->get_option_at(1), 100, '... get option at index 1' );
101 $stuff->add_options( 10, 15 );
103 '... set the option okay';
105 is_deeply( $stuff->options, [ 1, 100, 3, 10, 15 ],
106 '... got more options now' );
108 is( $stuff->num_options, 5, '... got 5 options' );
110 is( $stuff->remove_last_option, 15, '... removed the last option' );
112 is( $stuff->num_options, 4, '... got 4 options' );
113 is_deeply( $stuff->options, [ 1, 100, 3, 10 ], '... got diff options now' );
116 $stuff->insert_options( 10, 20 );
118 '... set the option okay';
120 is( $stuff->num_options, 6, '... got 6 options' );
121 is_deeply( $stuff->options, [ 10, 20, 1, 100, 3, 10 ],
122 '... got diff options now' );
124 is( $stuff->get_option_at(0), 10, '... get option at index 0' );
125 is( $stuff->get_option_at(1), 20, '... get option at index 1' );
126 is( $stuff->get_option_at(3), 100, '... get option at index 3' );
128 is( $stuff->remove_first_option, 10, '... getting the first option' );
130 is( $stuff->num_options, 5, '... got 5 options' );
131 is( $stuff->get_option_at(0), 20, '... get option at index 0' );
133 $stuff->clear_options;
134 is_deeply( $stuff->options, [], "... clear options" );
136 $stuff->add_options( 5, 1, 2, 3 );
137 $stuff->sort_options_in_place;
138 is_deeply( $stuff->options, [ 1, 2, 3, 5 ],
139 "... sort options in place (default sort order)" );
141 $stuff->sort_options_in_place( sub { $_[1] <=> $_[0] } );
142 is_deeply( $stuff->options, [ 5, 3, 2, 1 ],
143 "... sort options in place (descending order)" );
145 $stuff->clear_options();
146 $stuff->add_options( 5, 1, 2, 3 );
148 $stuff->descending_options();
150 '... curried sort in place lives ok';
152 is_deeply( $stuff->options, [ 5, 3, 2, 1 ], "... sort currying" );
154 throws_ok { $stuff->sort_options_in_place('foo') }
155 qr/Argument must be a code reference/,
156 'error when sort_in_place receives a non-coderef argument';
158 $stuff->clear_options;
161 $stuff->add_options('tree');
163 '... set the options okay';
166 $stuff->add_options_with_speed( 'compatible', 'safe' );
168 '... add options with speed okay';
171 $stuff->options, [qw/tree funrolls funbuns compatible safe/],
172 'check options after add_options_with_speed'
176 $stuff->prepend_prerequisites_along_with();
178 '... add prerequisite options okay';
180 $stuff->clear_options;
181 $stuff->add_options( 1, 2 );
184 $stuff->splice_options( 1, 0, 'foo' );
186 '... splice_options works';
189 $stuff->options, [ 1, 'foo', 2 ],
190 'splice added expected option'
193 is( $stuff->option_accessor( 1 => 'foo++' ), 'foo++' );
194 is( $stuff->option_accessor(1), 'foo++' );
199 # $stuff->insert_options(undef);
200 #} '... could not add an undef where a string is expected';
203 # $stuff->set_option(5, {});
204 #} '... could not add a hash ref where a string is expected';
207 Stuff->new( options => [ undef, 10, undef, 20 ] );
209 '... bad constructor params';
212 my $stuff = Stuff->new();
213 $stuff->add_options(undef);
215 '... rejects push of an invalid type';
218 my $stuff = Stuff->new();
219 $stuff->insert_options(undef);
221 '... rejects unshift of an invalid type';
224 my $stuff = Stuff->new();
225 $stuff->set_option_at( 0, undef );
227 '... rejects set of an invalid type';
230 my $stuff = Stuff->new();
231 $stuff->sort_in_place_options(undef);
233 '... sort rejects arg of invalid type';
236 my $stuff = Stuff->new();
237 $stuff->option_accessor();
239 '... accessor rejects 0 args';
242 my $stuff = Stuff->new();
243 $stuff->option_accessor( 1, 2, 3 );
245 '... accessor rejects 3 args';
249 my $options = $stuff->meta->get_attribute('options');
250 does_ok( $options, 'Mouse::Meta::Attribute::Native::Trait::Array' );
255 'add_options' => 'push',
256 'remove_last_option' => 'pop',
257 'remove_first_option' => 'shift',
258 'insert_options' => 'unshift',
259 'get_option_at' => 'get',
260 'set_option_at' => 'set',
261 'num_options' => 'count',
262 'has_no_options' => 'is_empty',
263 'clear_options' => 'clear',
264 'splice_options' => 'splice',
265 'sort_options_in_place' => 'sort_in_place',
266 'option_accessor' => 'accessor',
267 'add_options_with_speed' => [ 'push' => 'funrolls', 'funbuns' ],
268 'prepend_prerequisites_along_with' =>
269 [ 'unshift' => 'first', 'second' ],
270 'descending_options' => [ 'sort_in_place' => $sort ],
272 '... got the right handles mapping'
275 is( $options->type_constraint->type_parameter, 'Str',
276 '... got the right container type' );