2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Iter;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-07-16 17:11:54 +02:00
|
|
|
use Psl\Iter;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class EnumerateTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2020-07-16 17:11:54 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testEnumerate(array $expected, iterable $iterable): void
|
|
|
|
{
|
|
|
|
$result = Iter\enumerate($iterable);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame($expected, Iter\to_array_with_keys($result));
|
2020-07-16 17:11:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): iterable
|
|
|
|
{
|
|
|
|
yield [[], []];
|
|
|
|
yield [[['a', 'b'], ['c', 'd']], ['a' => 'b', 'c' => 'd']];
|
|
|
|
yield [[['a', 'b'], ['a', 'b'], ['a', 'b']], (static function () {
|
|
|
|
yield 'a' => 'b';
|
|
|
|
yield 'a' => 'b';
|
|
|
|
yield 'a' => 'b';
|
|
|
|
})()];
|
|
|
|
yield [[['a', null], ['b', 0]], ['a' => null, 'b' => 0]];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|