From: Dave Rolsky Date: Thu, 21 Apr 2011 19:52:22 +0000 (-0500) Subject: Add comprehensive test for all builtin types as a simple class attribute and as a... X-Git-Tag: 2.0100~51 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=547000a55ea4b966678c34ba56b813242a5f498d;p=gitmo%2FMoose.git Add comprehensive test for all builtin types as a simple class attribute and as a native trait attribute --- diff --git a/t/type_constraints/util_std_type_constraints.t b/t/type_constraints/util_std_type_constraints.t index d0855d3..51b667c 100644 --- a/t/type_constraints/util_std_type_constraints.t +++ b/t/type_constraints/util_std_type_constraints.t @@ -3,6 +3,7 @@ use strict; use warnings; +use Test::Fatal; use Test::More; use Eval::Closure; @@ -1018,6 +1019,27 @@ sub test_constraint { ); } + my $class = Moose::Meta::Class->create_anon( + superclasses => ['Moose::Object'], + ); + $class->add_attribute( + simple => ( + is => 'ro', + isa => $type, + ) + ); + $class->add_attribute( + collection => ( + traits => ['Array'], + is => 'ro', + isa => 'ArrayRef[' . $type->name . ']', + default => sub { [] }, + handles => { add_to_collection => 'push' }, + ) + ); + + my $anon_class = $class->name; + for my $accept ( @{ $tests->{accept} || [] } ) { my $described = describe($accept); ok( @@ -1034,6 +1056,22 @@ sub test_constraint { "$name accepts $described using inlined constraint" ); } + + is( + exception { + $anon_class->new( simple => $accept ); + }, + undef, + "no exception passing $described to constructor" + ); + + is( + exception { + $anon_class->new()->add_to_collection($accept); + }, + undef, + "no exception passing $described to constructor" + ); } for my $reject ( @{ $tests->{reject} || [] } ) { @@ -1052,6 +1090,20 @@ sub test_constraint { "$name rejects $described using inlined constraint" ); } + + ok( + exception { + $anon_class->new( simple => $reject ); + }, + "got exception passing $described to constructor" + ); + + ok( + exception { + $anon_class->new()->add_to_collection($reject); + }, + "got exception passing $described to constructor" + ); } }