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 SearchTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2020-09-01 07:50:23 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
2020-09-01 07:56:15 +02:00
|
|
|
public function testSearch($expected, iterable $iterable, callable $predicate): void
|
2020-09-01 07:50:23 +02:00
|
|
|
{
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame($expected, Iter\search($iterable, $predicate));
|
2020-09-01 07:50:23 +02:00
|
|
|
}
|
|
|
|
|
2020-09-01 07:56:15 +02:00
|
|
|
public function provideData(): iterable
|
2020-09-01 07:50:23 +02:00
|
|
|
{
|
2020-10-15 10:18:03 +02:00
|
|
|
yield ['baz', ['foo', 'bar', 'baz'], static fn (string $v): bool => 'baz' === $v];
|
|
|
|
yield [null, ['foo', 'bar', 'baz'], static fn (string $v): bool => 'qux' === $v];
|
|
|
|
yield [null, [], static fn (string $v): bool => 'qux' === $v];
|
2020-09-01 07:50:23 +02:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
yield ['baz', Iter\to_iterator(['foo', 'bar', 'baz']), static fn (string $v): bool => 'baz' === $v];
|
|
|
|
yield [null, Iter\to_iterator(['foo', 'bar', 'baz']), static fn (string $v): bool => 'qux' === $v];
|
|
|
|
yield [null, Iter\to_iterator([]), static fn (string $v): bool => 'qux' === $v];
|
2020-09-01 07:50:23 +02:00
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|