X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F070_native_traits%2F011_array_subtypes.t;h=832c46c8410f5014c1ba431b79c42baa09da71f7;hb=7a431e9c3e8c7ccf455d775c939ea85bd7d7dc30;hp=d78ac87d6f5ab5e5203643b6235aa6e6471d0129;hpb=14f358ac1dd05aadfd41371b28e3fd00c01810ed;p=gitmo%2FMoose.git diff --git a/t/070_native_traits/011_array_subtypes.t b/t/070_native_traits/011_array_subtypes.t index d78ac87..832c46c 100644 --- a/t/070_native_traits/011_array_subtypes.t +++ b/t/070_native_traits/011_array_subtypes.t @@ -59,6 +59,20 @@ use Test::Fatal; push_a3 => 'push', }, ); + + has a4 => ( + traits => ['Array'], + is => 'rw', + isa => 'ArrayRef', + lazy => 1, + default => 'invalid', + clearer => '_clear_a4', + handles => { + get_a4 => 'get', + push_a4 => 'push', + accessor_a4 => 'accessor', + }, + ); } my $foo = Foo->new; @@ -133,4 +147,32 @@ my $foo = Foo->new; is_deeply( $foo->a3, [ 1, 3 ], "a3 - correct contents" ); } +{ + my $expect = qr/\QAttribute (a4) does not pass the type constraint because: Validation failed for 'ArrayRef' with value invalid/; + + like( + exception { $foo->accessor_a4(0); }, + $expect, + 'invalid default is caught when trying to read via accessor' + ); + + like( + exception { $foo->accessor_a4(0 => 42); }, + $expect, + 'invalid default is caught when trying to write via accessor' + ); + + like( + exception { $foo->push_a4(42); }, + $expect, + 'invalid default is caught when trying to push' + ); + + like( + exception { $foo->get_a4(42); }, + $expect, + 'invalid default is caught when trying to get' + ); +} + done_testing;