/
opaque-ast.t
64 lines (46 loc) 路 1.26 KB
/
opaque-ast.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use v6;
use Test;
use experimental :macros;
=begin pod
=head1 DESCRIPTION
Tests for macros which return quasi but do not do splicing
See L<S06/"Macros">.
=end pod
plan 7;
# L<S06/Macros>
macro four () { quasi { 2+2 } }
is(four, 4, "macro returning quasi");
#?rakudo skip ':COMPILING flag RT #124964'
{
macro hi () { quasi :COMPILING { "hello $s" } }
macro hey () { ({ "hello $^s" }.body) }
my $s="world";
is(hi(),"hello world","macros can bind in caller's lexical env");
$s="paradise";
is(hi(),"hello paradise","macros but it's a binding only");
is(hey(),"hello paradise","macros but it's a binding only");
}
{
my $x;
macro noop () { $x = "Nothing happened"; quasi { } }
noop();
is($x,"Nothing happened", "Macros can return noops");
}
{
macro hygienic ($ast) {
my $x = 3;
quasi { $x + {{{ $ast }}} }
}
my $x = 4;
is hygienic($x), 7, 'lexical vars in macros are not visible to the AST vars';
}
#?rakudo skip 'return from macro RT #124965'
{
macro outside-declaration ( $ast ) {
my $COMPILING::x = 4;
return quasi { {{{ $ast }}} }
}
is outside-declaration( { $x * 2 } ), 8,
'A macro can declare lexicals that are visible where called';
}
# vim: ft=perl6