summaryrefslogtreecommitdiff
path: root/Data-MultiValued/t/moose-tagged.t
diff options
context:
space:
mode:
Diffstat (limited to 'Data-MultiValued/t/moose-tagged.t')
-rw-r--r--Data-MultiValued/t/moose-tagged.t67
1 files changed, 67 insertions, 0 deletions
diff --git a/Data-MultiValued/t/moose-tagged.t b/Data-MultiValued/t/moose-tagged.t
new file mode 100644
index 0000000..86fb8b9
--- /dev/null
+++ b/Data-MultiValued/t/moose-tagged.t
@@ -0,0 +1,67 @@
+#!perl
+use strict;
+use warnings;
+
+package Foo;{
+use Moose;
+use Data::MultiValued::AttributeTrait::Tagged;
+
+has stuff => (
+ is => 'rw',
+ isa => 'Int',
+ traits => ['MultiValued::Tagged'],
+ default => 3,
+ predicate => 'has_stuff',
+ clearer => 'clear_stuff',
+);
+
+has other => (
+ is => 'rw',
+ isa => 'Str',
+ traits => ['MultiValued::Tagged'],
+ 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_tagged($opts),'not has stuff tagged');
+ ok(!$obj->has_other,'not has other');
+ ok(!$obj->has_other_tagged($opts),'not has other tagged');
+
+ $obj->stuff_tagged($opts,7);
+ $obj->other_tagged($opts,'foo');
+
+ is($obj->stuff,3,'default');
+ is($obj->stuff_tagged($opts),7,'stuff tagged');
+ is($obj->other_tagged($opts),'foo','other tagged');
+};
+
+done_testing();