2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Iter;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-08-08 06:35:34 +02:00
|
|
|
use Psl\Collection;
|
|
|
|
use Psl\Iter;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
|
|
|
class FirstTest extends TestCase
|
|
|
|
{
|
2020-08-08 06:35:34 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
2020-09-01 07:50:23 +02:00
|
|
|
public function testFirst($expected, iterable $iterable): void
|
2020-08-08 06:35:34 +02:00
|
|
|
{
|
|
|
|
$result = Iter\first($iterable);
|
|
|
|
|
|
|
|
self::assertSame($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): iterable
|
|
|
|
{
|
|
|
|
yield [null, []];
|
|
|
|
yield [null, new \SplDoublyLinkedList()];
|
2020-09-01 07:50:23 +02:00
|
|
|
yield ['b', ['a' => 'b', 'c' => 'd']];
|
2020-08-08 06:35:34 +02:00
|
|
|
yield ['a', ['a', 'b']];
|
|
|
|
yield ['a', new Collection\Vector(['a', 'b'])];
|
2020-09-01 07:50:23 +02:00
|
|
|
yield ['b', new Collection\Vector(['b'])];
|
|
|
|
yield ['b', new Collection\Map(['a' => 'b', 'c' => 'd'])];
|
2020-08-08 06:35:34 +02:00
|
|
|
yield [null, (static function () {
|
|
|
|
yield null => null;
|
|
|
|
})()];
|
|
|
|
yield [null, (static function () {
|
|
|
|
return;
|
|
|
|
yield;
|
|
|
|
})()];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|