X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faccessor-coerce.t;h=4288b97f1705f72c7530fae073c06a9db8023999;hb=2fa823de095e7a25ed0278fda3de6c1690d9d19c;hp=7533adac0f9440a0df1b2aaf5168605eb095903e;hpb=9c02be6c5f4fa1a33e03b56809657d4ce6df0d91;p=gitmo%2FMoo.git diff --git a/t/accessor-coerce.t b/t/accessor-coerce.t index 7533ada..4288b97 100644 --- a/t/accessor-coerce.t +++ b/t/accessor-coerce.t @@ -94,7 +94,7 @@ run_for 'Baz'; ); } -like exception { Biff->new(plus_three => 1) }, qr/could not add three!/, 'Exception properly thrown'; +like exception { Biff->new(plus_three => 1) }, qr/coercion for "plus_three" failed: could not add three!/, 'Exception properly thrown'; { package Foo2; @@ -168,5 +168,38 @@ run_with_default_for 'Baz2'; like exception { Biff2->new() }, qr/could not add three!/, 'Exception properly thrown'; +{ + package Foo3; + + use Moo; + + has plus_three => ( + is => 'rw', + default => sub { 1 }, + coerce => sub { $_[0] + 3 }, + lazy => 1, + ); +} + +run_with_default_for 'Foo3'; + +{ + package Bar3; + + use Sub::Quote; + use Moo; + + has plus_three => ( + is => 'rw', + default => sub { 1 }, + coerce => quote_sub(q{ + my ($x) = @_; + $x + 3 + }), + lazy => 1, + ); +} + +run_with_default_for 'Bar3'; done_testing;