diff options
author | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-10 15:10:26 +0000 |
---|---|---|
committer | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-10 15:10:26 +0000 |
commit | dc07be4ac45756a0e664ee29e888f86b7609784a (patch) | |
tree | dca7e4467f73625604886e8910a609ccc978b0ce /t/moose-tagged.t | |
parent | 'clear' almost completely implemneted (diff) | |
download | data-multivalued-dc07be4ac45756a0e664ee29e888f86b7609784a.tar.gz data-multivalued-dc07be4ac45756a0e664ee29e888f86b7609784a.tar.bz2 data-multivalued-dc07be4ac45756a0e664ee29e888f86b7609784a.zip |
move up a level
Diffstat (limited to 't/moose-tagged.t')
-rw-r--r-- | t/moose-tagged.t | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/t/moose-tagged.t b/t/moose-tagged.t new file mode 100644 index 0000000..6e1ac7a --- /dev/null +++ b/t/moose-tagged.t @@ -0,0 +1,67 @@ +#!perl +use strict; +use warnings; + +package Foo;{ +use Moose; +use Data::MultiValued::AttributeTrait::Tags; + +has stuff => ( + is => 'rw', + isa => 'Int', + traits => ['MultiValued::Tags'], + default => 3, + predicate => 'has_stuff', + clearer => 'clear_stuff', +); + +has other => ( + is => 'rw', + isa => 'Str', + traits => ['MultiValued::Tags'], + predicate => 'has_other', + clearer => 'clear_other', +); +} +package main; +use Test::Most 'die'; +use Data::Printer; + +subtest 'default' => sub { + my $obj = Foo->new(); + + ok(!$obj->has_other,'not has other'); + ok($obj->has_stuff,'has stuff'); + + is($obj->stuff,3,'default'); +}; + +subtest 'constructor param' => sub { + my $obj = Foo->new({stuff=>12,other=>'bar'}); + + ok($obj->has_other,'has other'); + ok($obj->has_stuff,'has stuff'); + + is($obj->stuff,12,'param'); + is($obj->other,'bar','param'); +}; + +subtest 'with tags' => sub { + my $obj = Foo->new(); + + my $opts = {tag=>'one'}; + + ok($obj->has_stuff,'has stuff'); + ok(!$obj->has_stuff_multi($opts),'not has stuff tagged'); + ok(!$obj->has_other,'not has other'); + ok(!$obj->has_other_multi($opts),'not has other tagged'); + + $obj->stuff_multi($opts,7); + $obj->other_multi($opts,'foo'); + + is($obj->stuff,3,'default'); + is($obj->stuff_multi($opts),7,'stuff tagged'); + is($obj->other_multi($opts),'foo','other tagged'); +}; + +done_testing(); |