X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F800_shikabased%2F014-subtype-as.t;h=3dc197b5bbc4331ddea72452efeb4d4483ab104b;hb=b2b106d765ef1bcbb5ea3b215668baea1a9504b6;hp=cf9e40e11fbf6f5b211d0c489e72940480e5101e;hpb=1fbefea51e3234a987284705fc9c6cf34758a2a0;p=gitmo%2FMouse.git diff --git a/t/800_shikabased/014-subtype-as.t b/t/800_shikabased/014-subtype-as.t index cf9e40e..3dc197b 100644 --- a/t/800_shikabased/014-subtype-as.t +++ b/t/800_shikabased/014-subtype-as.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 12; use Scalar::Util qw/blessed/; { @@ -16,7 +16,7 @@ use Scalar::Util qw/blessed/; { package Foo; use Mouse; - use Mouse::TypeRegistry; + use Mouse::Util::TypeConstraints; subtype 'Type1' => as 'Str' => where { blessed($_) }; has str_obj => ( @@ -29,6 +29,19 @@ use Scalar::Util qw/blessed/; is => 'rw', isa => 'Type2', ); + + subtype 'Type3' => as 'Object'; + has as_only => ( + is => 'rw', + isa => 'Type3', + ); + + + type 'Type4'; + has any => ( + is => 'rw', + isa => 'Type4', + ); } eval { Foo->new( str_obj => Obj1->new ) }; @@ -45,3 +58,16 @@ like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Val my $f1 = eval { Foo->new( obj_str => Obj2->new ) }; isa_ok $f1, 'Foo'; is $f1->obj_str, 'Ref'; + +my $f2 = eval { Foo->new( as_only => Obj1->new ) }; +isa_ok $f2, 'Foo'; +is ref($f2->as_only), 'Obj1'; + +my $f3 = eval { Foo->new( any => Obj1->new ) }; +die $@ if $@; +isa_ok $f3, 'Foo'; +is ref($f3->any), 'Obj1'; + +my $f4 = eval { Foo->new( any => 'YATTA' ) }; +isa_ok $f4, 'Foo'; +is $f4->any, 'YATTA';