Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

55 lines (42 sloc) 1.447 kb
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Method::Signatures;
note "types"; {
my %tests = (
q[Foo $bar] => [positional => "Foo"],
q[$bar] => [positional => undef],
q[type $bar, Some::Type @this] => [positional => "type", "Some::Type"],
q[RFC1234::Foo::bar32 $var] => [positional => "RFC1234::Foo::bar32"],
q[Foo :$var] => [named => "Foo"],
q[Foo::Bar $var] => [positional => "Foo::Bar"],
);
for my $proto (keys %tests) {
my $want = $tests{$proto};
my $ms = Method::Signatures->new;
$ms->parse_proto($proto);
my $which = shift @$want;
for my $idx (0..$#{$want}) {
my $method = $which.'_parameters';
is $ms->{signature}->$method->[$idx]->type, $want->[$idx] || '';
}
}
}
note "inject_for_type_check"; {
{
package My::MS;
use base "Method::Signatures";
sub inject_for_type_check {
my $self = shift;
my $sig = shift;
my $var = $sig->variable;
return "type_check('$var');";
}
}
my $ms = My::MS->new;
my $code = $ms->parse_proto( 'Foo $this, :$bar, Foo::Bar :$foobar' );
like $code, qr{type_check\('\$this'\)};
like $code, qr{type_check\('\$foobar'\)};
}
done_testing;
Jump to Line
Something went wrong with that request. Please try again.