summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/moose-ranges.t27
-rw-r--r--t/moose-tagged.t34
-rw-r--r--t/moose-tags-ranges.t136
3 files changed, 197 insertions, 0 deletions
diff --git a/t/moose-ranges.t b/t/moose-ranges.t
index 404e649..35ff83d 100644
--- a/t/moose-ranges.t
+++ b/t/moose-ranges.t
@@ -34,6 +34,15 @@ subtest 'default' => sub {
ok($obj->has_stuff,'has stuff');
is($obj->stuff,3,'default');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_ranges($obj)],
+ [[undef,undef]],
+ 'stuff all_ranges');
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_ranges($obj)],
+ [],
+ 'other all_ranges');
};
subtest 'constructor param' => sub {
@@ -44,6 +53,15 @@ subtest 'constructor param' => sub {
is($obj->stuff,12,'param');
is($obj->other,'bar','param');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_ranges($obj)],
+ [[undef,undef]],
+ 'stuff all_ranges');
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_ranges($obj)],
+ [[undef,undef]],
+ 'other all_ranges');
};
subtest 'with ranges' => sub {
@@ -62,6 +80,15 @@ subtest 'with ranges' => sub {
is($obj->stuff,3,'default');
is($obj->stuff_multi($opts),7,'stuff ranged');
is($obj->other_multi($opts),'foo','other ranged');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_ranges($obj)],
+ [[undef,10],[10,20],[20,undef]],
+ 'stuff all_ranges');
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_ranges($obj)],
+ [[10,20]],
+ 'other all_ranges');
};
done_testing();
diff --git a/t/moose-tagged.t b/t/moose-tagged.t
index 1273bed..8e7dd97 100644
--- a/t/moose-tagged.t
+++ b/t/moose-tagged.t
@@ -39,6 +39,15 @@ subtest 'default' => sub {
ok($obj->has_stuff,'has stuff');
is($obj->stuff,3,'default');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_tags($obj)],
+ [undef],
+ 'stuff all_tags');
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_tags($obj)],
+ [],
+ 'other all_tags');
};
subtest 'constructor param' => sub {
@@ -49,6 +58,15 @@ subtest 'constructor param' => sub {
is($obj->stuff,12,'param');
is($obj->other,'bar','param');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_tags($obj)],
+ [undef],
+ 'stuff all_tags');
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_tags($obj)],
+ [undef],
+ 'other all_tags');
};
subtest 'with tags' => sub {
@@ -67,6 +85,22 @@ subtest 'with tags' => sub {
is($obj->stuff,3,'default');
is($obj->stuff_tagged($opts),7,'stuff tagged');
is($obj->other_multi($opts),'foo','other tagged');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_tags($obj)],
+ bag(undef,'one'),
+ 'stuff all_tags');
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_tags($obj)],
+ bag('one'),
+ 'other all_tags');
+
+ my @tags = $obj->meta->get_attribute('stuff')->all_tags($obj);
+ my $pred=$obj->meta->get_attribute('stuff')->multi_predicate;
+ for my $tag (@tags) {
+ ok($obj->$pred({tag=>$tag}),"stuff has tag @{[ $tag || 'undef' ]}");
+ }
+
};
done_testing();
diff --git a/t/moose-tags-ranges.t b/t/moose-tags-ranges.t
new file mode 100644
index 0000000..bb8fb06
--- /dev/null
+++ b/t/moose-tags-ranges.t
@@ -0,0 +1,136 @@
+#!perl
+use strict;
+use warnings;
+
+package Foo;{
+use Moose;
+use Data::MultiValued::AttributeTrait::TagsAndRanges;
+
+has stuff => (
+ is => 'rw',
+ isa => 'Int',
+ traits => ['MultiValued::TagsAndRanges'],
+ default => 3,
+ predicate => 'has_stuff',
+ clearer => 'clear_stuff',
+);
+
+has other => (
+ is => 'rw',
+ isa => 'Str',
+ traits => ['MultiValued::TagsAndRanges'],
+ 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');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_tags_and_ranges($obj)],
+ [[undef, [[undef,undef]]]],
+ 'stuff all_ranges');
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_tags_and_ranges($obj)],
+ [],
+ 'other all_ranges');
+};
+
+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');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_tags_and_ranges($obj)],
+ [[undef, [[undef,undef]]]],
+ 'stuff all_ranges');
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_tags_and_ranges($obj)],
+ [[undef, [[undef,undef]]]],
+ 'other all_ranges');
+};
+
+subtest 'with ranges' => sub {
+ my $obj = Foo->new();
+
+ my $opts = {from=>10,to=>20,at=>15};
+
+ ok($obj->has_stuff,'has stuff');
+ ok($obj->has_stuff_multi($opts),'has stuff ranged (forever)');
+ ok(!$obj->has_other,'not has other');
+ ok(!$obj->has_other_multi($opts),'not has other ranged');
+
+ $obj->stuff_multi($opts,7);
+ $obj->other_multi($opts,'foo');
+
+ is($obj->stuff,3,'default');
+ is($obj->stuff_multi($opts),7,'stuff ranged');
+ is($obj->other_multi($opts),'foo','other ranged');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_tags($obj)],
+ [undef],
+ 'stuff all_tags');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_tags_and_ranges($obj)],
+ [[undef, [[undef,10],[10,20],[20,undef]]]],
+ 'stuff all_tags_and_ranges');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_tags_and_ranges($obj)],
+ [[undef, [[10,20]]]],
+ 'other all_tags_and_ranges');
+};
+
+subtest 'with tags and ranges' => sub {
+ my $obj = Foo->new();
+
+ my $opts = {from=>10,to=>20,at=>15,tag=>'x'};
+
+ ok($obj->has_stuff,'has stuff');
+ ok(!$obj->has_stuff_multi($opts),'has stuff ranged (forever)');
+ ok(!$obj->has_other,'not has other');
+ ok(!$obj->has_other_multi($opts),'not has other ranged');
+
+ $obj->stuff_multi($opts,7);
+ $obj->other_multi($opts,'foo');
+
+ is($obj->stuff,3,'default');
+ is($obj->stuff_multi($opts),7,'stuff ranged');
+ is($obj->other_multi($opts),'foo','other ranged');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_tags($obj)],
+ bag(undef,'x'),
+ 'stuff all_tags');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('stuff')->all_tags_and_ranges($obj)],
+ bag(
+ ['x', [[10,20]]],
+ [undef,[[undef,undef]]],
+ ),
+ 'stuff all_tags_and_ranges');
+
+ cmp_deeply(
+ [$obj->meta->get_attribute('other')->all_tags_and_ranges($obj)],
+ [['x', [[10,20]]]],
+ 'other all_tags_and_ranges');
+};
+
+done_testing();