test Isa checking
[gitmo/Moo.git] / xt / moose-accessor-isa.t
1 use strictures 1;
2 use Test::More;
3 use Test::Exception;
4
5 use Moo::HandleMoose;
6
7 {
8    package FrewWithIsa;
9    use Moo::Role;
10    use Sub::Quote;
11
12    has frooh => (
13       is => 'rw',
14       isa => sub { die 'not int' unless $_[0] =~ /^\d$/ },
15    );
16
17    has frew => (
18       is => 'rw',
19       isa => quote_sub(q{ die 'not int' unless $_[0] =~ /^\d$/ }),
20    );
21
22    package Bar;
23    use Moose;
24    with 'FrewWithIsa';
25 }
26
27 lives_ok {
28    Bar->new(frooh => 1, frew => 1);
29 } 'creation of valid Bar';
30
31 dies_ok {
32    Bar->new(frooh => 'silly', frew => 1);
33 } 'creation of invalid Bar validated by coderef';
34
35 dies_ok {
36    Bar->new(frooh => 1, frew => 'goose');
37 } 'creation of invalid Bar validated by quoted sub';
38
39 done_testing;