-
Notifications
You must be signed in to change notification settings - Fork 135
/
will.t
124 lines (110 loc) · 3.58 KB
/
will.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use v6;
use Test;
BEGIN plan 20;
# L<S04/Phasers>
my $begin;
{
BEGIN $begin ~= "a";
my $b will begin { $begin ~= "b" };
BEGIN $begin ~= "c";
CHECK $begin ~= "f";
my $bb will check { $begin ~= "e" };
CHECK $begin ~= "d";
is $begin, "abcdef", 'all begin/check blocks in order';
}
my $init;
{
#?rakudo todo 'will init NYI'
is $init, "abc", 'all init blocks in order';
BEGIN $init ~= "a";
INIT $init ~= "b";
my $bbb will init { $init ~= "c" };
}
my $same1;
#?rakudo skip 'declared variable not visible in block yet RT #125061'
{
my $x will begin { $same1 ~= "a" if $_ === $x }
my $xx will check { $same1 ~= "b" if $_ === $xx }
my $xxx will init { $same1 ~= "c" if $_ === $xxx }
is $same1, "abc", 'all blocks set $_';
}
my $block;
{
my $d will pre { $block ~= "a" };
my $dd will enter { $block ~= "b" };
is $block, "ab", 'entered block ok';
my $e will leave { $block ~= "c" };
my $ee will post { $block ~= "d" };
my $eee will keep { $block ~= "e" };
my $eeee will undo { $block ~= "f" }; # should not fire
1; # successful exit
}
#?rakudo todo "will post NYI RT #125062"
is $block, "abecd", 'all block blocks set variable';
my $same2;
#?rakudo skip 'declared variable not visible in block yet RT #125063'
{
my $d will pre { $same2 ~= "a" if $_ === $d; 1 };
my $dd will enter { $same2 ~= "b" if $_ === $dd };
is $same2, "ab", 'entered block ok';
my $e will leave { $same2 ~= "c" if $_ === $e };
my $ee will post { $same2 ~= "d" if $_ === $ee; 1 };
my $eee will keep { $same2 ~= "e" if $_ === $eee };
my $eeee will undo { $same2 ~= "f" if $_ === $eeee }; # should not fire
1; # successful exit
}
#?rakudo todo 'declared variable not visible in block yet RT #125064'
is $same2, "abecd", 'all block blocks get $_';
my $for;
{
my @is = <a aeb aebeb>;
for ^3 {
my $g will first { $for ~= "a" };
my $h will next { $for ~= "b" };
my $i will last { $for ~= "c" };
is( $for, @is[$_], "for iteration #{$_+1}" );
my $ii will keep { $for ~= "d" }; # should not fire
my $iii will undo { $for ~= "e" };
Nil; # failure exit
}
}
is $for, "aebebebc", 'all for blocks set variable';
my $same3;
#?rakudo skip 'declared variable not visible in block yet RT #125066'
{
my @is = <a aeb aebeb>;
for ^3 {
my $j will first { $same3 ~= "a" if $_ === $j; 1 };
my $k will next { $same3 ~= "b" if $_ === $k; 1 };
my $l will last { $same3 ~= "c" if $_ === $l; 1 };
is( $same3, @is[$_], "same iteration #{$_+1}" );
my $ll will keep { $same2 ~= "d" if $_ === $ll }; # should not fire
my $lll will undo { $same2 ~= "e" if $_ === $lll };
Nil; # failure exit
}
}
#?rakudo todo 'declared variable not visible in block yet RT #125067'
is $same3, "aebebebc", 'all for blocks get $_';
{
my $seen = 42;
dies-ok {EVAL 'my $a will foo { $seen = 1 }'}, 'unknown will trait';
is $seen, 42, 'block should not have executed';
lives-ok {my $a will compose { $seen = 1 }}, "don't know how to test yet";
is $seen, 42, 'block should not have executed';
}
# RT #125455
{
my $did-we-leave = 0;
class A {
my $boo will leave { $did-we-leave = 1 };
is $did-we-leave, 0, 'will leave trait on class-scoped my variable not run yet';
}
is $did-we-leave, 1, 'will leave trait on class-scoped my variable ran';
}
# RT #119109
{
my $what;
my @a will begin { $what = $_.WHAT.perl; };
is $what, 'Array', 'will begin block gets var as topic';
}
# vim: ft=perl6