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

38 lines
939 B
PHP
Raw Normal View History

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 TruncateTest extends TestCase
{
2019-12-26 23:10:57 +01:00
/**
* @dataProvider provideData
*/
public function testTruncate(
string $expected,
string $str,
int $offset,
int $width,
?string $trim_marker = null
): void {
2019-12-26 23:10:57 +01:00
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, '...'],
];
}
2019-12-24 01:52:07 +01:00
}