more tests and tweaks
[gitmo/MooseX-AttributeHelpers.git] / t / 003_basic_hash.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More no_plan => 1;
7
8 BEGIN {
9     use_ok('MooseX::AttributeHelpers');   
10 }
11
12 {
13     package Stuff;
14     use Moose;
15
16     has 'options' => (
17         metaclass => 'Collection::Hash',
18         is        => 'ro',
19         isa       => 'HashRef[Str]',
20         default   => sub { {} },
21         provides  => {
22             'set'   => 'set_option',
23             'get'   => 'get_option',            
24             'empty' => 'has_options',
25             'count' => 'num_options',
26         }
27     );
28 }
29
30 my $stuff = Stuff->new();
31 isa_ok($stuff, 'Stuff');
32
33 can_ok($stuff, $_) for qw[
34     set_option
35     get_option
36     has_options
37     num_options
38 ];
39
40 ok(!$stuff->has_options, '... we have no options');
41 is($stuff->num_options, 0, '... we have no options');
42
43 is_deeply($stuff->options, {}, '... no options yet');
44
45 $stuff->set_option(foo => 'bar');
46
47 ok($stuff->has_options, '... we have options');
48 is($stuff->num_options, 1, '... we have 1 option(s)');
49 is_deeply($stuff->options, { foo => 'bar' }, '... got options now');
50
51 $stuff->set_option(bar => 'baz');
52
53 is($stuff->num_options, 2, '... we have 2 option(s)');
54 is_deeply($stuff->options, { foo => 'bar', bar => 'baz' }, '... got more options now');
55
56 is($stuff->get_option('foo'), 'bar', '... got the right option');
57
58
59