Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add new signature/parameter matching tests.
  • Loading branch information
clsn committed Jan 26, 2014
1 parent 8fe2db8 commit 13c7fbf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
41 changes: 34 additions & 7 deletions S03-smartmatch/signature-signature.t
@@ -1,16 +1,43 @@
use v6;
use Test;
plan 5;
plan *;

#L<S03/Smart matching/Signature-signature>
{
ok :(Str) ~~ :(Str), 'signature :(Str) is the same as :(Str)';
nok :(Str) ~~ :(Int), 'signature :(Str) is not the same as :(Int)';
ok :(Str, Int) ~~ :(Str, Int), 'signature :(Str, Int) is the same as :(Str, Int)';
nok :(Str, Int) ~~ :(Int, Str), 'signature :(Str, Int) is not the same as :(Int, Str)';
nok :(Str, Int) ~~ :(Str, Int, Str), 'signature :(Str, Int) is not the same as :(Str, Int, Str)';
my @tests=
(:(Int), :(Int), True,
:(Int, Str), :(Int), False,
:(Int, Str $?), :(Int), True,
:(Any), :(Str), True,
:(*@_), :(Int, Rat, &), True,
:(:a(:b(:c($x)))), :(:a($x), :b($y)), False,
:(:a(:b(:c($x)))), :(:a($x)), True,
:(Any $x ($l, Int $r)), :(Int $x ($y, Str $z)), False,
:(:x($r) (Str $g, Any $i)), :(:x($t) (Int $f, Any $k)), False,
:(:x($r) (Str $g, Any $i)), :(:x($t) (Str $f, Str $k)), True,
:(Int @x, Any $b, Rat $n?, *@_), :(Int @, Str $, Rat, Str), True,
:(Str $a, Str $b), :(Str $a, Str $b?), False,
:(Any $x, :$foo!), :(Any $, :$foo), False,
:(Int, *%_), :(Int, Any :$x!, Str :$y), True,
:([Any, Str, Numeric]), :(@ (Complex, Str, Int)), True,
:(Complex $z, :$x, :$y, :$q), :(Complex, *%rest), False,
:(:$x, Int :$y, Cool :$z, *%_), :(*%_), False,
:(Mu, Any, Numeric), :(Mu, *@_), False,
);

for @tests -> $s1, $s2, $res {
is(($s2 ~~ $s1), $res, "{$s2.perl} ~~ {$s1.perl}");
}

#?rakudo skip "Parametric types"
#?niecza skip "Parametric types"
# Can't deal with parameters.
ok (:(::T $x, T $y) R~~ :(Str $y, Str $z)), "Parametric types";
#?rakudo skip "Code params with signatures"
# No support for code params with signatures yet.
ok (:(&foo(Str --> Bool)) R~~ :(&bar(Str --> Bool))),
"Code params with signatures";
}

done;

# vim: ft=perl6
2 changes: 1 addition & 1 deletion S06-signature/errors.t
Expand Up @@ -52,7 +52,7 @@ eval_dies_ok 'my class A { submethod BUILD(:$!notthere = 10) }; A.new',
{
try { EVAL 'sub rt72082(@a, $b) {}; rt72082(5)' };
my $error = ~$!;
ok $error ~~ / 'will never work' .* 'Expected' .* '(@a, $b)' /
ok $error ~~ / 'will never work' .* 'Expected' .* '(@a, Any $b)' /
}

# RT #76368
Expand Down
2 changes: 1 addition & 1 deletion integration/advent2009-day20.t
Expand Up @@ -11,7 +11,7 @@ is &foo.name, 'foo', 'Introspecting subroutine name';
my $bar = &foo;
is $bar.name, 'foo', 'Introspecting subroutine for a sub assigned to a scalar';

is &foo.signature.perl, ':(Int $i, @stuff, $blah = { ... })', 'Introspecting and stringification of subroutine signature';
is &foo.signature.perl, ':(Int $i, @stuff, Any $blah = { ... })', 'Introspecting and stringification of subroutine signature';

# Not sure if this is an appropriate test - as this code doesn't exist in the Advent Calendar
my @sig-info = \(name => '$i', type => 'Int'),
Expand Down

0 comments on commit 13c7fbf

Please sign in to comment.