-
Notifications
You must be signed in to change notification settings - Fork 135
/
slurpy-and-interpolation.t
45 lines (31 loc) · 1.18 KB
/
slurpy-and-interpolation.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
use v6;
use Test;
plan 7;
# L<S03/Argument List Interpolating/"interpolate">
# try to flatten the args for baz() to match
sub baz ($a, $b) { return "a: $a b: $b"}
sub invoke (*@args) { baz(|@args) }
my $val;
lives-ok {
$val = invoke(1, 2);
}, '... slurpy args flattening and matching parameters';
is($val, 'a: 1 b: 2', '... slurpy args flattening and matching parameters');
# try to flatten the args for the anon sub to match
sub invoke2 ($f, *@args) { $f(|@args) };
is(invoke2(sub ($a, $b) { return "a: $a b: $b"}, 1, 2), 'a: 1 b: 2',
'... slurpy args flattening and matching parameters');
dies-ok {
invoke2(sub ($a, $b) { return "a: $a b: $b"}, 1, 2, 3);
}, '... slurpy args flattening and not matching because of too many parameters';
# used to be a Rakudo regression, RT #62730
{
sub f1(*%h) { %h.perl };
sub f2(*%h) { f1(|%h) };
lives-ok { f2( :a(1) ) },
'Can interpolate hashes into slurpy named parameters';
is EVAL(f2(:a(4))).<a>, 4, '... with a sane return value';
}
# RT #113804
#?niecza skip "Unable to resolve method Capture in type Range"
is join('|', |(1..5)), '1|2|3|4|5', 'can interpolate ranges into arglists';
# vim: ft=perl6