5ff20f8479a68bd57546081a334f4f1fa97286ba
[gitmo/Moo.git] / t / accessor-default.t
1 use strictures 1;
2 use Test::More;
3
4 {
5   package Foo;
6
7   use Sub::Quote;
8   use Moo;
9
10   has one => (is => 'ro', lazy => 1, default => quote_sub q{ {} });
11   has two => (is => 'ro', lazy => 1, builder => '_build_two');
12   sub _build_two { {} }
13   has three => (is => 'ro', default => quote_sub q{ {} });
14   has four => (is => 'ro', builder => '_build_four');
15   sub _build_four { {} }
16   has five => (is => 'ro', init_arg => undef, default => sub { {} });
17   has six => (is => 'ro', builder => 1);
18   sub _build_six { {} }
19   has seven => (is => 'ro', required => 1, default => quote_sub q{ {} });
20 }
21
22 sub check {
23   my ($attr, @h) = @_;
24
25   is_deeply($h[$_], {}, "${attr}: empty hashref \$h[$_]") for 0..1;
26
27   isnt($h[0],$h[1], "${attr}: not the same hashref");
28 }
29
30 check one => map Foo->new->one, 1..2;
31
32 check two => map Foo->new->two, 1..2;
33
34 check three => map Foo->new->{three}, 1..2;
35
36 check four => map Foo->new->{four}, 1..2;
37
38 check five => map Foo->new->{five}, 1..2;
39
40 check six => map Foo->new->{six}, 1..2;
41
42 check seven => map Foo->new->{seven}, 1..2;
43
44 done_testing;