File: has-array.t

package info (click to toggle)
libmoo-perl 2.002005-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 856 kB
  • ctags: 192
  • sloc: perl: 2,561; makefile: 6
file content (44 lines) | stat: -rw-r--r-- 1,107 bytes parent folder | download | duplicates (3)
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
use Moo::_strictures;
use Test::More;
use Test::Fatal;

is(exception {
  package Local::Test::Role1;
  use Moo::Role;
  has [qw/ attr1 attr2 /] => (is => 'ro');
}, undef, 'has \@attrs works in roles');

is(exception {
  package Local::Test::Class1;
  use Moo;
  with 'Local::Test::Role1';
  has [qw/ attr3 attr4 /] => (is => 'ro');
}, undef, 'has \@attrs works in classes');

my $obj = new_ok 'Local::Test::Class1' => [
  attr1  => 1,
  attr2  => 2,
  attr3  => 3,
  attr4  => 4,
];

can_ok(
  $obj,
  qw( attr1 attr2 attr3 attr4 ),
);

like(exception {
  package Local::Test::Role2;
  use Moo::Role;
  has [qw/ attr1 attr2 /] => (is => 'ro', 'isa');
}, qr/^Invalid options for 'attr1', 'attr2' attribute\(s\): even number of arguments expected, got 3/,
  'correct exception when has given bad parameters in role');

like(exception {
  package Local::Test::Class2;
  use Moo;
  has [qw/ attr3 attr4 /] => (is => 'ro', 'isa');
}, qr/^Invalid options for 'attr3', 'attr4' attribute\(s\): even number of arguments expected, got 3/,
  'correct exception when has given bad parameters in class');

done_testing;