X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F043-parameterized-type.t;h=7bc3edb492b2a3ac5a3500a1f11b5dce010e80be;hb=1f7ac337dbaf78702b2a316e9b64b9cea8fd7608;hp=8bc1d982d23b9c33987affc6297645c6b6913901;hpb=5fa003bf0b3308fd48519ff1173feb778c550c01;p=gitmo%2FMouse.git diff --git a/t/043-parameterized-type.t b/t/043-parameterized-type.t index 8bc1d98..7bc3edb 100644 --- a/t/043-parameterized-type.t +++ b/t/043-parameterized-type.t @@ -1,13 +1,11 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 7; use Test::Exception; -TODO: { - local $TODO = "Mouse does not support parameterized types yet"; - - eval { +{ + { package Foo; use Mouse; @@ -15,8 +13,44 @@ TODO: { is => 'ro', isa => 'HashRef[Int]', ); + + has bar => ( + is => 'ro', + isa => 'ArrayRef[Int]', + ); + + has 'complex' => ( + is => 'rw', + isa => 'ArrayRef[HashRef[Int]]' + ); }; ok(Foo->meta->has_attribute('foo')); -}; + + lives_and { + my $hash = { a => 1, b => 2, c => 3 }; + my $array = [ 1, 2, 3 ]; + my $complex = [ { a => 1, b => 1 }, { c => 2, d => 2} ]; + my $foo = Foo->new(foo => $hash, bar => $array, complex => $complex); + + is_deeply($foo->foo(), $hash, "foo is a proper hash"); + is_deeply($foo->bar(), $array, "bar is a proper array"); + is_deeply($foo->complex(), $complex, "complex is a proper ... structure"); + } "Parameterized constraints work"; + + # check bad args + throws_ok { + Foo->new( foo => { a => 'b' }); + } qr/Attribute \(foo\) does not pass the type constraint because: Validation failed for 'HashRef\[Int\]' failed with value/, "Bad args for hash throws an exception"; + + throws_ok { + Foo->new( bar => [ a => 'b' ]); + } qr/Attribute \(bar\) does not pass the type constraint because: Validation failed for 'ArrayRef\[Int\]' failed with value/, "Bad args for array throws an exception"; + + throws_ok { + Foo->new( complex => [ { a => 1, b => 1 }, { c => "d", e => "f" } ] ) + } qr/Attribute \(complex\) does not pass the type constraint because: Validation failed for 'ArrayRef\[HashRef\[Int\]\]' failed with value/, "Bad args for complex types throws an exception"; +} + +