X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F003_basic_hash.t;h=7b1b7794e31911eaa11c502c01990b369b2e8955;hb=og-contains%2Bdocs;hp=c0b3a2a5536616a8c0c374a3cf4a427942c19ad3;hpb=9a9764976656e1a089735d0cb1f1affd06f4d7e4;p=gitmo%2FMooseX-AttributeHelpers.git diff --git a/t/003_basic_hash.t b/t/003_basic_hash.t index c0b3a2a..7b1b779 100644 --- a/t/003_basic_hash.t +++ b/t/003_basic_hash.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 26; +use Test::More tests => 40; use Test::Exception; BEGIN { @@ -27,6 +27,12 @@ BEGIN { 'count' => 'num_options', 'clear' => 'clear_options', 'delete' => 'delete_option', + 'exists' => 'has_option', + }, + curries => { + 'set' => { + set_quantity => ['quantity'] + }, } ); } @@ -41,12 +47,14 @@ can_ok($stuff, $_) for qw[ num_options delete_option clear_options + has_option ]; ok(!$stuff->has_options, '... we have no options'); is($stuff->num_options, 0, '... we have no options'); is_deeply($stuff->options, {}, '... no options yet'); +ok(!$stuff->has_option('foo'), '... we have no foo option'); lives_ok { $stuff->set_option(foo => 'bar'); @@ -54,6 +62,7 @@ lives_ok { ok($stuff->has_options, '... we have options'); is($stuff->num_options, 1, '... we have 1 option(s)'); +ok($stuff->has_option('foo'), '... we have a foo option'); is_deeply($stuff->options, { foo => 'bar' }, '... got options now'); lives_ok { @@ -65,10 +74,27 @@ is_deeply($stuff->options, { foo => 'bar', bar => 'baz' }, '... got more options is($stuff->get_option('foo'), 'bar', '... got the right option'); +is_deeply([ $stuff->get_option(qw(foo bar)) ], [qw(bar baz)], "get multiple options at once"); + +lives_ok { + $stuff->set_option(oink => "blah", xxy => "flop"); +} '... set the option okay'; + +is($stuff->num_options, 4, "4 options"); +is_deeply([ $stuff->get_option(qw(foo bar oink xxy)) ], [qw(bar baz blah flop)], "get multiple options at once"); + lives_ok { $stuff->delete_option('bar'); } '... deleted the option okay'; +lives_ok { + $stuff->delete_option('oink'); +} '... deleted the option okay'; + +lives_ok { + $stuff->delete_option('xxy'); +} '... deleted the option okay'; + is($stuff->num_options, 1, '... we have 1 option(s)'); is_deeply($stuff->options, { foo => 'bar' }, '... got more options now'); @@ -77,6 +103,12 @@ $stuff->clear_options; is_deeply($stuff->options, { }, "... cleared options" ); lives_ok { + $stuff->set_quantity(4); +} '... options added okay with defaults'; + +is_deeply($stuff->options, {quantity => 4}, '... returns what we expect'); + +lives_ok { Stuff->new(options => { foo => 'BAR' }); } '... good constructor params'; @@ -90,4 +122,19 @@ dies_ok { Stuff->new(options => { foo => [] }); } '... bad constructor params'; +## test the meta + +my $options = $stuff->meta->get_attribute('options'); +isa_ok($options, 'MooseX::AttributeHelpers::Collection::Hash'); + +is_deeply($options->provides, { + 'set' => 'set_option', + 'get' => 'get_option', + 'empty' => 'has_options', + 'count' => 'num_options', + 'clear' => 'clear_options', + 'delete' => 'delete_option', + 'exists' => 'has_option', +}, '... got the right provies mapping'); +is($options->type_constraint->type_parameter, 'Str', '... got the right container type');