Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Test closure semantics of &?ROUTINE.
  • Loading branch information
jnthn committed Jul 9, 2015
1 parent 2098c0c commit 4331787
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion S02-magicals/sub.t
Expand Up @@ -8,7 +8,7 @@ This tests the &?ROUTINE magical value
=end comment

plan 6;
plan 8;

# L<S06/The C<&?ROUTINE> object>
# L<S02/Names/Which routine am I in>
Expand Down Expand Up @@ -38,4 +38,18 @@ is($result3, 6, 'the &?ROUTINE magical works correctly in overloaded operators'
is $variable, &baz, '&?ROUTINE is correct inside a rule';
}

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

# vim: ft=perl6

0 comments on commit 4331787

Please sign in to comment.