X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F800_shikabased%2F010-isa-or.t;h=c60e45c3bf91bbbb1f38278f28a80d1d61f95855;hb=e6dc493dcf34553b9726d220f7aa42b0fc50eea5;hp=8b45921af06336642d906c660dec052f6c6f00a9;hpb=3b46bd4991dea7ead4e7f52a089222d24554e2bd;p=gitmo%2FMouse.git diff --git a/t/800_shikabased/010-isa-or.t b/t/800_shikabased/010-isa-or.t index 8b45921..c60e45c 100644 --- a/t/800_shikabased/010-isa-or.t +++ b/t/800_shikabased/010-isa-or.t @@ -6,15 +6,18 @@ use Test::More tests => 18; package Foo; use Mouse; use Mouse::Util::TypeConstraints; - subtype Baz => where { defined($_) && $_ eq 'Baz' }; + type Baz => where { defined($_) && $_ eq 'Baz' }; + coerce Baz => from 'ArrayRef', via { 'Baz' }; + has 'bar' => ( is => 'rw', isa => 'Str | Baz | Undef', coerce => 1 ); } eval { Foo->new( bar => +{} ); }; -ok $@, 'not got an object'; +like($@, qr/^Attribute \(bar\) does not pass the type constraint because: Validation failed for 'Baz\|Str\|Undef' failed with value HASH\(\w+\)/, 'type constraint and coercion failed') + or diag "\$@='$@'"; eval { isa_ok(Foo->new( bar => undef ), 'Foo'); @@ -32,7 +35,7 @@ my $f = Foo->new; eval { $f->bar([]); }; -ok !$@; +ok !$@, $@; is $f->bar, 'Baz', 'bar is baz (coerce from ArrayRef)'; eval { @@ -53,10 +56,10 @@ is $f->bar, undef, 'bar is undef'; use Mouse; use Mouse::Util::TypeConstraints; - subtype 'Type1' => where { defined($_) && $_ eq 'Name' }; + type 'Type1' => where { defined($_) && $_ eq 'Name' }; coerce 'Type1', from 'Str', via { 'Names' }; - subtype 'Type2' => where { defined($_) && $_ eq 'Group' }; + type 'Type2' => where { defined($_) && $_ eq 'Group' }; coerce 'Type2', from 'Str', via { 'Name' }; has 'foo' => ( is => 'rw', isa => 'Type1|Type2', coerce => 1 ); @@ -69,23 +72,23 @@ is $foo->foo, 'Name', 'foo is Name'; { package KLASS; - sub new { bless {}, shift }; + use Mouse; } { - package Baz; + package Funk; use Mouse; use Mouse::Util::TypeConstraints; - subtype 'Type3' => where { defined($_) && $_ eq 'Name' }; + type 'Type3' => where { defined($_) && $_ eq 'Name' }; coerce 'Type3', from 'CodeRef', via { 'Name' }; has 'foo' => ( is => 'rw', isa => 'Type3|KLASS|Undef', coerce => 1 ); } -eval { Baz->new( foo => 'aaa' ) }; -like $@, qr/Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Type3\|KLASS\|Undef' failed with value aaa/; +eval { Funk->new( foo => 'aaa' ) }; +like $@, qr/Attribute \(foo\) does not pass the type constraint because: Validation failed for 'KLASS\|Type3\|Undef' failed with value aaa/; -my $k = Baz->new; +my $k = Funk->new; ok $k, 'got an object 4'; $k->foo(sub {}); is $k->foo, 'Name', 'foo is Name';