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 54 lines (40 sloc) 1.225 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
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)'
#?niecza skip 'assigning to readonly value'
{
    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)'
#?niecza skip 'assigning to readonly value'
{
    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');
    #?niecza todo
    is($($/), "BC", 'Zero matched');
    is(~$0, "bc", 'One matched');
}

# vim: ft=perl6
Something went wrong with that request. Please try again.