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 75 lines (60 sloc) 1.867 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 64 65 66 67 68 69 70 71 72 73 74
use v6;

use Test;

plan 2;

# TODO, based on synopsis 4:
#
# * KEEP, UNDO, PRE, POST, CONTROL
# CATCH is tested in t/spec/S04-statements/try.t
# and t/spec/S04-exception-handlers/catch.t
#
# * $var will undo, etc
#
# * LEAVE type blocks in the context of CATCH
#
# * PRE/POST in classes is not the same as LEAVE/ENTER

# L<S04/"Phasers">

{
    my $str;

    for 1..10 -> $i {
        last if $i > 3;
        $str ~= "($i a)";
        next if $i % 2 == 1;
        $str ~= "($i b)";
        LAST { $str ~= "($i Lst)" }
        LEAVE { $str ~= "($i Lv)" }
        NEXT { $str ~= "($i N)" }
        FIRST { $str ~= "($i F)" }
        ENTER { $str ~= "($i E)" }
    }

    is $str, "(1 F)(1 E)(1 a)" ~ "(1 N)(1 Lv)" ~
                  "(2 E)(2 a)(2 b)(2 N)(2 Lv)" ~
                  "(3 E)(3 a)" ~ "(3 N)(3 Lv)" ~
                  "(4 E)" ~ "(4 Lv)(4 Lst)",
       'trait blocks work properly in for loop';
}

{
    my $str;

    for 1..10 -> $i {
        last if $i > 3;
        $str ~= "($i a)";

        ENTER { $str ~= "($i E1)" }
        LAST { $str ~= "($i Lst1)" }
        FIRST { $str ~= "($i F1)" }
        LEAVE { $str ~= "($i Lv1)" }

        next if $i % 2 == 1;
        $str ~= "($i b)";

        LAST { $str ~= "($i Lst2)" }
        NEXT { $str ~= "($i N1)" }
        FIRST { $str ~= "($i F2)" }
        LEAVE { $str ~= "($i Lv2)" }
        ENTER { $str ~= "($i E2)" }
        NEXT { $str ~= "($i N2)" }
    }

    is $str,
"(1 F1)(1 F2)(1 E1)(1 E2)(1 a)" ~ "(1 N2)(1 N1)" ~ "(1 Lv2)(1 Lv1)" ~
            "(2 E1)(2 E2)(2 a)(2 b)(2 N2)(2 N1)" ~ "(2 Lv2)(2 Lv1)" ~
            "(3 E1)(3 E2)(3 a)" ~ "(3 N2)(3 N1)" ~ "(3 Lv2)(3 Lv1)" ~
            "(4 E1)(4 E2)" ~ "(4 Lv2)(4 Lv1)" ~ "(4 Lst2)(4 Lst1)",
       'trait blocks work properly in for loop';
}

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