mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-02 17:56:09 +01:00
56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Psl\Tests\Arr;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psl\Arr;
|
|
use Psl\Str;
|
|
|
|
final class PartitionTest extends TestCase
|
|
{
|
|
/**
|
|
* @dataProvider provideData
|
|
*/
|
|
public function testPartition(array $expected, array $array, callable $predicate): void
|
|
{
|
|
static::assertSame($expected, Arr\partition($array, $predicate));
|
|
}
|
|
|
|
public function provideData(): array
|
|
{
|
|
return [
|
|
[
|
|
[['bar', 'baz'], ['foo', 'qux']],
|
|
['foo', 'bar', 'baz', 'qux'],
|
|
static fn (string $str) => Str\starts_with($str, 'b'),
|
|
],
|
|
|
|
[
|
|
[['bar', 'baz'], ['foo', 'qux']],
|
|
['foo', 'bar', 'baz', 'qux'],
|
|
static fn (string $str) => Str\starts_with($str, 'b'),
|
|
],
|
|
|
|
[
|
|
[[], []],
|
|
[],
|
|
static fn ($_) => false,
|
|
],
|
|
|
|
[
|
|
[[], ['foo', 'bar', 'baz', 'qux']],
|
|
['foo', 'bar', 'baz', 'qux'],
|
|
static fn (string $str) => false,
|
|
],
|
|
|
|
[
|
|
[['foo', 'bar', 'baz', 'qux'], []],
|
|
['foo', 'bar', 'baz', 'qux'],
|
|
static fn (string $str) => true,
|
|
],
|
|
];
|
|
}
|
|
}
|