Skip to content

Commit aaf36de

Browse files
committed
Unfudge &?BLOCK test; add closure semantics test.
1 parent 4331787 commit aaf36de

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

S02-magicals/block.t

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ This tests the &?BLOCK magical from Synopsis 6
1010

1111
# L<S06/The C<&?BLOCK> object>
1212

13-
plan 1;
13+
plan 3;
1414

15-
#?rakudo skip '&?BLOCK NYI RT #125131'
1615
{
1716
# L<S02/Names/Which block am I in?>
1817
# L<S06/The C<&?BLOCK> object/tail-recursion on an anonymous block:>
@@ -21,4 +20,19 @@ my $anonfactorial = -> Int $n { $n < 2 ?? 1 !! $n * &?BLOCK($n-1) };
2120
my $result = $anonfactorial(3);
2221
is($result, 6, 'the &?BLOCK magical worked');
2322
}
23+
24+
{
25+
my @collected;
26+
sub foo($a) {
27+
-> $n {
28+
@collected.push($a);
29+
$n == 1 ?? 1 !! $n * &?BLOCK($n - 1)
30+
}
31+
}
32+
my $b1 = foo('a');
33+
my $b2 = foo('b');
34+
is $b1(4), 24, 'Correct result from function generator returning function using &?BLOCK';
35+
is @collected.join(''), 'aaaa', 'Correct closure semantics with &?BLOCK';
36+
}
37+
2438
# vim: ft=perl6

0 commit comments

Comments
 (0)