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
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class ContainsTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2020-07-16 17:11:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-template T
|
|
|
|
*
|
|
|
|
* @psalm-param iterable<T> $iterable
|
|
|
|
* @psalm-param T $value
|
|
|
|
*
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testContainsKey(bool $expected, iterable $iterable, $value): void
|
|
|
|
{
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame($expected, Iter\contains($iterable, $value));
|
2020-07-16 17:11:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): iterable
|
|
|
|
{
|
|
|
|
yield [false, [], 0];
|
|
|
|
yield [false, [], 1];
|
|
|
|
yield [false, [], null];
|
|
|
|
yield [false, [0], null];
|
|
|
|
yield [true, [null], null];
|
|
|
|
yield [false, [1, 2], 0];
|
|
|
|
yield [true, [1, 2], 1];
|
|
|
|
yield [true, [1, 2], 2];
|
|
|
|
yield [false, ['hello' => 'world'], 'hello'];
|
|
|
|
yield [true, ['hello' => 'world'], 'world'];
|
|
|
|
yield [false, ['hello' => 'world'], 'worlD'];
|
|
|
|
yield [true, [null => null], null];
|
|
|
|
yield [false, new Collection\Vector([1, 2]), 0];
|
|
|
|
yield [true, new Collection\Vector([1, 2]), 1];
|
|
|
|
yield [true, new Collection\Vector([1, 2]), 2];
|
2020-10-15 10:18:03 +02:00
|
|
|
yield [false, (static fn () => yield 'foo' => 'bar')(), 'foo'];
|
|
|
|
yield [true, (static fn () => yield 'foo' => 'bar')(), 'bar'];
|
2020-07-16 17:11:54 +02:00
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|