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';
25 isa => 'ArrayRef[Int]',
26 init_arg => 'options',
27 default => sub { [] },
29 'num_options' => 'count',
30 'has_no_options' => 'is_empty',
31 'map_options', => 'map',
32 'filter_options' => 'grep',
33 'find_option' => 'first',
34 'options' => 'elements',
35 'join_options' => 'join',
36 'get_option_at' => 'get',
37 'sorted_options' => 'sort',
38 'randomized_options' => 'shuffle',
39 'unique_options' => 'uniq',
40 'less_than_five' => [ grep => ($less = sub { $_ < 5 }) ],
41 'up_by_one' => [ map => ($up = sub { $_ + 1 }) ],
42 'pairwise_options' => [ natatime => 2 ],
43 'dashify' => [ join => '-' ],
44 'descending' => [ sort => ($sort = sub { $_[1] <=> $_[0] }) ],
45 'product' => [ reduce => ($prod = sub { $_[0] * $_[1] }) ],
51 my $stuff = Stuff->new( options => [ 1 .. 10 ] );
52 isa_ok( $stuff, 'Stuff' );
54 can_ok( $stuff, $_ ) for qw[
75 is_deeply( $stuff->_options, [ 1 .. 10 ], '... got options' );
77 ok( !$stuff->has_no_options, '... we have options' );
78 is( $stuff->num_options, 10, '... got 2 options' );
79 cmp_ok( $stuff->get_option_at(0), '==', 1, '... get option 0' );
82 [ $stuff->filter_options( sub { $_ % 2 == 0 } ) ],
84 '... got the right filtered values'
88 [ $stuff->map_options( sub { $_ * 2 } ) ],
89 [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 ],
90 '... got the right mapped values'
93 is( $stuff->find_option( sub { $_ % 2 == 0 } ), 2,
94 '.. found the right option' );
96 is_deeply( [ $stuff->options ], [ 1 .. 10 ], '... got the list of options' );
98 is( $stuff->join_options(':'), '1:2:3:4:5:6:7:8:9:10',
99 '... joined the list of options by :' );
102 [ $stuff->sorted_options ], [ sort ( 1 .. 10 ) ],
103 '... got sorted options (default sort order)'
106 [ $stuff->sorted_options( sub { $_[1] <=> $_[0] } ) ],
107 [ sort { $b <=> $a } ( 1 .. 10 ) ],
108 '... got sorted options (descending sort order) '
111 throws_ok { $stuff->sorted_options('foo') }
112 qr/Argument must be a code reference/,
113 'error when sort receives a non-coderef argument';
115 is_deeply( [ sort { $a <=> $b } $stuff->randomized_options ], [ 1 .. 10 ] );
118 $stuff->pairwise_options(sub { push @pairs, [@_] });
119 is_deeply( \@pairs, [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ], [ 9, 10 ] ] );
122 is_deeply( [ $stuff->less_than_five() ], [ 1 .. 4 ] );
124 is_deeply( [ $stuff->up_by_one() ], [ 2 .. 11 ] );
126 is( $stuff->dashify, '1-2-3-4-5-6-7-8-9-10' );
128 is_deeply( [ $stuff->descending ], [ reverse 1 .. 10 ] );
130 is( $stuff->product, 3628800 );
132 my $other_stuff = Stuff->new( options => [ 1, 1, 2, 3, 5 ] );
133 is_deeply( [ $other_stuff->unique_options ], [1, 2, 3, 5] );
137 my $options = $stuff->meta->get_attribute('_options');
138 does_ok( $options, 'Mouse::Meta::Attribute::Native::Trait::Array' );
143 'num_options' => 'count',
144 'has_no_options' => 'is_empty',
145 'map_options', => 'map',
146 'filter_options' => 'grep',
147 'find_option' => 'first',
148 'options' => 'elements',
149 'join_options' => 'join',
150 'get_option_at' => 'get',
151 'sorted_options' => 'sort',
152 'randomized_options' => 'shuffle',
153 'unique_options' => 'uniq',
154 'less_than_five' => [ grep => $less ],
155 'up_by_one' => [ map => $up ],
156 'pairwise_options' => [ natatime => 2 ],
157 'dashify' => [ join => '-' ],
158 'descending' => [ sort => $sort ],
159 'product' => [ reduce => $prod ],
161 '... got the right handles mapping'
164 is( $options->type_constraint->type_parameter, 'Int',
165 '... got the right container type' );
168 $stuff->sort_in_place_options(undef);
170 '... sort rejects arg of invalid type';