X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=t%2F001_mouse%2F043-parameterized-type.t;h=3e223e227c73692412d5df48dd8fee7303756656;hp=6eaedddc864720894321bedba581fa5c0c398819;hb=fc83f4cf2ef7708120a216bddc285b93082d7958;hpb=920139b3efca66d2caeeef306c97fa0da62c6b73 diff --git a/t/001_mouse/043-parameterized-type.t b/t/001_mouse/043-parameterized-type.t index 6eaeddd..3e223e2 100644 --- a/t/001_mouse/043-parameterized-type.t +++ b/t/001_mouse/043-parameterized-type.t @@ -1,9 +1,11 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 46; +use Test::More tests => 54; use Test::Exception; +use Tie::Hash; +use Tie::Array; { { package My::Role; @@ -183,4 +185,40 @@ ok $x->check([[10, undef]]); ok!$x->check([[10, 3.14]]); ok!$x->check({}); +$x = tie my @ta, 'Tie::StdArray'; +my $array_of_int = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Int]'); + +@$x = (1, 2, 3); +ok $array_of_int->check(\@ta), 'magical array'; + +@$x = (1, 2, 3.14); +ok !$array_of_int->check(\@ta); + +$x = tie my %th, 'Tie::StdHash'; + +my $hash_of_int = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('HashRef[Int]'); + +%$x = (foo => 1, bar => 3, baz => 5); +ok $hash_of_int->check(\%th), 'magical hash'; + +$x->{foo} = 3.14; +ok!$hash_of_int->check(\%th); + +my %th_clone; +while(my($k, $v) = each %th){ + $th_clone{$k} = $v; +} + +is( $hash_of_int->type_parameter, 'Int' ); + +if('Mouse' eq ('Mo' . 'use')){ # under Mouse + ok $hash_of_int->__is_parameterized(); + ok!$hash_of_int->type_parameter->__is_parameterized(); +} +else{ # under Moose + ok $hash_of_int->can('type_parameter'); + ok!$hash_of_int->type_parameter->can('type_parameter'); +} + +is_deeply \%th_clone, \%th, 'the hash iterator is initialized';