Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 64 lines (45 sloc) 1.241 kb
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
use v6;

use Test;

=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'
{
    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'
{
    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
Something went wrong with that request. Please try again.