Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Unfudge &?BLOCK test; add closure semantics test.
  • Loading branch information
jnthn committed Jul 9, 2015
1 parent 4331787 commit aaf36de
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions S02-magicals/block.t
Expand Up @@ -10,9 +10,8 @@ This tests the &?BLOCK magical from Synopsis 6

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

plan 1;
plan 3;

#?rakudo skip '&?BLOCK NYI RT #125131'
{
# L<S02/Names/Which block am I in?>
# L<S06/The C<&?BLOCK> object/tail-recursion on an anonymous block:>
Expand All @@ -21,4 +20,19 @@ my $anonfactorial = -> Int $n { $n < 2 ?? 1 !! $n * &?BLOCK($n-1) };
my $result = $anonfactorial(3);
is($result, 6, 'the &?BLOCK magical worked');
}

{
my @collected;
sub foo($a) {
-> $n {
@collected.push($a);
$n == 1 ?? 1 !! $n * &?BLOCK($n - 1)
}
}
my $b1 = foo('a');
my $b2 = foo('b');
is $b1(4), 24, 'Correct result from function generator returning function using &?BLOCK';
is @collected.join(''), 'aaaa', 'Correct closure semantics with &?BLOCK';
}

# vim: ft=perl6

0 comments on commit aaf36de

Please sign in to comment.