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