-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
50complextypes.t
62 lines (46 loc) · 955 Bytes
/
50complextypes.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use strict;
use warnings;
use Test::More;
use Test::Fatal;
BEGIN {
if ($] lt '5.016') {
plan(skip_all => 'known limitation in Perl 5.14');
exit();
}
}
use Zydeco factory_package => 'Local';
class Foo;
class Bar {
method bar (
# Integer or complex thingy
Int | # comemnt here
ArrayRef[Str|HashRef[~Int]]
$baz # ... called $baz
= 999 # defaults to 999
) {
1;
}
method baz ( Ints $z ) {
return $z;
}
begin {
my $t = Type::Registry->for_class($package);
$t->add_type(ArrayRef[Int] => 'Ints');
}
}
my $bar = Local->new_bar;
ok( $bar->bar( 1 ) );
ok( $bar->bar( [qw/ x y z /] ) );
ok( $bar->bar( [qw/ x y z /, {}] ) );
ok( $bar->bar( [qw/ x y z /, { quux => 'quuux' }] ) );
ok( $bar->bar( [qw/ x y z /, { quux => \1 }] ) );
isnt(
exception { $bar->bar( [qw/ x y z /, { quux => 42 }] ) },
undef,
);
is_deeply( $bar->baz([1,2,3]), [1,2,3] );
isnt(
exception { $bar->baz(2) },
undef,
);
done_testing;