forked from Raku/roast
/
closure.t
50 lines (37 loc) · 1.09 KB
/
closure.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
46
47
48
49
50
use v6;
use Test;
=begin pod
This file was derived from the perl5 CPAN module Perl6::Rules,
version 0.3 (12 Apr 2004), file t/codevars.t.
It has (hopefully) been, and should continue to be, updated to
be valid perl6.
=end pod
# L<S05/Bracket rationalization/It now delimits an embedded closure>
plan 12;
{
my $x = 3;
my $y = 2;
ok 'a' ~~ /. { $y = $x; 0 }/, 'can match and execute a closure';
is $y, 3, 'could access and update outer lexicals';
}
#?rakudo skip 'assignment to match variables (dubious)'
{
ok("abc" ~~ m/a(bc){$<caught> = $0}/, 'Inner match');
is(~$/<caught>, "bc", 'Inner caught');
}
my $caught = "oops!";
ok("abc" ~~ m/a(bc){$caught = $0}/, 'Outer match');
is($caught, "bc", 'Outer caught');
#?rakudo skip 'assignment to match variables (dubious)'
{
ok("abc" ~~ m/a(bc){$0 = uc $0}/, 'Numeric match');
is($/, "abc", 'Numeric matched');
is($0, "BC", 'Numeric caught');
}
#?rakudo skip 'make() inside closure'
{
ok("abc" ~~ m/a(bc){make uc $0}/ , 'Zero match');
is($($/), "BC", 'Zero matched');
is(~$0, "bc", 'One matched');
}
# vim: ft=perl6