Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (56 sloc) 1.077 kb
ba90e175 »
2008-01-03 Tests for while and until loops
1 use v6-alpha;
2
3 use Test;
4
5 plan 10;
6
7 {
8 my $i = 0;
9 while $i < 5 { $i++; };
10 is($i, 5, 'while $i < 5 {} works');
11 }
12 {
13 my $i = 0;
14 while 5 > $i { $i++; };
15 is($i, 5, 'while 5 > $i {} works');
16 }
17 # with parens
18 {
19 my $i = 0;
20 while ($i < 5) { $i++; };
21 is($i, 5, 'while ($i < 5) {} works');
22 }
23 {
24 my $i = 0;
25 while (5 > $i) { $i++; };
26 is($i, 5, 'while (5 > $i) {} works');
27 }
28
29 # single value
30 {
31 my $j = 0;
32 while 0 { $j++; };
33 is($j, 0, 'while 0 {...} works');
34 }
35 {
36 my $k = 0;
37 while $k { $k++; };
38 is($k, 0, 'while $var {...} works');
39 }
40
41 #?perl6 todo('No pointy blocks on while loops yet', 2);
42 # L<S04/The C<for> statement/It is also possible to write>
43 # while ... -> $x {...}
44 {
45 my @array = 1..5;
46 my $str;
47 while @array.pop -> $x {
48 $str ~= $x;
49 }
50 is $!, undef, 'eval worked';
51 is $str, '54321', 'while ... -> $x {...} worked (1)';
52 }
53
54 {
55 my @array = 0..5;
56 my $str;
57 while pop @array -> $x {
58 $str ~= $x;
59 }
60 is $!, undef, 'eval worked', :todo('pointy blocks not implemented yet');
61 is $str, '54321', 'while ... -> $x {...} worked (2)';
62 }
Something went wrong with that request. Please try again.