Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 75 lines (61 sloc) 2.39 kB
94a9756 [t/spec] first real signature introspection tests
moritz authored
1 use v6;
2 use Test;
3 plan *;
4
5 # L<S06/Signature Introspection>
6
7 {
be253a0 [t/spec] more signature introspection
moritz authored
8 sub a($x, Int $y?, :$z) { };
94a9756 [t/spec] first real signature introspection tests
moritz authored
9 isa_ok &a.signature.params, List, '.params is a List';
10 my @l = &a.signature.params;
11 ok ?(all(@l) ~~ Parameter), 'And all items are Paramters';
12 is +@l, 3, 'we have three of them';
13 is ~(@l>>.name), '$x $y $z', 'can get the names with sigils';
14 ok @l[0].type === Any, 'Could get first type';
15 ok @l[1].type === Int, 'Could get second type';
16
17 is ~(@l>>.readonly), '1 1 1', 'they are all read-only';
18 is ~(@l>>.rw), '0 0 0', '... none rw';
19 is ~(@l>>.copy), '0 0 0', '... none copy';
20 is ~(@l>>.ref), '0 0 0', '... none ref';
21 is ~(@l>>.slurpy), '0 0 0', '... none slurpy';
22 is ~(@l>>.optional), '0 1 1', '... some optional';
23 is ~(@l>>.invocant), '0 0 0', '... none invocant';
be253a0 [t/spec] more signature introspection
moritz authored
24 is ~(@l>>.named), '0 0 1', '... one named';
25 }
94a9756 [t/spec] first real signature introspection tests
moritz authored
26
be253a0 [t/spec] more signature introspection
moritz authored
27 {
28 sub b(:x($a)! is rw, :$y is ref, :$z is copy) { };
29 my @l = &b.signature.params;
30 #?rakudo todo 'is ref'
31 is ~(@l>>.readonly), '0 0 0', '(second sig) none are all read-only';
32 is ~(@l>>.rw), '1 0 0', '... one rw';
33 #?rakudo todo 'is ref'
34 is ~(@l>>.ref), '0 1 0', '... one ref';
35 is ~(@l>>.copy), '0 0 1', '... one copy';
36 is ~(@l>>.slurpy), '0 0 0', '... none slurpy';
37 is ~(@l>>.optional), '0 1 1', '... some optional';
38 is ~(@l>>.invocant), '0 0 0', '... none invocant';
39 is ~(@l>>.named), '1 1 1', '... one named';
40
41 is ~@l[0].named_names, 'x', 'named_names work';
42 is ~@l[0].name, '$a', '.name works for renamed params';
43 }
44
45 {
46 sub d(*@pos, *%named) { };
47 my @l = &d.signature.params;
48 is ~(@l>>.named), '0 1', '.named for slurpies';
49 is ~(@l>>.slurpy), '1 1', '.slurpy';
50 is ~(@l>>.name), '@pos %named', '.name for slurpies';
51 }
52
53
54 #?rakudo skip 'multi-level renamed parameters'
55 {
56 sub d(:x(:y(:z($a)))) { };
57 is ~&d.signature.params.[0].named_names.sort, 'x y z', 'multi named_names';
58 is ~&d.signature.params.[0].name, '$a', '... and .name still works';
94a9756 [t/spec] first real signature introspection tests
moritz authored
59 }
60
9305b95 [t/spec] failing tests for .default
moritz authored
61 #?rakudo skip '.default'
62 {
63 sub e($x = 3; $y = { 2 + $x }) { };
64 my @l = &e.signature.params>>.default;
65 ok ?( all(@l) ~~ Code ), '.default returns closure';
66 is @l[0].(), 3, 'first closure works';
67 is @l[1].().(), 5, 'closure as default value captured outer default value';
68
69 }
70
94a9756 [t/spec] first real signature introspection tests
moritz authored
71
72 done_testing;
73
74 # vim: ft=perl6
Something went wrong with that request. Please try again.