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

45 lines
1.2 KiB
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-07-16 17:11:54 +02:00
use Psl\Collection;
use Psl\Iter;
2019-12-24 01:52:07 +01:00
final class ContainsKeyTest extends TestCase
2019-12-24 01:52:07 +01:00
{
2020-07-16 17:11:54 +02:00
/**
* @psalm-template Tk
* @psalm-template Tv
*
* @psalm-param iterable<Tk, Tv> $iterable
* @psalm-param Tk $key
*
* @dataProvider provideData
*/
public function testContainsKey(bool $expected, iterable $iterable, $key): void
{
static::assertSame($expected, Iter\contains_key($iterable, $key));
2020-07-16 17:11:54 +02:00
}
public function provideData(): iterable
{
yield [false, [], 0];
yield [false, [], 1];
yield [true, [1, 2], 0];
yield [true, [1, 2], 1];
yield [false, [1, 2], 2];
yield [true, ['hello' => 'world'], 'hello'];
yield [false, ['hello' => 'world'], 'hellO'];
yield [false, ['hello' => 'world'], 'world'];
yield [false, [null => null], null];
yield [true, new Collection\Vector([1, 2]), 0];
yield [true, new Collection\Vector([1, 2]), 1];
yield [false, new Collection\Vector([1, 2]), 2];
yield [true, (static fn () => yield 'foo' => 'bar')(), 'foo'];
yield [false, (static fn () => yield 'foo' => 'bar')(), 'bar'];
2020-07-16 17:11:54 +02:00
}
2019-12-24 01:52:07 +01:00
}