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\Iter;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class KeysTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2020-09-01 07:50:23 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testKeys(array $expected, iterable $iterable): void
|
|
|
|
{
|
|
|
|
$result = Iter\keys($iterable);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame($expected, Iter\to_array_with_keys($result));
|
2020-09-01 07:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): iterable
|
|
|
|
{
|
|
|
|
yield [[0, 1, 2, 3], [1, 2, 3, 4]];
|
|
|
|
yield [[0, 1, 2, 3], Iter\to_iterator([1, 2, 3, 4])];
|
|
|
|
yield [[0, 1, 2, 3], Iter\range(1, 4)];
|
|
|
|
yield [[0, 1, 2, 3, 4], Iter\range(4, 8)];
|
|
|
|
yield [[], []];
|
|
|
|
yield [[0], [null]];
|
|
|
|
yield [[0, 1], [null, null]];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|