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\Iter;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class FromKeysTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2020-08-08 06:35:34 +02:00
|
|
|
public function testFromKeys(): void
|
|
|
|
{
|
2020-10-15 10:18:03 +02:00
|
|
|
$actual = Iter\from_keys(['hello', 'world'], static fn (string $_key) => false);
|
2020-08-08 06:35:34 +02:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame('hello', Iter\first_key($actual));
|
|
|
|
static::assertSame('world', Iter\last_key($actual));
|
|
|
|
static::assertFalse(Iter\first($actual));
|
|
|
|
static::assertFalse(Iter\last($actual));
|
2020-08-08 06:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFromKeysWithNonArrayKeyKeys(): void
|
|
|
|
{
|
|
|
|
$actual = Iter\from_keys([
|
|
|
|
[1, 'hello'],
|
|
|
|
[2, 'world']
|
2020-10-15 10:18:03 +02:00
|
|
|
], static fn (array $k) => $k[1]);
|
2020-08-08 06:35:34 +02:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame([1, 'hello'], Iter\first_key($actual));
|
|
|
|
static::assertSame([2, 'world'], Iter\last_key($actual));
|
|
|
|
static::assertSame('hello', Iter\first($actual));
|
|
|
|
static::assertSame('world', Iter\last($actual));
|
2020-08-08 06:35:34 +02:00
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|