Skip to content

Commit

Permalink
Test that map() is lazy even with arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Oct 21, 2018
1 parent c7b561d commit d225a45
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/EagerWithArraysTest.php
Expand Up @@ -30,6 +30,12 @@
*/
class EagerWithArraysTest extends TestCase
{
public static function specimens(): \Generator
{
yield 'take' => [take([0, 0, 1, 2, 3])];
yield 'fromArray' => [fromArray([0, 0, 1, 2, 3])];
}

/**
* @dataProvider specimens
*/
Expand Down Expand Up @@ -72,9 +78,17 @@ public function testEagerArrayFilterAndReduce(Standard $pipeline)
$this->assertSame(6, $pipeline->filter()->reduce());
}

public static function specimens(): \Generator
/**
* @dataProvider specimens
*/
public function testNonEagerArrayMap(Standard $pipeline)
{
yield 'take' => [take([0, 0, 1, 2, 3])];
yield 'fromArray' => [fromArray([0, 0, 1, 2, 3])];
$this->assertSame([1, 1, 1, 1, 1], $pipeline->map(function ($value) {
return 1;
})->toArray());

// This should not be possible even with an array, as map() is always lazy
$this->expectExceptionMessage('Cannot traverse an already closed generator');
$pipeline->toArray();
}
}

0 comments on commit d225a45

Please sign in to comment.