use strict;
use warnings;
-use Test::More tests => 45;
+use Test::More tests => 50;
use Test::Exception;
BEGIN {
'exists' => 'has_option',
'defined' => 'is_defined',
'accessor' => 'option_accessor',
+ 'kv' => 'key_value',
+ 'elements' => 'options_elements',
},
curries => {
'accessor' => {
Stuff->new(options => { foo => [] });
} '... bad constructor params';
+dies_ok {
+ my $stuff = Stuff->new;
+ $stuff->option_accessor();
+} '... accessor dies on 0 args';
+
+dies_ok {
+ my $stuff = Stuff->new;
+ $stuff->option_accessor(1 => 2, 3);
+} '... accessor dies on 3 args';
+
+dies_ok {
+ my $stuff = Stuff->new;
+ $stuff->option_accessor(1 => 2, 3 => 4);
+} '... accessor dies on 4 args';
+
## test the meta
my $options = $stuff->meta->get_attribute('options');
'defined' => 'is_defined',
'exists' => 'has_option',
'accessor' => 'option_accessor',
+ 'kv' => 'key_value',
+ 'elements' => 'options_elements',
}, '... got the right provides mapping');
is($options->type_constraint->type_parameter, 'Str', '... got the right container type');
+
+$stuff->set_option( oink => "blah", xxy => "flop" );
+my @key_value = sort { $a->[0] cmp $b->[0] } $stuff->key_value;
+is_deeply(
+ \@key_value,
+ [ [ 'oink', 'blah' ], [ 'quantity', 4 ], [ 'xxy', 'flop' ] ],
+ '... got the right key value pairs'
+);
+
+my %options_elements = $stuff->options_elements;
+is_deeply(
+ \%options_elements,
+ {
+ 'oink' => 'blah',
+ 'quantity' => 4,
+ 'xxy' => 'flop'
+ },
+ '... got the right hash elements'
+);