update repo to point to github
[gitmo/Moo.git] / t / has-array.t
1 use strictures;
2 use Test::More;
3 use Test::Fatal;
4
5 is(exception {
6   package Local::Test::Role1;
7   use Moo::Role;
8   has [qw/ attr1 attr2 /] => (is => 'ro');
9 }, undef, 'has \@attrs works in roles');
10
11 is(exception {
12   package Local::Test::Class1;
13   use Moo;
14   with 'Local::Test::Role1';
15   has [qw/ attr3 attr4 /] => (is => 'ro');
16 }, undef, 'has \@attrs works in classes');
17
18 my $obj = new_ok 'Local::Test::Class1' => [
19   attr1  => 1,
20   attr2  => 2,
21   attr3  => 3,
22   attr4  => 4,
23 ];
24
25 can_ok(
26   $obj,
27   qw( attr1 attr2 attr3 attr4 ),
28 );
29
30 like(exception {
31   package Local::Test::Role2;
32   use Moo::Role;
33   has [qw/ attr1 attr2 /] => (is => 'ro', 'isa');
34 }, qr/^Invalid options for 'attr1', 'attr2' attribute\(s\): even number of arguments expected, got 3/,
35   'correct exception when has given bad parameters in role');
36
37 like(exception {
38   package Local::Test::Class2;
39   use Moo;
40   has [qw/ attr3 attr4 /] => (is => 'ro', 'isa');
41 }, qr/^Invalid options for 'attr3', 'attr4' attribute\(s\): even number of arguments expected, got 3/,
42   'correct exception when has given bad parameters in class');
43
44 done_testing;