summaryrefslogtreecommitdiff
path: root/t/moose-ranges.t
blob: 404e649816ed7493f8d46c33084562b9dd4afe35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!perl 
use strict;
use warnings;
 
package Foo;{ 
use Moose;
use Data::MultiValued::AttributeTrait::Ranges;
 
has stuff => (
    is => 'rw',
    isa => 'Int',
    traits => ['MultiValued::Ranges'],
    default => 3,
    predicate => 'has_stuff',
    clearer => 'clear_stuff',
);
 
has other => (
    is => 'rw',
    isa => 'Str',
    traits => ['MultiValued::Ranges'],
    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 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');
};
 
done_testing();