Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 69 lines (57 sloc) 1.122 kB
ba90e17 Tests for while and until loops
duff authored
1 use v6-alpha;
2
3 use Test;
4
5 plan 10;
6
7 {
983f107 [rakudo] while/until statements now parse
particle authored
8 my $i = 0;
9 while $i < 5 { $i++; };
10 is($i, 5, 'while $i < 5 {} works');
ba90e17 Tests for while and until loops
duff authored
11 }
983f107 [rakudo] while/until statements now parse
particle authored
12
ba90e17 Tests for while and until loops
duff authored
13 {
983f107 [rakudo] while/until statements now parse
particle authored
14 my $i = 0;
15 while 5 > $i { $i++; };
16 is($i, 5, 'while 5 > $i {} works');
ba90e17 Tests for while and until loops
duff authored
17 }
983f107 [rakudo] while/until statements now parse
particle authored
18
ba90e17 Tests for while and until loops
duff authored
19 # with parens
20 {
983f107 [rakudo] while/until statements now parse
particle authored
21 my $i = 0;
22 while ($i < 5) { $i++; };
23 is($i, 5, 'while ($i < 5) {} works');
ba90e17 Tests for while and until loops
duff authored
24 }
983f107 [rakudo] while/until statements now parse
particle authored
25
ba90e17 Tests for while and until loops
duff authored
26 {
983f107 [rakudo] while/until statements now parse
particle authored
27 my $i = 0;
28 while (5 > $i) { $i++; };
29 is($i, 5, 'while (5 > $i) {} works');
ba90e17 Tests for while and until loops
duff authored
30 }
31
32 # single value
33 {
983f107 [rakudo] while/until statements now parse
particle authored
34 my $j = 0;
35 while 0 { $j++; };
36 is($j, 0, 'while 0 {...} works');
ba90e17 Tests for while and until loops
duff authored
37 }
983f107 [rakudo] while/until statements now parse
particle authored
38
ba90e17 Tests for while and until loops
duff authored
39 {
983f107 [rakudo] while/until statements now parse
particle authored
40 my $k = 0;
41 while $k { $k++; };
42 is($k, 0, 'while $var {...} works');
ba90e17 Tests for while and until loops
duff authored
43 }
44
983f107 [rakudo] while/until statements now parse
particle authored
45
f60ff61 [fudge] more sub counting tweaks
lwall authored
46 #?rakudo skip 'No pointy blocks on while loops yet'
ba90e17 Tests for while and until loops
duff authored
47 # L<S04/The C<for> statement/It is also possible to write>
48 # while ... -> $x {...}
49 {
50 my @array = 1..5;
51 my $str;
52 while @array.pop -> $x {
53 $str ~= $x;
54 }
55 is $!, undef, 'eval worked';
56 is $str, '54321', 'while ... -> $x {...} worked (1)';
57 }
58
f60ff61 [fudge] more sub counting tweaks
lwall authored
59 #?rakudo skip 'No pointy blocks on while loops yet'
ba90e17 Tests for while and until loops
duff authored
60 {
61 my @array = 0..5;
62 my $str;
63 while pop @array -> $x {
64 $str ~= $x;
65 }
a2ddaeb more "fudge normal form"
lwall authored
66 is $!, undef, 'eval worked';
ba90e17 Tests for while and until loops
duff authored
67 is $str, '54321', 'while ... -> $x {...} worked (2)';
68 }
Something went wrong with that request. Please try again.