-
Notifications
You must be signed in to change notification settings - Fork 135
/
first.t
47 lines (40 loc) · 888 Bytes
/
first.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
use v6;
use Test;
plan 4;
# L<S04/Closure traits/FIRST "at loop initialization time">
{
my $str = '';
for 1..2 {
FIRST { $str ~= $_ }
}
is $str, 1, 'FIRST only ran once';
}
{
my ($a, $a_in_first);
for 1..2 {
$a++;
FIRST { $a_in_first = $a }
}
is $a_in_first, undef, 'FIRST {} ran before the loop body';
}
# L<S04/Closure traits/can occur multiple times>
{
my $str = '';
for 1..2 {
FIRST { $str ~= $_ }
FIRST { $str ~= ':' }
FIRST { $str ~= ' ' }
}
is $str, '1: ', 'multiple FIRST {} ran in order';
}
# L<S04/Closure traits/FIRST "at loop initialization time" "before any ENTER">
{
my $str = '';
for 1..2 {
FIRST { $str ~= 'f1' }
ENTER { $str ~= 'e' }
FIRST { $str ~= 'f2' }
}
is $str, 'f1f2ee', 'FIRST {} ran before ENTER {}';
}
# vim: ft=perl6