<commit_before>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 10;

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');

ok("abc" ~~ m/a(bc){$0 = uc $0}/, 'Numeric match');
is($/, "abc", 'Numeric matched');
is($0, "BC", 'Numeric caught');

ok("abc" ~~ m/a(bc){make uc $0}/ , 'Zero match');
is($($/), "BC", 'Zero matched');
is(~$0, "bc", 'One matched');

# vim: ft=perl6<commit_msg>[t/spec] enhance S05-metachars/closure.t, and fudge for rakudo<commit_after>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
{'fraction_non_alphanumeric': 0.21561712846347608, 'fraction_numerical': 0.027204030226700253, 'mean_word_length': 3.9526184538653366, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4296769', 'n_tokens_mistral': 832, 'n_tokens_neox': 802, 'n_words': 248}