6 use Test::More tests => 33;
10 use_ok('MooseX::AttributeHelpers');
16 use MooseX::AttributeHelpers;
19 metaclass => 'Collection::Hash',
21 isa => 'HashRef[Str]',
22 default => sub { {} },
24 'set' => 'set_option',
25 'get' => 'get_option',
26 'has_items' => 'has_options',
27 'is_empty' => 'no_options',
28 'count' => 'num_options',
29 'clear' => 'clear_options',
30 'delete' => 'delete_option',
35 my $stuff = Stuff->new();
36 isa_ok($stuff, 'Stuff');
38 can_ok($stuff, $_) for qw[
48 ok($stuff->no_options, '... we have no options');
49 is($stuff->num_options, 0, '... we have no options');
51 is_deeply($stuff->options, {}, '... no options yet');
54 $stuff->set_option(foo => 'bar');
55 } '... set the option okay';
57 ok($stuff->has_options, '... we have options');
58 is($stuff->num_options, 1, '... we have 1 option(s)');
59 is_deeply($stuff->options, { foo => 'bar' }, '... got options now');
62 $stuff->set_option(bar => 'baz');
63 } '... set the option okay';
65 is($stuff->num_options, 2, '... we have 2 option(s)');
66 is_deeply($stuff->options, { foo => 'bar', bar => 'baz' }, '... got more options now');
68 is($stuff->get_option('foo'), 'bar', '... got the right option');
70 is_deeply([ $stuff->get_option(qw(foo bar)) ], [qw(bar baz)], "get multiple options at once");
73 $stuff->set_option(oink => "blah", xxy => "flop");
74 } '... set the option okay';
76 is($stuff->num_options, 4, "4 options");
77 is_deeply([ $stuff->get_option(qw(foo bar oink xxy)) ], [qw(bar baz blah flop)], "get multiple options at once");
80 $stuff->delete_option('bar');
81 } '... deleted the option okay';
84 $stuff->delete_option('oink');
85 } '... deleted the option okay';
88 $stuff->delete_option('xxy');
89 } '... deleted the option okay';
91 is($stuff->num_options, 1, '... we have 1 option(s)');
92 is_deeply($stuff->options, { foo => 'bar' }, '... got more options now');
94 $stuff->clear_options;
96 is_deeply($stuff->options, { }, "... cleared options" );
99 Stuff->new(options => { foo => 'BAR' });
100 } '... good constructor params';
105 $stuff->set_option(bar => {});
106 } '... could not add a hash ref where an string is expected';
109 Stuff->new(options => { foo => [] });
110 } '... bad constructor params';