Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add more tests for labels
  • Loading branch information
FROGGS committed May 21, 2014
1 parent b1be572 commit 3ef752a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
69 changes: 69 additions & 0 deletions S04-statements/label.t
@@ -0,0 +1,69 @@
use v6;

use Test;
# L<S04/"Loop statements"/"next, last, and redo">
plan 4;

{
my $x = 0;
my $y = 0;
my $t = '';
A: while $x++ < 2 {
$t ~= "A$x";
B: while $y++ < 2 {
$t ~= "B$y";
redo A if $y++ == 1;
last A
}
}
is $t, 'A1B1A1A2', 'labeled while loops with redo and last'
}

{
my $i = 0;
my $t = '';
A: for "A" {
$t ~= $_;
B: for "B" {
$t ~= $_;
redo A unless $i++
}
}
is($t, 'ABAB', 'redoing outer for loop');
}

{
my $i = 0;
my $t = '';
A: for "A1", "A2" {
$t ~= $_;
B: for "B" {
$t ~= $_;
C: for "C" {
$t ~= $_;
redo B unless $i++
}
}
}
is($t, 'A1BCBCA2BC', 'redoing outer for loop');
}

{
my $i = 0;
my $t = '';
A: for "A1", "A2" {
$t ~= $_;
B: for "B" {
$t ~= $_;
C: for "C" {
$t ~= $_;
D: while "D" {
$t ~= 'D';
redo B unless $i++;
last
}
}
}
}
is($t, 'A1BCDBCDA2BCD', 'redoing outer for loop');
}
16 changes: 15 additions & 1 deletion S04-statements/redo.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;
# L<S04/"Loop statements"/redo>
plan 11;
plan 12;

{
my $i = 0;
Expand Down Expand Up @@ -113,4 +113,18 @@ plan 11;
eval_dies_ok '{redo}', 'redo without loop construct dies';
}

{
my $x;
my $out = '';
FOO: for "foo" {
$out ~= $_;
BAR: for "bar" {
$out ~= $_;
redo FOO unless $x++
}
}

is $out, 'foobarfoobar', 'redoing outer for loop';
}

# vim: ft=perl6

0 comments on commit 3ef752a

Please sign in to comment.