endtoend-test-psl/tests/Psl/Str/Byte/SpliceTest.php
2020-01-02 00:00:08 +01:00

35 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class SpliceTest extends TestCase
{
/**
* @dataProvider provideData
*/
public function testSplice(string $expected, string $string, string $replacement, int $offset, ?int $length = null): void
{
self::assertSame($expected, Byte\splice($string, $replacement, $offset, $length));
}
public function provideData(): array
{
return [
['', '', '', 0, null, ],
['hello darkness', 'hello world', 'darkness', 6, null, ],
['hello cruel world', 'hello world', ' cruel ', 5, 1],
['hello cruel world', 'hello world', ' cruel ', -6, 1, ],
['hello cruel world', 'hello world', ' cruel', 5, 0, ],
['hello darkness', 'hello ', 'darkness', 6, null, ],
['hello darkness', 'hello world', 'darkness', 6, 100, ],
['hello darkness', 'hello world', 'darkness', 6, 11, ],
['People linked by destiny will always find each other.', 'People linked by destiny will find each other.', ' always ', 29, 1],
];
}
}