endtoend-test-psl/tests/Psl/Str/TruncateTest.php

38 lines
939 B
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class TruncateTest extends TestCase
{
/**
* @dataProvider provideData
*/
public function testTruncate(
string $expected,
string $str,
int $offset,
int $width,
?string $trim_marker = null
): void {
self::assertSame($expected, Str\truncate($str, $offset, $width, $trim_marker));
}
public function provideData(): array
{
return [
['Hello', 'Hello, World!', 0, 5],
['He...', 'Hello, World!', 0, 5, '...'],
['Hello...', 'Hello, World!', 0, 8, '...'],
['héllö...', 'héllö, wôrld!', 0, 8, '...'],
['wôrld!', 'héllö, wôrld!', 7, 8, '...'],
['مرحبا...', 'مرحبا بكم', 0, 8, '...'],
['سيف', 'مرحبا سيف', 6, 8, '...'],
];
}
}