Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
GLRify tests using an assortment of valid GLR idioms
  • Loading branch information
skids committed Aug 26, 2015
1 parent c7bf5f5 commit b59c475
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions S04-statements/gather.t
Expand Up @@ -8,15 +8,14 @@ plan 33;

# Standard gather
{
my @a;
my $i;

@a := gather {
my @a := gather {
$i = 1;
for (1 .. 5) -> $j {
take $j;
}
};
}.values;

ok(!$i, "not yet gathered");
is(+@a, 5, "5 elements gathered");
Expand Down Expand Up @@ -106,7 +105,7 @@ plan 33;
take $a;
$count++
}
};
}.List;
my $result = @list[2];
is($count, 2, "gather is lazy");
}
Expand All @@ -123,13 +122,13 @@ plan 33;
}

{
my @list = gather {
my \list := gather {
loop (my $v = 1; $v <= 10; $v++)
{
take $v if $v % 2 == 0;
}
};
is ~@list, "2 4 6 8 10", "gather with nested loop";
is ~list, "2 4 6 8 10", "gather with nested loop";
}

{
Expand All @@ -148,8 +147,8 @@ plan 33;
}
}

my @evens := grep-div((1...*), 2);
is ~grep-div(@evens, 3)[^16], ~grep-div((1...100), 6), "Nested identical gathers";
my \evens = grep-div((1...*), 2);
is ~grep-div(evens, 3)[^16], ~grep-div((1...100), 6), "Nested identical gathers";
}

# RT #77036
Expand Down Expand Up @@ -225,6 +224,8 @@ plan 33;
}

#?niecza skip 'Cannot use bind operator with this LHS'
# XXX GLR
#?rakudo skip 'LoL is dead, long live LoL'
{
my ($c) := \(gather for 1..2 {
take $_, $_ * 10;
Expand All @@ -234,18 +235,19 @@ plan 33;
is $c.item, ($(1,10),$(2,20)).list.item, "a list of Parcels, as an item.";
}

#?rakudo todo 'RT #66820'
# XXX GLR
#?rakudo skip 'RT #66820, and hangs under GLR'
{
my $cat;
lives-ok { my @a := gather for 1..3 { take $_; $cat ~= ~@a }; +@a }, 'can access bound gather result while gathering';
lives-ok { my @a := gather for 1..3 { take $_; $cat ~= ~@a }.list; +@a }, 'can access bound gather result while gathering';
is $cat, "11 21 2 3", 'bound gather result has up-to-date value while gathering';
}

# RT #111962
{
my @grid = [ Bool.pick xx 5 ] xx 5;
my @neigh = [ ] xx 5;
for ^5 X ^5 -> $i, $j {
for ^5 X ^5 -> ($i, $j) {
@neigh[$i][$j] = gather take-rw @grid[$i + .[0]][$j + .[1]]
if 0 <= $i + .[0] < 5 and 0 <= $j + .[1] < 5
for [-1,-1],[+0,-1],[+1,-1],
Expand Down

0 comments on commit b59c475

Please sign in to comment.