endtoend-test-psl/tests/Psl/Str/Byte/SpliceTest.php

46 lines
1.3 KiB
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
2019-12-26 23:10:57 +01:00
use Psl\Str\Byte;
2019-12-24 01:52:07 +01:00
class SpliceTest extends TestCase
{
2019-12-26 23:10:57 +01:00
/**
* @dataProvider provideData
*/
public function testSplice(
string $expected,
string $string,
string $replacement,
int $offset,
?int $length = null
): void {
2019-12-26 23:10:57 +01:00
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
],
2019-12-26 23:10:57 +01:00
];
}
2019-12-24 01:52:07 +01:00
}