support custom non-moose type constraints (#85851)
[p5sagit/Function-Parameters.git] / t / types_moose_2.t
similarity index 88%
rename from t/moose_types.t
rename to t/types_moose_2.t
index 1f5344d..2533cfe 100644 (file)
@@ -3,7 +3,7 @@ use warnings FATAL => 'all';
 use strict;
 
 use Test::More
-       eval { require Moose; 1 }
+       eval { require Moose::Util; 1 }
        ? (tests => 49)
        : (skip_all => "Moose required for testing types")
 ;
@@ -11,7 +11,7 @@ use Test::Fatal;
 
 use Function::Parameters qw(:strict);
 
-fun foo(Int $n, CodeRef $f, $x) {
+fun foo(('Int') $n, ('CodeRef') $f, $x) {
        $x = $f->($x) for 1 .. $n;
        $x
 }
@@ -19,7 +19,7 @@ fun foo(Int $n, CodeRef $f, $x) {
 is foo(0, fun {}, undef), undef;
 is foo(0, fun {}, "o hai"), "o hai";
 is foo(3, fun ($x) { "($x)" }, 1.5), "(((1.5)))";
-is foo(3, fun (Str $x) { "($x)" }, 1.5), "(((1.5)))";
+is foo(3, fun (('Str') $x) { "($x)" }, 1.5), "(((1.5)))";
 
 {
        my $info = Function::Parameters::info \&foo;
@@ -41,7 +41,14 @@ is foo(3, fun (Str $x) { "($x)" }, 1.5), "(((1.5)))";
 like exception { foo("ermagerd", fun {}, undef) }, qr/\bparameter 1.+\$n\b.+\bValidation failed\b.+\bInt\b.+ermagerd/;
 like exception { foo(0, {}, undef) }, qr/\bparameter 2.+\$f\b.+\bValidation failed\b.+\bCodeRef\b/;
 
-fun bar(((Function::Parameters::info(\&foo)->positional_required)[0]->type) $whoa) { $whoa * 2 }
+fun bar(
+       (
+               do {
+                       require Moose;
+                       (Function::Parameters::info(\&foo)->positional_required)[0]->type
+               }
+       ) $whoa
+) { $whoa * 2 }
 
 is bar(21), 42;
 {
@@ -58,7 +65,7 @@ is bar(21), 42;
 }
 
 {
-       my $info = Function::Parameters::info(fun ( ArrayRef [ Int | CodeRef ]@nom) {});
+       my $info = Function::Parameters::info(fun ( (q~ArrayRef [ Int | CodeRef ]~ )@nom) {});
        is $info->invocant, undef;
        is $info->positional_required, 0;
        is $info->positional_optional, 0;