bump version
[gitmo/Moo.git] / t / accessor-pred-clear.t
CommitLineData
8f333548 1use strictures 1;
2use Test::More;
3
4{
5 package Foo;
6
b1eebd55 7 use Moo;
8f333548 8
e8dc5201 9 my @params = (is => 'ro', lazy => 1, default => sub { 3 });
10
11 has one => (@params, predicate => 'has_one', clearer => 'clear_one');
12
13 has $_ => (@params, clearer => 1, predicate => 1) for qw( bar _bar );
8f333548 14}
15
16my $foo = Foo->new;
17
e8dc5201 18for ( qw( one bar _bar ) ) {
19 my ($lead, $middle) = ('_' x /^_/, '_' x !/^_/);
20 my $predicate = $lead . "has$middle$_";
21 my $clearer = $lead . "clear$middle$_";
22
23 ok(!$foo->$predicate, 'empty');
24 is($foo->$_, 3, 'lazy default');
25 ok($foo->$predicate, 'not empty now');
26 is($foo->$clearer, 3, 'clearer returns value');
27 ok(!$foo->$predicate, 'clearer empties');
28 is($foo->$_, 3, 'default re-fired');
29 ok($foo->$predicate, 'not empty again');
30}
8f333548 31
32done_testing;