play jenga
[gitmo/Moo.git] / xt / moose-accessor-isa.t
CommitLineData
b014a523 1use strictures 1;
2use Test::More;
3use Test::Exception;
4
5use 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
27lives_ok {
28 Bar->new(frooh => 1, frew => 1);
29} 'creation of valid Bar';
30
31dies_ok {
32 Bar->new(frooh => 'silly', frew => 1);
33} 'creation of invalid Bar validated by coderef';
34
35dies_ok {
36 Bar->new(frooh => 1, frew => 'goose');
37} 'creation of invalid Bar validated by quoted sub';
38
39done_testing;