X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FFunction-Parameters.git;a=blobdiff_plain;f=t%2Fforeign%2FMethod-Signatures%2Ftype_check.t;h=9fbb3e860105f1a3ddef1d786edb5fdae6efb93a;hp=1a519144d8ed9677513ca02f42bc88dfb4f08cc8;hb=1a52f2db46f6d870454428a07bfae09e0359eeee;hpb=ff265988561375d3cf480004e29e3891094c0afb diff --git a/t/foreign/Method-Signatures/type_check.t b/t/foreign/Method-Signatures/type_check.t index 1a51914..9fbb3e8 100644 --- a/t/foreign/Method-Signatures/type_check.t +++ b/t/foreign/Method-Signatures/type_check.t @@ -4,9 +4,9 @@ use strict; use warnings FATAL => 'all'; use Test::More - eval { require Moose; 1 } - ? () - : (skip_all => "Moose required for testing types") + eval { require Moose; 1 } + ? () + : (skip_all => "Moose required for testing types") ; use Test::More; use Test::Fatal; @@ -38,10 +38,15 @@ our @TYPES = maybe_int => 'Maybe[Int]' => [ 42, undef ] => 'foo' , paramized_aref => 'ArrayRef[Num]' => [[ 6.5, 42, 1e23 ]] => [[ 6.5, 42, 'thing' ]] , paramized_href => 'HashRef[Num]' => { a => 6.5, b => 2, c => 1e23 } => { a => 6.5, b => 42, c => 'thing' } , + paramized_nested=> 'HashRef[ArrayRef[Int]]' + => { foo=>[1..3], bar=>[1] } => { foo=>['a'] } , ## ScalarRef[X] not implemented in Mouse, so this test is moved to typeload_moose.t ## if Mouse starts supporting it, the test could be restored here paramized_sref => 'ScalarRef[Num]' => \42 => \'thing' , int_or_aref => 'Int|ArrayRef[Int]' => [ 42 , [42 ] ] => 'foo' , + int_or_aref_or_undef + => 'Int|ArrayRef[Int]|Undef' + => [ 42 , [42 ], undef ] => 'foo' , ); @@ -49,9 +54,14 @@ our $tester; { package TypeCheck::Class; + use strict; + use warnings; + use Test::More; use Test::Fatal; + use Function::Parameters qw(:strict); + method new ($class:) { bless {}, $class; } sub _list { return ref $_[0] eq 'ARRAY' ? @{$_[0]} : ( $_[0] ); } @@ -67,7 +77,7 @@ our $tester; # make sure the declaration of the method doesn't throw a warning is eval qq{ method $method ($type \$bar) {} 42 }, 42; - is $@, ''; + is $@, ''; # positive test--can we call it with a good value? my @vals = _list($goodval); @@ -131,8 +141,9 @@ our $tester; $method = 'unknown_paramized_type'; $type = 'Bmoogle[Int]'; is eval qq{ method $method ($type \$bar) {} 42 }, undef; - like $@, qr/\QCould not locate the base type (Bmoogle)/; + like $@, qr/\QCould not locate the base type (Bmoogle)/; like exception { $tester->$method(42) }, qr/\QCan't locate object method "unknown_paramized_type" via package "TypeCheck::Class"/; + }