2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Str;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-12-26 23:10:57 +01:00
|
|
|
use Psl\Str;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
|
|
|
class SplitTest extends TestCase
|
|
|
|
{
|
2019-12-26 23:10:57 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testSplit(array $expected, string $string, string $delimiter, ?int $length = null): void
|
|
|
|
{
|
|
|
|
self::assertSame($expected, Str\split($string, $delimiter, $length));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[[], '', '', 1],
|
|
|
|
[['Hello, World!'], 'Hello, World!', ' ', 1],
|
|
|
|
[['Hello,', 'World!'], 'Hello, World!', ' ', 2],
|
|
|
|
[['مرحبا', 'سيف', ], 'مرحبا سيف', ' ', 3],
|
|
|
|
[['اهلا', 'بكم'], 'اهلا بكم', ' ', 2],
|
|
|
|
[['اهلا بكم'], 'اهلا بكم', '', 1],
|
|
|
|
[['اهلا', 'بكم'], 'اهلا بكم', ' ', null],
|
|
|
|
[['اهلا', 'بكم'], 'اهلا بكم', ' ', 100],
|
|
|
|
[['h', 'é', 'l', 'l', 'ö', ' ', 'w', 'ôrld'], 'héllö wôrld', '', 8, ],
|
|
|
|
[['h', 'é', 'l', 'l', 'ö', ' ', 'w', 'ô', 'r', 'l', 'd'], 'héllö wôrld', ''],
|
|
|
|
[['fôo'], 'fôo', 'bar', null],
|
|
|
|
[['héll', ' w', 'rld'], 'héllô wôrld', 'ô', 3, ],
|
|
|
|
[['héllö w', 'rld'], 'héllö wôrld', 'ô', 3, ],
|
|
|
|
];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|