endtoend-test-psl/tests/Psl/Iter/LastTest.php

42 lines
983 B
PHP
Raw Normal View History

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