forked from Raku/roast
/
introspection.t
42 lines (31 loc) · 1.26 KB
/
introspection.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
use v6;
use Test;
plan 12;
# L<S06/Other matters/Introspection>
# introspecting only subs
only sub only-sub($a, $b) { "only" }; #OK not used
# .candidates
is(&only-sub.candidates.elems,1,"an only subs lists itself in the .candidates");
is(&only-sub.candidates[0].(1,2),"only","an only subs lists itself in the .candidates");
# .cando
is(&only-sub.cando(\(1,2)).elems,1,"an only sub implements .cando");
is(&only-sub.cando(\(1,2)).[0].(1,2),"only","an only sub implements .cando");
# .signature
ok(\(1,2) ~~ &only-sub.signature,"an only sub implements .signature");
# introspecting multi subs
multi sub multi-sub(1,2) { "m1" };
multi sub multi-sub(1) { "m2" };
multi sub multi-sub() { "m3" };
# .candidates
is(&multi-sub.candidates.elems,3,"a multi sub returns all its candidates");
# .cando
is(&multi-sub.cando(\(1,2)).[0].(1,2),"m1","you can invoke through introspection");
is(&multi-sub.cando(\(1)).[0].(1),"m2","you can invoke through introspection");
is(&multi-sub.cando(\()).[0].(),"m3","you can invoke through introspection");
# .signature
{
my $sig = &multi-sub.signature;
ok(\(1,2) ~~ $sig,"junction sig matches first candidate");
ok(\(1) ~~ $sig,"junction sig matches second candidate");
ok(\() ~~ $sig, "junction sig matches third candidate");
}