forked from Raku/roast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture-signature.t
42 lines (33 loc) · 884 Bytes
/
capture-signature.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 6;
sub t1(%h) {
given %h {
when :(Int :$a) { "pivo" }
when :(Str :$a) { "slivovica" }
}
}
my %h = a => 42;
is t1(%h), "pivo", "signature smart-match against hash works (1)";
%h<a> = "moja draha";
is t1(%h), "slivovica", "signature smart-match against hash works (1)";
sub t2(@a) {
given @a {
when :($a) { "godis" }
when :($a, $b) { "om nom nom" }
}
}
is t2([1]), "godis", "signature smart-match against array works (1)";
is t2([1,2]), "om nom nom", "signature smart-match against array works (2)";
# RT #77164
{
sub f($ = rand) { };
ok \() ~~ &f.signature, 'can smart-match against a signature with a default value';
}
# RT #118581
{
lives_ok { \(1) ~~ :(int $x as Str) },
'can match integer capture against signature with native integer coercing to Str';
}
done;
# vim: ft=perl6