mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-02 17:56:09 +01:00
31 lines
942 B
PHP
31 lines
942 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Psl\Tests\Iter;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psl\Iter;
|
|
|
|
class SearchTest extends TestCase
|
|
{
|
|
/**
|
|
* @dataProvider provideData
|
|
*/
|
|
public function testSearch($expected, iterable $iterable, callable $predicate): void
|
|
{
|
|
self::assertSame($expected, Iter\search($iterable, $predicate));
|
|
}
|
|
|
|
public function provideData(): iterable
|
|
{
|
|
yield ['baz', ['foo', 'bar', 'baz'], fn (string $v): bool => 'baz' === $v];
|
|
yield [null, ['foo', 'bar', 'baz'], fn (string $v): bool => 'qux' === $v];
|
|
yield [null, [], fn (string $v): bool => 'qux' === $v];
|
|
|
|
yield ['baz', Iter\to_iterator(['foo', 'bar', 'baz']), fn (string $v): bool => 'baz' === $v];
|
|
yield [null, Iter\to_iterator(['foo', 'bar', 'baz']), fn (string $v): bool => 'qux' === $v];
|
|
yield [null, Iter\to_iterator([]), fn (string $v): bool => 'qux' === $v];
|
|
}
|
|
}
|