X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faccessor-pred-clear.t;h=e8f5cbffa70225316e1eb94738c75a54b6d7a894;hb=master;hp=4f733218247fae988e83867c267b9b8f415ea711;hpb=b1eebd55fe3d34b6afa73a4880737dc91379b71e;p=gitmo%2FMoo.git diff --git a/t/accessor-pred-clear.t b/t/accessor-pred-clear.t index 4f73321..e8f5cbf 100644 --- a/t/accessor-pred-clear.t +++ b/t/accessor-pred-clear.t @@ -6,20 +6,27 @@ use Test::More; use Moo; - has one => ( - is => 'ro', lazy => 1, default => sub { 3 }, - predicate => 'has_one', clearer => 'clear_one' - ); + my @params = (is => 'ro', lazy => 1, default => sub { 3 }); + + has one => (@params, predicate => 'has_one', clearer => 'clear_one'); + + has $_ => (@params, clearer => 1, predicate => 1) for qw( bar _bar ); } my $foo = Foo->new; -ok(!$foo->has_one, 'empty'); -is($foo->one, 3, 'lazy default'); -ok($foo->has_one, 'not empty now'); -is($foo->clear_one, 3, 'clearer returns value'); -ok(!$foo->has_one, 'clearer empties'); -is($foo->one, 3, 'default re-fired'); -ok($foo->has_one, 'not empty again'); +for ( qw( one bar _bar ) ) { + my ($lead, $middle) = ('_' x /^_/, '_' x !/^_/); + my $predicate = $lead . "has$middle$_"; + my $clearer = $lead . "clear$middle$_"; + + ok(!$foo->$predicate, 'empty'); + is($foo->$_, 3, 'lazy default'); + ok($foo->$predicate, 'not empty now'); + is($foo->$clearer, 3, 'clearer returns value'); + ok(!$foo->$predicate, 'clearer empties'); + is($foo->$_, 3, 'default re-fired'); + ok($foo->$predicate, 'not empty again'); +} done_testing;