Skip to content

Commit 72cc163

Browse files
committed
test file for named parameter renaming/aliasing
1 parent 5fe92c0 commit 72cc163

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

S06-signature/named-renaming.t

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use v6;
2+
use Test;
3+
4+
plan 10;
5+
6+
{
7+
sub f(:a(:$b)) { $b }
8+
sub g(:a( $b)) { $b }
9+
10+
is f( a => 1), 1, 'can use the alias name (1)';
11+
is g( a => 1), 1, 'can use the alias name (1)';
12+
is f( b => 1), 1, 'can use the var name';
13+
dies_ok { eval 'g( b => 1)' },
14+
'cannot use the var name if there is no : in front of it';
15+
}
16+
17+
{
18+
sub mandatory(:x(:$y)!) { $y }
19+
is mandatory( y => 2), 2, 'mandatory named';
20+
is mandatory( x => 3), 3, 'mandatory renamed';
21+
dies_ok { eval 'mandatory()' }, 'and it really is mandatory';
22+
}
23+
24+
{
25+
sub typed(:i(:%j)) { %j.keys.[0] };
26+
is typed(i => { a => 1 }), 'a', 'typed renames -- sanity';
27+
dies_ok { eval 'typed(:j)' }, 'type constraint on var';
28+
dies_ok { eval 'typed(:i)' }, 'type constraint on var propagates to alias';
29+
}

0 commit comments

Comments
 (0)