Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 72 lines (59 sloc) 1.11 kb
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
ba90e17 Tests for while and until loops
duff authored
2
3 use Test;
4
abbd86a [t/spec] Added test for required whitespace after a built-in statemen…
azawawi authored
5 plan 9;
ba90e17 Tests for while and until loops
duff authored
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
ba90e17 Tests for while and until loops
duff authored
46 # L<S04/The C<for> statement/It is also possible to write>
47 # while ... -> $x {...}
48 {
49 my @array = 1..5;
50 my $str;
51 while @array.pop -> $x {
52 $str ~= $x;
53 }
54 is $str, '54321', 'while ... -> $x {...} worked (1)';
55 }
56
57 {
58 my @array = 0..5;
59 my $str;
60 while pop @array -> $x {
61 $str ~= $x;
62 }
63 is $str, '54321', 'while ... -> $x {...} worked (2)';
64 }
abbd86a [t/spec] Added test for required whitespace after a built-in statemen…
azawawi authored
65
66 #L<S04/"keywords require whitespace">
67 {
68 my $i = 0;
69 eval_dies_ok('while($i < 5) { $i++; }',
70 'keyword needs at least one whitespace after it');
71 }
Something went wrong with that request. Please try again.