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';
21 isa => 'HashRef[Str]',
22 default => sub { {} },
24 'set_option' => 'set',
25 'get_option' => 'get',
26 'has_no_options' => 'is_empty',
27 'num_options' => 'count',
28 'clear_options' => 'clear',
29 'delete_option' => 'delete',
30 'has_option' => 'exists',
31 'is_defined' => 'defined',
32 'option_accessor' => 'accessor',
34 'options_elements' => 'elements',
35 'quantity' => [ accessor => 'quantity' ],
40 my $stuff = Stuff->new();
41 isa_ok( $stuff, 'Stuff' );
43 can_ok( $stuff, $_ ) for qw[
56 ok( $stuff->has_no_options, '... we have no options' );
57 is( $stuff->num_options, 0, '... we have no options' );
59 is_deeply( $stuff->options, {}, '... no options yet' );
60 ok( !$stuff->has_option('foo'), '... we have no foo option' );
64 $set_result = $stuff->set_option( foo => 'bar' );
66 '... set the option okay';
67 is($set_result, 'bar', '... returns value set');
69 ok( $stuff->is_defined('foo'), '... foo is defined' );
71 ok( !$stuff->has_no_options, '... we have options' );
72 is( $stuff->num_options, 1, '... we have 1 option(s)' );
73 ok( $stuff->has_option('foo'), '... we have a foo option' );
74 is_deeply( $stuff->options, { foo => 'bar' }, '... got options now' );
77 $set_result = $stuff->set_option( bar => 'baz' );
79 '... set the option okay';
80 is($set_result, 'baz', '... returns value set');
82 is( $stuff->num_options, 2, '... we have 2 option(s)' );
83 is_deeply( $stuff->options, { foo => 'bar', bar => 'baz' },
84 '... got more options now' );
86 is( $stuff->get_option('foo'), 'bar', '... got the right option' );
88 is_deeply( [ $stuff->get_option(qw(foo bar)) ], [qw(bar baz)],
89 "get multiple options at once" );
91 is( scalar($stuff->get_option(qw( foo bar) )), "baz",
92 '... got last option in scalar context');
96 @set_return = $stuff->set_option( oink => "blah", xxy => "flop" );
98 '... set the option okay';
99 is_deeply(\@set_return, [ qw(blah flop) ], '... and returns values set');
101 is( $stuff->num_options, 4, "4 options" );
102 is_deeply( [ $stuff->get_option(qw(foo bar oink xxy)) ],
103 [qw(bar baz blah flop)], "get multiple options at once" );
106 $stuff->delete_option('bar');
108 '... deleted the option okay';
111 $stuff->delete_option('oink','xxy');
113 '... deleted multiple option okay';
115 is( $stuff->num_options, 1, '... we have 1 option(s)' );
116 is_deeply( $stuff->options, { foo => 'bar' }, '... got more options now' );
118 $stuff->clear_options;
120 is_deeply( $stuff->options, {}, "... cleared options" );
125 '... options added okay with defaults';
127 is( $stuff->quantity, 4, 'reader part of curried accessor works' );
129 is_deeply( $stuff->options, { quantity => 4 }, '... returns what we expect' );
132 Stuff->new( options => { foo => 'BAR' } );
134 '... good constructor params';
139 $stuff->set_option( bar => {} );
141 '... could not add a hash ref where an string is expected';
144 Stuff->new( options => { foo => [] } );
146 '... bad constructor params';
150 my $options = $stuff->meta->get_attribute('options');
151 does_ok( $options, 'Mouse::Meta::Attribute::Native::Trait::Hash' );
156 'set_option' => 'set',
157 'get_option' => 'get',
158 'has_no_options' => 'is_empty',
159 'num_options' => 'count',
160 'clear_options' => 'clear',
161 'delete_option' => 'delete',
162 'has_option' => 'exists',
163 'is_defined' => 'defined',
164 'option_accessor' => 'accessor',
166 'options_elements' => 'elements',
167 'quantity' => [ accessor => 'quantity' ],
169 '... got the right handles mapping'
172 is( $options->type_constraint->type_parameter, 'Str',
173 '... got the right container type' );
175 $stuff->set_option( oink => "blah", xxy => "flop" );
176 my @key_value = sort{ $a->[0] cmp $b->[0] } $stuff->key_value;
179 [ sort{ $a->[0] cmp $b->[0] } [ 'xxy', 'flop' ], [ 'quantity', 4 ], [ 'oink', 'blah' ] ],
180 '... got the right key value pairs'
181 ) or do{ require Data::Dumper; diag(Data::Dumper::Dumper(\@key_value)) };
183 my %options_elements = $stuff->options_elements;
191 '... got the right hash elements'