[Str] add tests

This commit is contained in:
Saif Eddin G 2020-01-02 00:03:14 +01:00 committed by GitHub
commit d10c400985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
118 changed files with 2375 additions and 220 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
/vendor/
.composer.lock
composer.lock
.php_cs.cache
.phpunit.result.cache

View File

@ -25,6 +25,9 @@
<testsuite name="Psl Random">
<directory>tests/Psl/Random</directory>
</testsuite>
<testsuite name="Psl Str">
<directory>tests/Psl/Str</directory>
</testsuite>
</testsuites>
<logging>
@ -42,4 +45,4 @@
</exclude>
</whitelist>
</filter>
</phpunit>
</phpunit>

View File

@ -16,10 +16,14 @@ use Psl;
* will be one character in length.
* If the $chunk_size length exceeds the length of string, the entire string is returned
* as the first (and only) array element.
* If the given string is empty, and empty array will be returned.
*/
function chunk(string $string, int $chunk_size = 1): array
{
Psl\invariant($chunk_size >= 1, 'Expected positive chunk size.');
if ('' === $string) {
return [];
}
return \str_split($string, $chunk_size);
}

View File

@ -11,5 +11,11 @@ function ends_with(
string $string,
string $suffix
): bool {
return 0 === ($suffix_length = length($suffix)) || (length($string) >= $suffix_length && 0 === \substr_compare($string, $suffix, -$suffix_length, $suffix_length));
if (null === search($string, $suffix)) {
return false;
}
$suffix_length = length($suffix);
return slice($string, -$suffix_length) === $suffix;
}

View File

@ -7,9 +7,14 @@ namespace Psl\Str\Byte;
/**
* Returns whether the string ends with the given suffix (case-insensitive).
*/
function ends_with_ci(
string $string,
string $suffix
): bool {
return 0 === ($suffix_length = length($suffix)) || (length($string) >= $suffix_length && 0 === \substr_compare($string, $suffix, -$suffix_length, $suffix_length, true));
function ends_with_ci(string $string, string $suffix): bool
{
if (null === search_ci($string, $suffix)) {
return false;
}
$suffix_length = length($suffix);
return length($string) >= $suffix_length &&
0 === \substr_compare($string, $suffix, -$suffix_length, $suffix_length, true);
}

View File

@ -4,21 +4,20 @@ declare(strict_types=1);
namespace Psl\Str\Byte;
use Psl\Arr;
/**
* Returns the 'haystack' string with all occurrences of the keys of
* `$replacements` replaced by the corresponding values.
*
* @param array<string, string> $replacements
* @param iterable<string, string> $replacements
*/
function replace_every(
string $haystack,
array $replacements
): string {
return \str_replace(
Arr\keys($replacements),
Arr\values($replacements),
$haystack
);
function replace_every(string $haystack, iterable $replacements): string
{
$search = [];
$replace = [];
foreach ($replacements as $k => $v) {
$search[] = $k;
$replace[] = $v;
}
return \str_replace($search, $replace, $haystack);
}

View File

@ -9,12 +9,17 @@ use Psl\Arr;
/**
* Returns the 'haystack' string with all occurrences of the keys of
* `$replacements` replaced by the corresponding values (case-insensitive).
*
* @param iterble<string, string> $replacements
*/
function replace_every_ci(string $haystack, array $replacements): string
function replace_every_ci(string $haystack, iterable $replacements): string
{
return \str_ireplace(
Arr\keys($replacements),
Arr\values($replacements),
$haystack
);
$search = [];
$replace = [];
foreach ($replacements as $k => $v) {
$search[] = $k;
$replace[] = $v;
}
return \str_ireplace($search, $replace, $haystack);
}

View File

@ -19,5 +19,9 @@ function search(string $haystack, string $needle, int $offset = 0): ?int
{
$offset = Psl\Internal\validate_offset($offset, length($haystack));
if ('' === $needle) {
return null;
}
return false === ($pos = \strpos($haystack, $needle, $offset)) ? null : $pos;
}

View File

@ -19,5 +19,9 @@ function search_ci(string $haystack, string $needle, int $offset = 0): ?int
{
$offset = Psl\Internal\validate_offset($offset, length($haystack));
if ('' === $needle) {
return null;
}
return false === ($pos = \stripos($haystack, $needle, $offset)) ? null : $pos;
}

View File

@ -9,7 +9,7 @@ namespace Psl\Str\Byte;
*/
function shuffle(string $string): string
{
if (length($string) >= 1) {
if (length($string) < 1) {
return $string;
}

View File

@ -9,5 +9,9 @@ namespace Psl\Str\Byte;
*/
function starts_with(string $str, string $prefix): bool
{
if ('' === $prefix) {
return false;
}
return 0 === \strncmp($str, $prefix, length($prefix));
}

View File

@ -9,5 +9,9 @@ namespace Psl\Str\Byte;
*/
function starts_with_ci(string $str, string $prefix): bool
{
if ('' === $prefix) {
return false;
}
return 0 === \strncasecmp($str, $prefix, length($prefix));
}

View File

@ -14,8 +14,13 @@ namespace Psl\Str\Byte;
*/
function words(string $string, ?string $characters_list = null): array
{
/** @var array<int, string> $words */
$words = null === $characters_list ? \str_word_count($string, 2) : \str_word_count($string, 2, $characters_list);
if (null === $characters_list) {
/** @var array<int, string> $words */
$words = \str_word_count($string, 2);
} else {
/** @var array<int, string> $words */
$words = \str_word_count($string, 2, $characters_list);
}
return $words;
}

View File

@ -26,5 +26,9 @@ namespace Psl\Str;
*/
function capitalize(string $string): string
{
if ('' === $string) {
return '';
}
return concat(uppercase(slice($string, 0, 1)), slice($string, 1, length($string)));
}

View File

@ -12,13 +12,13 @@ namespace Psl\Str;
*
* Example:
*
* Str\capitalize('hello, world!')
* Str\capitalize_words('hello, world!')
* => Str('Hello, World!')
*
* Str\capitalize('Hello, world!')
* Str\capitalize_words('Hello, world!')
* => Str('Hello, World!')
*
* Str\capitalize('مرحبا بكم')
* Str\capitalize_words('مرحبا بكم')
* => Str('مرحبا بكم')
*/
function capitalize_words(string $string): string

View File

@ -6,5 +6,5 @@ namespace Psl\Str;
function encoding(string $str): string
{
return \mb_detect_encoding($str, mb_detect_order(), true) ?: 'UTF-8';
return \mb_detect_encoding($str, mb_detect_order() ?: 'UTF-8', true) ?: 'UTF-8';
}

View File

@ -34,13 +34,20 @@ function ends_with(
string $string,
string $suffix
): bool {
if (is_empty($suffix)) {
if ($suffix === $string) {
return true;
}
if (!\preg_match('//u', $suffix)) {
$suffix_length = length($suffix);
$total_length = length($string);
if ($suffix_length > $total_length) {
return false;
}
return Byte\length($string) - Byte\length($suffix) === Byte\search_last($string, $suffix);
$position = search_last($string, $suffix);
if (null === $position) {
return false;
}
return $position + $suffix_length === $total_length;
}

View File

@ -34,13 +34,20 @@ function ends_with_ci(
string $string,
string $suffix
): bool {
if ('' === $suffix) {
if ($suffix === $string) {
return true;
}
if (!\preg_match('//u', $suffix)) {
$suffix_length = length($suffix);
$total_length = length($string);
if ($suffix_length > $total_length) {
return false;
}
return (bool) \preg_match('{' . \preg_quote($suffix, '/') . '$}iu', $string);
$position = search_last_ci($string, $suffix);
if (null === $position) {
return false;
}
return $position + $suffix_length === $total_length;
}

View File

@ -26,13 +26,11 @@ function levenshtein(string $str1, string $str2, ?int $cost_of_insertion = null,
return \levenshtein($str1, $str2);
}
if (null !== $cost_of_deletion && null !== $cost_of_insertion && null !== $cost_of_replacement) {
return \levenshtein($str1, $str2, $cost_of_insertion, $cost_of_replacement, $cost_of_deletion);
}
// https://github.com/php/php-src/blob/623911f993f39ebbe75abe2771fc89faf6b15b9b/ext/standard/levenshtein.c#L101
Psl\invariant_violation('Expected either all costs to be supplied, or non.');
Psl\invariant(
null !== $cost_of_deletion && null !== $cost_of_insertion && null !== $cost_of_replacement,
'Expected either all costs to be supplied, or non.'
);
// satisfy PhpStorm
return 0;
return \levenshtein($str1, $str2, $cost_of_insertion, $cost_of_replacement, $cost_of_deletion);
}

View File

@ -17,25 +17,30 @@ use Psl;
* Example:
*
* Str\pad_left('Ay', 4)
* => Str(' Ay')
* => Str(' Ay')
*
* Str\pad_left('ay', 1, 'A')
* Str\pad_left('ay', 3, 'A')
* => Str('Aay')
*
* Str\pad_left('eet', 4, 'Yeeeee')
* => Str('Yeeeeet')
* => Str('Yeet')
*
* Str\pad_left('مرحبا', 5, 'ا')
* => Str(رحباااااا')
* Str\pad_left('مرحبا', 8, ')
* => Str(مممرحبا')
*/
function pad_left(string $string, int $total_length, string $pad_string = ' '): string
{
Psl\invariant('' !== $pad_string, 'Expected non-empty pad string.');
Psl\invariant($total_length >= 0, 'Expected non-negative total length.');
return Byte\pad_left(
$string,
Byte\length($string) - length($string) + $total_length,
$pad_string
);
while (length($string) < $total_length) {
$remaining = $total_length - length($string);
if ($remaining <= length($pad_string)) {
$pad_string = slice($pad_string, 0, $remaining);
}
$string = $pad_string . $string;
}
return $string;
}

View File

@ -17,25 +17,30 @@ use Psl;
* Example:
*
* Str\pad_right('Ay', 4)
* => Str('Ay ')
* => Str('Ay ')
*
* Str\pad_right('Ay', 1, 'y')
* => Str('Ayy')
* Str\pad_right('Ay', 5, 'y')
* => Str('Ayyyy')
*
* Str\pad_right('Yee', 4, 'eeet')
* => Str('Yeeeeet')
* Str\pad_right('Yee', 4, 't')
* => Str('Yeet')
*
* Str\pad_right('مرحبا', 5, ')
* => Str(مممممرحبا')
* Str\pad_right('مرحبا', 8, 'ا')
* => Str(رحباااا')
*/
function pad_right(string $string, int $total_length, string $pad_string = ' '): string
{
Psl\invariant('' !== $pad_string, 'Expected non-empty pad string.');
Psl\invariant($total_length >= 0, 'Expected non-negative total length.');
return Byte\pad_right(
$string,
Byte\length($string) - length($string) + $total_length,
$pad_string
);
while (length($string) < $total_length) {
$remaining = $total_length - length($string);
if ($remaining <= length($pad_string)) {
$pad_string = slice($pad_string, 0, $remaining);
}
$string .= $pad_string;
}
return $string;
}

View File

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Psl\Str;
/**
* Returns the 'haystack' string with all occurrences of the keys of
* Returns the '$haystack' string with all occurrences of the keys of
* `$replacements` replaced by the corresponding values.
*
* @psalm-param iterable<string, string> $replacements

View File

@ -10,17 +10,12 @@ use Psl;
* Returns the 'haystack' string with all occurrences of the keys of
* `$replacements` replaced by the corresponding values (case-insensitive).
*
* @psalm-param array<string, string> $replacements
* @psalm-param iterable<string, string> $replacements
*/
function replace_every_ci(string $haystack, array $replacements): string
function replace_every_ci(string $haystack, iterable $replacements): string
{
Psl\invariant('' === $haystack || \preg_match('//u', $haystack), 'Invalid UTF-8 string.');
foreach ($replacements as $needle => $replacement) {
Psl\invariant('' === $needle || \preg_match('//u', $needle), 'Invalid UTF-8 string.');
Psl\invariant('' === $replacement || \preg_match('//u', $replacement), 'Invalid UTF-8 string.');
if ('' === $needle || null === search($haystack, $needle)) {
if ('' === $needle || null === search_ci($haystack, $needle)) {
continue;
}

View File

@ -22,7 +22,7 @@ function search_last(string $haystack, string $needle, int $offset = 0): ?int
}
$haystack_length = length($haystack);
Psl\invariant($offset >= -$haystack_length && $offset <= $haystack_length, 'Offset is out-of-bounds.');
Psl\invariant($offset >= -$haystack_length && $offset <= $haystack_length, 'Offset is out-of-bound.');
return false === ($pos = \mb_strrpos($haystack, $needle, $offset)) ? null : $pos;
}

View File

@ -17,7 +17,12 @@ use Psl;
function slice(string $string, int $offset, ?int $length = null): string
{
Psl\invariant(null === $length || $length >= 0, 'Expected non-negative length.');
$offset = Psl\Internal\validate_offset($offset, length($string));
$string_length = length($string);
$offset = Psl\Internal\validate_offset($offset, $string_length);
if (0 === $offset && (null === $length || $string_length <= $length)) {
return $string;
}
return false === ($result = \mb_substr($string, $offset, $length, encoding($string))) ? '' : $result;
}

View File

@ -14,13 +14,15 @@ use Psl;
* remainder of the string will be replaced. If the length is zero, the
* replacement will be inserted at the offset.
*/
function splice(string $string, string $replacement, int $offset, ?int $length = null): string
function splice(string $string, string $replacement, int $offset = 0, ?int $length = null): string
{
Psl\invariant(null === $length || $length >= 0, 'Expected non-negative length.');
$offset = Psl\Internal\validate_offset($offset, length($string));
$total_length = length($string);
$offset = Psl\Internal\validate_offset($offset, $total_length);
$offset = $offset ? \strlen(slice($string, 0, $offset)) : 0;
$length = $length ? \strlen(slice($string, $offset, $length)) : $length;
if (null === $length || ($offset + $length) >= $total_length) {
return slice($string, 0, $offset) . $replacement;
}
return \substr_replace($string, $replacement, $offset, $length ?? \PHP_INT_MAX);
return slice($string, 0, $offset) . $replacement . slice($string, $offset + $length);
}

View File

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Psl\Str;
use Psl;
use Psl\Arr;
use Psl\Math;
/**
* Returns an array containing the string split on the given delimiter. The vec
@ -18,6 +18,7 @@ use Psl\Arr;
*/
function split(string $string, string $delimiter, ?int $limit = null): array
{
Psl\invariant(null === $limit || $limit >= 1, 'Expected positive limit');
if ('' === $delimiter) {
if (null === $limit || $limit >= length($string)) {
/** @var array<int, string> $result */
@ -30,7 +31,6 @@ function split(string $string, string $delimiter, ?int $limit = null): array
return [$string];
}
Psl\invariant($limit > 1, 'Expected positive limit.');
/** @var array<int, string> $result */
$result = chunk(slice($string, 0, $limit - 1));
$result[] = slice($string, $limit - 1);
@ -38,15 +38,22 @@ function split(string $string, string $delimiter, ?int $limit = null): array
return $result;
}
if (null === $limit) {
/** @var array<int, string> $result */
$result = \explode($delimiter, $string);
} else {
/** @var array<int, string> $result */
$result = \explode($delimiter, $string, $limit);
$limit ??= Math\INT64_MAX;
$tail = $string;
$chunks = [];
$position = search($tail, $delimiter);
while (1 < $limit && null !== $position) {
$result = slice($tail, 0, $position);
$chunks[] = $result;
$tail = slice($tail, length($result) + length($delimiter));
$limit--;
$position = search($tail, $delimiter);
}
Psl\invariant(Arr\is_array($result), 'Unexpected error');
$chunks[] = $tail;
return $result;
return $chunks;
}

View File

@ -12,8 +12,8 @@ namespace Psl\Str;
*/
function trim(string $string, ?string $char_mask = null): string
{
$char_mask = $char_mask ?? " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}";
$char_mask = preg_quote($char_mask);
$char_mask ??= " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}";
$char_mask = preg_quote($char_mask, null);
return \preg_replace("{^[$char_mask]++|[$char_mask]++$}u", '', $string);
return \preg_replace("{^[$char_mask]++|[$char_mask]++$}uD", '', $string);
}

View File

@ -12,8 +12,8 @@ namespace Psl\Str;
*/
function trim_left(string $string, ?string $char_mask = null): string
{
$char_mask = $char_mask ?? " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}";
$char_mask = preg_quote($char_mask);
$char_mask ??= " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}";
$char_mask = preg_quote($char_mask, null);
return \preg_replace("{[$char_mask]++$}u", '', $string);
return \preg_replace("{^[$char_mask]++}uD", '', $string);
}

View File

@ -12,8 +12,8 @@ namespace Psl\Str;
*/
function trim_right(string $string, ?string $char_mask = null): string
{
$char_mask = $char_mask ?? " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}";
$char_mask = preg_quote($char_mask);
$char_mask ??= " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}";
$char_mask = preg_quote($char_mask, null);
return \preg_replace("{^[$char_mask]++}u", '', $string);
return \preg_replace("{[$char_mask]++$}uD", '', $string);
}

View File

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Psl\Str;
/**
* Return width of string.
* Return width of length.
*/
function width(string $str): int
{

View File

@ -22,25 +22,29 @@ function wrap(string $string, int $width = 75, string $break = "\n", bool $cut =
return '';
}
// if ('' === $break) -> throw
Psl\invariant('' !== $break, 'Break string cannot be empty.');
Psl\invariant(0 !== $width && !$cut, 'Cannot force cut when width is zero.');
// if (0 === $width && $cut) -> throw
Psl\invariant(0 !== $width || !$cut, 'Cannot force cut when width is zero.');
$stringWidth = length($string);
$breakWidth = length($break);
$stringLength = length($string);
$breakLength = length($break);
$result = '';
$lastStart = $lastSpace = 0;
for ($current = 0; $current < $stringWidth; ++$current) {
for ($current = 0; $current < $stringLength; ++$current) {
$char = slice($string, $current, 1);
$possibleBreak = $char;
if (1 !== $breakWidth) {
$possibleBreak = slice($string, $current, $breakWidth);
if (1 !== $breakLength) {
$possibleBreak = slice($string, $current, $breakLength);
}
if ($possibleBreak === $break) {
$result .= slice($string, $lastStart, $current - $lastStart + $breakWidth);
$current += $breakWidth - 1;
$result .= slice($string, $lastStart, $current - $lastStart + $breakLength);
$current += $breakLength - 1;
$lastStart = $lastSpace = $current + 1;
continue;
}
if (' ' === $char) {
if ($current - $lastStart >= $width) {
$result .= slice($string, $lastStart, $current - $lastStart) . $break;
@ -49,17 +53,20 @@ function wrap(string $string, int $width = 75, string $break = "\n", bool $cut =
$lastSpace = $current;
continue;
}
if ($current - $lastStart >= $width && $cut && $lastStart >= $lastSpace) {
$result .= slice($string, $lastStart, $current - $lastStart) . $break;
$lastStart = $lastSpace = $current;
continue;
}
if ($current - $lastStart >= $width && $lastStart < $lastSpace) {
$result .= slice($string, $lastStart, $lastSpace - $lastStart) . $break;
$lastStart = ++$lastSpace;
continue;
}
}
if ($lastStart !== $current) {
$result .= slice($string, $lastStart, $current - $lastStart);
}

View File

@ -5,8 +5,28 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class CapitalizeTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testCapitalize(string $expected, string $value): void
{
self::assertSame($expected, Byte\capitalize($value));
}
public function provideData(): array
{
return [
['', ''],
['Hello', 'hello', ],
['Hello, world', 'hello, world'],
['Alpha', 'Alpha', ],
['Héllö, wôrld!', 'héllö, wôrld!'],
['ḫéllö, wôrld!', 'ḫéllö, wôrld!'],
['ßoo', 'ßoo'],
];
}
}

View File

@ -5,8 +5,26 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class CapitalizeWordsTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testCapitalizeWords(string $expected, string $value): void
{
self::assertSame($expected, Byte\capitalize_words($value));
}
public function provideData(): array
{
return [
['Hello', 'hello', ],
['Hello, World', 'hello, world'],
['ḫello, ꝡorld', 'ḫello, ꝡorld'],
['Alpha', 'Alpha', ],
['Foo, Bar, And Baz', 'foo, bar, and baz']
];
}
}

View File

@ -5,8 +5,26 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ChrTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testChr(string $expected, int $value): void
{
self::assertSame($expected, Byte\chr($value));
}
public function provideData(): array
{
return [
['E', 1605],
['0', 48],
['&', 38],
['\'', 1575],
['A', 65]
];
}
}

View File

@ -5,8 +5,26 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ChunkTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testCapitalize(array $expected, string $value, int $chunk_size = 1): void
{
self::assertSame($expected, Byte\chunk($value, $chunk_size));
}
public function provideData(): array
{
return [
[['h', 'e', 'l', 'l', 'o'], 'hello', ],
[['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'], 'hello, world', ],
[['Al', 'ph', 'a ', ' '], 'Alpha ', 2, ],
[['م', 'ر', 'ح', 'ب', 'ا'], 'مرحبا', 2],
[[], ''],
];
}
}

View File

@ -5,8 +5,37 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class CompareCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testCompareCi(int $expected, string $str1, string $str2, ?int $length = null): void
{
$diff = Byte\compare_ci($str1, $str2, $length);
if (0 === $expected) {
self::assertSame(0, $diff);
} else if (0 > $expected) {
self::assertLessThanOrEqual(-1, $diff);
} else {
self::assertGreaterThanOrEqual(1, $diff);
}
}
public function provideData(): array
{
return [
[0, 'Hello', 'hello'],
[0, 'hello', 'Hello'],
[0, 'Hello', 'Hello'],
[-1, 'Hello', 'helloo'],
[1, 'Helloo', 'hello'],
[0, 'Helloo', 'hello', 2],
[0, 'Helloo', 'hello', 5],
[1, 'Helloo', 'hello', 6],
];
}
}

View File

@ -5,8 +5,37 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class CompareTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testCompare(int $expected, string $str1, string $str2, ?int $length = null): void
{
$diff = Byte\compare($str1, $str2, $length);
if (0 === $expected) {
self::assertSame(0, $diff);
} else if (0 > $expected) {
self::assertLessThanOrEqual(-1, $diff);
} else {
self::assertGreaterThanOrEqual(1, $diff);
}
}
public function provideData(): array
{
return [
[-1, 'Hello', 'hello'],
[1, 'hello', 'Hello'],
[0, 'Hello', 'Hello'],
[-1, 'Hello', 'helloo'],
[-1, 'Helloo', 'hello'],
[-1, 'Helloo', 'hello', 2],
[-1, 'Helloo', 'hello', 5],
[-1, 'Helloo', 'hello', 6],
];
}
}

View File

@ -5,8 +5,29 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ContainsCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testContainsCi(bool $expected, string $haystack, string $needle, int $offset = 0): void
{
self::assertSame($expected, Byte\contains_ci($haystack, $needle, $offset));
}
public function provideData(): array
{
return [
[true, 'Hello, World', 'Hello', 0],
[true, 'Hello, World', 'world', 0],
[true, 'Hello, World', '', 8],
[false, 'hello, world', 'hey', 5],
[true, 'Azjezz', 'az', 0],
[false, 'azjezz', 'Az', 2],
[true, 'مرحبا بكم', 'بكم', 5],
[true, 'مرحبا بكم', 'بكم', 5],
];
}
}

View File

@ -5,8 +5,68 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ContainsTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testContains(bool $expected, string $haystack, string $needle, int $offset = 0): void
{
self::assertSame($expected, Byte\contains($haystack, $needle, $offset));
}
public function provideData(): array
{
return [
[
true,
'Hello, World',
'Hello',
0
],
[
false,
'Hello, World',
'world',
0
],
[
true,
'Hello, World',
'',
8
],
[
false,
'hello, world',
'hey',
5
],
[
true,
'azjezz',
'az',
0
],
[
false,
'azjezz',
'Az',
2
],
[
true,
'مرحبا بكم',
'بكم',
5
]
];
}
}

View File

@ -5,8 +5,31 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class EndsWithCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testEndsWithCi(bool $expected, string $haystack, string $suffix): void
{
self::assertSame($expected, Byte\ends_with_ci($haystack, $suffix));
}
public function provideData(): array
{
return [
[true, 'Hello', 'Hello'],
[false, 'Hello, WorlḐ', 'worlḑ', ],
[true, 'Hello, Worlḑ', 'worlḑ', ],
[false, 'T U N I S I A', 'e', ],
[true, 'تونس', 'س'],
[false, 'Hello, World', '', ],
[false, 'hello, world', 'hey', ],
[false, 'hello, worlḑ', 'hello cruel worḑ'],
[true, 'azjezz', 'z', ],
[true, 'مرحبا بكم', 'بكم', ],
];
}
}

View File

@ -5,8 +5,31 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class EndsWithTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testEndsWith(bool $expected, string $haystack, string $suffix): void
{
self::assertSame($expected, Byte\ends_with($haystack, $suffix));
}
public function provideData(): array
{
return [
[true, 'Hello', 'Hello'],
[false, 'Hello, WorlḐ', 'worlḑ', ],
[false, 'Hello, Worlḑ', 'worlḑ', ],
[false, 'T U N I S I A', 'e', ],
[true, 'تونس', 'س'],
[false, 'Hello, World', '', ],
[false, 'hello, world', 'hey', ],
[false, 'hello, worlḑ', 'hello cruel worḑ'],
[true, 'azjezz', 'z', ],
[true, 'مرحبا بكم', 'بكم', ],
];
}
}

View File

@ -5,8 +5,29 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class LengthTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testLength(int $expected, string $str): void
{
self::assertSame($expected, Byte\length($str));
}
public function provideData(): array
{
return [
[6, 'azjezz'],
[8, 'تونس'],
[6, 'سيف'],
[21, 'こんにちは世界'],
[12, '🥇🥈🥉'],
[6, '你好'],
[18, 'สวัสดี'],
[6, 'ؤخى']
];
}
}

View File

@ -5,8 +5,36 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class LowercaseTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testLowercase(string $expected, string $str): void
{
self::assertSame($expected, Byte\lowercase($str));
}
public function provideData(): array
{
return [
['hello', 'hello'],
['hello', 'Hello'],
['سيف', 'سيف'],
['1337', '1337'],
['hÉllÖ, wÔrld!', 'HÉLLÖ, WÔRLD!'],
['héllö, wôrld!', 'héllö, wôrld!'],
['ß', 'ß'],
['ẞ', 'ẞ'],
['🤷 🔥', '🤷 🔥'],
['سيف', 'سيف'],
['1337', '1337'],
['你好', '你好'],
['こんにちは世界', 'こんにちは世界'],
['สวัสดี', 'สวัสดี'],
['ؤخى', 'ؤخى']
];
}
}

View File

@ -5,8 +5,26 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class OrdTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testOrd(int $expected, string $value): void
{
self::assertSame($expected, Byte\ord($value));
}
public function provideData(): array
{
return [
[217, 'م'],
[48, '0'],
[38, '&'],
[216, 'ا'],
[65, 'A'],
];
}
}

View File

@ -5,8 +5,25 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class PadLeftTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testPadLeft(string $expected, string $str, int $total_length, string $pad_string = ' '): void
{
self::assertSame($expected, Byte\pad_left($str, $total_length, $pad_string));
}
public function provideData(): array
{
return [
[' aaay', 'aaay', 5],
['Aaaay', 'aaay', 5, 'A'],
['Yeet', 'eet', 4, 'Yeeeee'],
['مرحبا', 'مرحبا', 8, 'م'],
];
}
}

View File

@ -5,8 +5,25 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class PadRightTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testPadRight(string $expected, string $str, int $total_length, string $pad_string = ' '): void
{
self::assertSame($expected, Byte\pad_right($str, $total_length, $pad_string));
}
public function provideData(): array
{
return [
['aaay ', 'aaay', 5],
['aaayy', 'aaay', 5, 'y'],
['Yeet', 'Yee', 4, 't'],
['مرحبا', 'مرحبا', 8, 'ا'],
];
}
}

View File

@ -5,8 +5,25 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ReplaceCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testReplaceCi(string $expected, string $haystack, string $needle, string $replacement): void
{
self::assertSame($expected, Byte\replace_ci($haystack, $needle, $replacement));
}
public function provideData(): array
{
return [
['Hello, World!', 'Hello, you!', 'You', 'World', ],
['Hello, World!', 'Hello, You!', 'You', 'World', ],
['مرحبا بكم', 'مرحبا سيف', 'سيف', 'بكم'],
['foo', 'foo', 'bar', 'baz'],
];
}
}

View File

@ -5,8 +5,49 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ReplaceEveryCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testReplaceEveryCi(string $expected, string $haystack, iterable $replacements): void
{
self::assertSame($expected, Byte\replace_every_ci($haystack, $replacements));
}
public function provideData(): array
{
return [
[
'Hello, World!',
'Hello, you!',
['You' => 'World'],
],
[
'Hello, World!',
'Hello, You!',
['You' => 'World'],
],
[
'مرحبا بكم',
'مرحبا سيف',
['سيف' => 'بكم'],
],
[
'اهلا بكم',
'مرحبا سيف',
[
'سيف' => 'بكم',
'مرحبا' => 'اهلا'
],
],
[
'Foo',
'Foo',
['bar' => 'baz']
]
];
}
}

View File

@ -5,8 +5,46 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ReplaceEveryTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testReplaceEvery(string $expected, string $haystack, iterable $replacements): void
{
self::assertSame($expected, Byte\replace_every($haystack, $replacements));
}
public function provideData(): array
{
return [
[
'Hello, you!',
'Hello, you!',
['You' => 'World'],
],
[
'Hello, World!',
'Hello, You!',
['You' => 'World'],
],
[
'مرحبا بكم',
'مرحبا سيف',
['سيف' => 'بكم'],
],
[
'اهلا بكم',
'مرحبا سيف',
['سيف' => 'بكم', 'مرحبا' => 'اهلا'],
],
[
'Foo',
'Foo',
['bar' => 'baz']
]
];
}
}

View File

@ -5,8 +5,25 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ReplaceTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testReplace(string $expected, string $haystack, string $needle, string $replacement): void
{
self::assertSame($expected, Byte\replace($haystack, $needle, $replacement));
}
public function provideData(): array
{
return [
['Hello, you!', 'Hello, you!', 'You', 'World', ],
['Hello, World!', 'Hello, You!', 'You', 'World', ],
['مرحبا بكم', 'مرحبا سيف', 'سيف', 'بكم'],
['foo', 'foo', 'bar', 'baz'],
];
}
}

View File

@ -5,8 +5,23 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ReverseTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testReverse(string $expected, string $input): void
{
self::assertSame($expected, Byte\reverse($input));
}
public function provideData(): array
{
return [
['oof', 'foo'],
['', ''],
];
}
}

View File

@ -5,8 +5,24 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class Rot13Test extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testWords(string $expected, string $string): void
{
self::assertSame($expected, Byte\rot13($string));
}
public function provideData(): array
{
return [
['', ''],
['Uryyb', 'Hello'],
['Uryyb, Jbeyq!', 'Hello, World!'],
];
}
}

View File

@ -5,8 +5,29 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class SearchCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testSearchCi(?int $expected, string $haystack, string $needle, int $offset = 0): void
{
self::assertSame($expected, Byte\search_ci($haystack, $needle, $offset));
}
public function provideData(): array
{
return [
[7, 'Hello, you!', 'You', ],
[7, 'Hello, You!', 'You', ],
[0, 'Ho! Ho! Ho!', 'ho', ],
[0, 'Ho! Ho! Ho!', 'Ho', ],
[7, 'Hello, You!', 'You', 5],
[null, 'Hello, World!', 'You', 5],
[null, 'foo', 'bar', 2],
];
}
}

View File

@ -5,8 +5,29 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class SearchLastTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testSearchLast(?int $expected, string $haystack, string $needle, int $offset = 0): void
{
self::assertSame($expected, Byte\search_last($haystack, $needle, $offset));
}
public function provideData(): array
{
return [
[null, 'Hello, you!', 'You', ],
[7, 'Hello, You!', 'You', ],
[null, 'Ho! Ho! Ho!', 'ho', ],
[8, 'Ho! Ho! Ho!', 'Ho', ],
[7, 'Hello, You!', 'You', 5],
[null, 'Hello, World!', 'You', 5],
[null, 'foo', 'bar', 2],
];
}
}

View File

@ -5,8 +5,29 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class SearchTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testSearch(?int $expected, string $haystack, string $needle, int $offset = 0): void
{
self::assertSame($expected, Byte\search($haystack, $needle, $offset));
}
public function provideData(): array
{
return [
[null, 'Hello, you!', 'You', ],
[7, 'Hello, You!', 'You', ],
[null, 'Ho! Ho! Ho!', 'ho', ],
[0, 'Ho! Ho! Ho!', 'Ho', ],
[7, 'Hello, You!', 'You', 5],
[null, 'Hello, World!', 'You', 5],
[null, 'foo', 'bar', 2],
];
}
}

View File

@ -5,8 +5,30 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class ShuffleTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testShuffle(string $str): void
{
$shuffled = Byte\shuffle($str);
self::assertSame(Byte\length($str), Byte\length($shuffled));
if (Byte\length($shuffled) > 1) {
self::assertNotSame($str, $shuffled);
}
}
public function provideData(): array
{
return [
[''],
['A'],
['Hello, World!'],
['People linked by destiny will always find each other.'],
];
}
}

View File

@ -5,8 +5,49 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Exception;
use Psl\Str\Byte;
class SliceTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testSlice(string $expected, string $string, int $offset, ?int $length = null): void
{
self::assertSame($expected, Byte\slice($string, $offset, $length));
}
public function provideData(): array
{
return [
['', '', 0, 0, ],
['Hello', 'Hello, World!', 0, 5],
['Hello, World!', 'Hello, World!', 0],
['World', 'Hello, World!', 7, 5],
['destiny', 'People linked by destiny will always find each other.', 17, 7],
];
}
public function testSliceThrowsForNegativeLength(): void
{
$this->expectException(Exception\InvariantViolationException::class);
Byte\slice('Hello', 0, -1);
}
public function testSliceThrowsForOutOfBoundOffset(): void
{
$this->expectException(Exception\InvariantViolationException::class);
Byte\slice('Hello', 10);
}
public function testSliceThrowsForNegativeOutOfBoundOffset(): void
{
$this->expectException(Exception\InvariantViolationException::class);
Byte\slice('hello', -6);
}
}

View File

@ -5,8 +5,30 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class SpliceTest extends TestCase
{
// TODO: add tests.
/**
* @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],
];
}
}

View File

@ -5,8 +5,28 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class SplitTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testSplit(array $expected, string $string, string $delimiter, ?int $length = null): void
{
self::assertSame($expected, Byte\split($string, $delimiter, $length));
}
public function provideData(): array
{
return [
[[], '', '', 1],
[['H', 'e', 'l', 'l', 'o'], 'Hello', ''],
[['Hello'], 'Hello', '', 1],
[['H', 'ello'], 'Hello', '', 2],
[['Hello, World!'], 'Hello, World!', ' ', 1],
[['Hello,', 'World!'], 'Hello, World!', ' '],
[['Hello,', 'World!'], 'Hello, World!', ' ', 2],
];
}
}

View File

@ -5,8 +5,37 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class StartsWithCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testStartsWithCi(bool $expected, string $haystack, string $prefix): void
{
self::assertSame($expected, Byte\starts_with_ci($haystack, $prefix));
}
public function provideData(): array
{
return [
[true, 'Hello, World', 'Hello', ],
[false, 'Hello, World', 'world', ],
[false, 'Hello, World', '', ],
[false, 'hello, world', 'hey', ],
[true, 'azjezz', 'az', ],
[true, 'azjezz', 'Az', ],
[false, 'مرحبا بكم', 'بكم', ],
[true, 'مرحبا بكم', 'مرحبا', ],
[true, 'مرحبا سيف', 'مرحبا', 3],
[false, 'مرحبا سيف', 'سيف', 3],
[true, 'اهلا بكم', 'اهلا', 2],
[true, 'héllö wôrld', 'héllö', ],
[false, 'héllö wôrld', 'hello', ],
[true, 'fôo', 'fôo', ],
[true, 'fôo', 'f', ],
[true, 'fôo', 'fô', ],
];
}
}

View File

@ -5,8 +5,38 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class StartsWithTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testStartsWith(bool $expected, string $haystack, string $prefix): void
{
self::assertSame($expected, Byte\starts_with($haystack, $prefix));
}
public function provideData(): array
{
return [
[true, 'Hello, World', 'Hello', ],
[false, 'Hello, World', 'world', ],
[false, 'Hello, World', '', ],
[false, 'hello, world', 'hey', ],
[true, 'azjezz', 'az', ],
[false, 'azjezz', 'Az', ],
[false, 'مرحبا بكم', 'بكم', ],
[true, 'مرحبا بكم', 'مرحبا', ],
[true, 'مرحبا سيف', 'مرحبا', 3],
[false, 'مرحبا سيف', 'سيف', 3],
[true, 'اهلا بكم', 'اهلا', 2],
[true, 'héllö wôrld', 'héllö', ],
[false, 'héllö wôrld', 'hello', ],
[true, 'fôo', 'fôo', ],
[true, 'fôo', 'f', ],
[true, 'fôo', 'fô', ],
];
}
}

View File

@ -5,8 +5,37 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class StripPrefixTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testStripPrefix(string $expected, string $haystack, string $prefix): void
{
self::assertSame($expected, Byte\strip_prefix($haystack, $prefix));
}
public function provideData(): array
{
return [
['World', 'Hello, World', 'Hello, '],
['Hello, World', 'Hello, World', 'world'],
['Hello, World', 'Hello, World', ''],
['hello, world', 'hello, world', 'hey'],
['jezz', 'azjezz', 'az'],
['azjezz', 'azjezz', 'Az'],
['مرحبا بكم', 'مرحبا بكم', 'بكم'],
['بكم', 'مرحبا بكم', 'مرحبا '],
['سيف', 'مرحبا سيف', 'مرحبا ', 3],
['مرحبا سيف', 'مرحبا سيف', 'سيف', 3],
[' بكم', 'اهلا بكم', 'اهلا', 2],
['wôrld', 'héllö wôrld', 'héllö '],
['héllö wôrld', 'héllö wôrld', 'hello'],
['', 'fôo', 'fôo'],
['ôo', 'fôo', 'f'],
['o', 'fôo', 'fô'],
];
}
}

View File

@ -5,8 +5,43 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class StripSuffixTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testStripSuffix(string $expected, string $haystack, string $suffix): void
{
self::assertSame($expected, Byte\strip_suffix($haystack, $suffix));
}
public function provideData(): array
{
return [
['', 'Hello', 'Hello'],
['Hello, World', 'Hello, World', 'world', ],
['T U N I S I A', 'T U N I S I A', 'e', ],
['تون', 'تونس', 'س'],
['Hello, World', 'Hello, World', '', ],
['Hello, World', 'Hello, World', 'Hello, cruel world!', ],
['hello, world', 'hello, world', 'hey', ],
['azjez', 'azjezz', 'z', ],
['مرحبا ', 'مرحبا بكم', 'بكم', ],
['Hello', 'Hello, World', ', World', ],
['Hello, World', 'Hello, World', 'world', ],
['Hello, World', 'Hello, World', '', ],
['hello, world', 'hello, world', 'universe', ],
['azje', 'azjezz', 'zz', ],
['azjezz', 'azjezz', 'ZZ', ],
['مرحبا', 'مرحبا سيف', ' سيف', 3],
['اهلا', 'اهلا بكم', ' بكم', 3],
['héllö', 'héllö wôrld', ' wôrld', ],
['héllö wôrld', 'héllö wôrld', ' world', ],
['fô', 'fôo', 'o', ],
['fôo', 'fôo', 'ô', ],
['f', 'fôo', 'ôo', ],
];
}
}

View File

@ -5,8 +5,47 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class TrimLeftTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testTrimLeft(string $expected, string $string, ?string $chars = null): void
{
self::assertSame($expected, Byte\trim_left($string, $chars));
}
public function provideData(): array
{
return [
[
"Hello Wôrld\t!!!\n",
" Hello Wôrld\t!!!\n",
null,
],
[
"Hello Wôrld\t!!!\n",
" Hello Wôrld\t!!!\n",
' ',
],
[
" Héllö World\t!!!\n",
" Héllö World\t!!!\n",
"\n",
],
[
"Héllö World\t!!!\n",
" Héllö World\t!!!\n",
" \n!",
],
[
"Héllö Wôrld\t!!! \n",
" Héllö Wôrld\t!!! \n",
' ',
],
];
}
}

View File

@ -5,8 +5,57 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class TrimRightTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testTrimRight(string $expected, string $string, ?string $chars = null): void
{
self::assertSame($expected, Byte\trim_right($string, $chars));
}
public function provideData(): array
{
return [
[
" Hello World\t!!!",
" Hello World\t!!!\n",
null,
],
[
" Hello World\t!!!\n",
" Hello World\t!!!\n",
' ',
],
[
" Hello World\t!!!",
" Hello World\t!!!\n",
"\n",
],
[
" Hello World\t",
" Hello World\t!!!\n",
"\n!",
],
[
' Hello World',
" Hello World\t!!!\n",
"\n!\t",
],
[
" Hello World\t",
" Hello World\t!!!\n",
" \n!",
],
[
" Hello World\t!!! \n",
" Hello World\t!!! \n",
' ',
],
];
}
}

View File

@ -5,8 +5,51 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class TrimTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testTrim(string $expected, string $string, ?string $chars = null): void
{
self::assertSame($expected, Byte\trim($string, $chars));
}
public function provideData(): array
{
return [
[
"Hello Wôrld\t!!!",
" Hello Wôrld\t!!!\n",
null,
],
[
"Hello Wôrld\t!!!\n",
" Hello Wôrld\t!!!\n",
' ',
],
[
" Héllö World\t!!!",
" Héllö World\t!!!\n",
"\n",
],
[
"Héllö World\t",
" Héllö World\t!!!\n",
" \n!",
],
[
"Héllö World",
" Héllö World\t!!!\n",
" \n!\t",
],
[
"Héllö Wôrld\t!!! \n",
" Héllö Wôrld\t!!! \n",
' ',
],
];
}
}

View File

@ -5,8 +5,34 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class UppercaseTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testUppercase(string $expected, string $str): void
{
self::assertSame($expected, Byte\uppercase($str));
}
public function provideData(): array
{
return [
['HELLO', 'hello'],
['HELLO', 'helLO'],
['HELLO', 'Hello'],
['HéLLö, WôRLD!', 'héllö, wôrld!'],
['ẞ', 'ẞ'],
['🤷 🔥', '🤷 🔥'],
['سيف', 'سيف'],
['1337', '1337'],
['你好', '你好'],
['こんにちは世界', 'こんにちは世界'],
['สวัสดี', 'สวัสดี'],
['ؤخى', 'ؤخى']
];
}
}

View File

@ -5,8 +5,30 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str\Byte;
class WordsTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testWords(array $expected, string $string, ?string $extra_chars = null): void
{
self::assertSame($expected, Byte\words($string, $extra_chars));
}
public function provideData(): array
{
return [
[[], ''],
[['Hello'], 'Hello'],
[['Hello'], 'Hello', ' '],
[[0 => 'Hello', 7 => 'World'], 'Hello, World!'],
[[0 => 'Hello', 6 => ' World'], 'Hello, World!', ' '],
[[0 => 'Hello', 7 => 'World!'], 'Hello, World!', '!'],
[[0 => 'Hello,', 7 => 'World!'], 'Hello, World!', '!,'],
[[0 => 'Hello, World!'], 'Hello, World!', '!, '],
];
}
}

View File

@ -5,8 +5,27 @@ declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
use Psl\Str;
use Psl\Str\Byte;
class WrapTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testWrap(string $expected, string $str, int $width = 75, string $break = "\n", bool $cut = false): void
{
self::assertSame($expected, Byte\wrap($str, $width, $break, $cut));
}
public function provideData(): array
{
return [
['Hello', 'Hello'],
['', ''],
['☕ ~ ☕ ~ ☕', '☕ ☕ ☕', 1, ' ~ '],
["héllö,-\nwôrld", 'héllö, wôrld', 8, "-\n", true],
['مرحبا<br />بكم', 'مرحبا بكم', 3, '<br />', false],
];
}
}

View File

@ -5,8 +5,36 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class CapitalizeTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testCapitalize(string $expected, string $value): void
{
self::assertSame($expected, Str\capitalize($value));
}
public function provideData(): array
{
return [
['', ''],
['Hello', 'hello', ],
['Hello, world', 'hello, world'],
['Alpha', 'Alpha', ],
['مرحبا بكم', 'مرحبا بكم'],
['Héllö, wôrld!', 'héllö, wôrld!'],
['Ḫéllö, wôrld!', 'ḫéllö, wôrld!'],
['SSoo', 'ßoo'],
['ẞoo', 'ẞoo'],
['🤷 🔥', '🤷 🔥'],
['سيف', 'سيف'],
['你好', '你好'],
['こんにちは世界', 'こんにちは世界'],
['สวัสดี', 'สวัสดี'],
['ؤخى', 'ؤخى']
];
}
}

View File

@ -5,8 +5,28 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class CapitalizeWordsTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testCapitalizeWords(string $expected, string $value): void
{
self::assertSame($expected, Str\capitalize_words($value));
}
public function provideData(): array
{
return [
['Hello', 'hello', ],
['Hello, World', 'hello, world'],
['Ḫello, Ꝡorld', 'ḫello, ꝡorld'],
['Alpha', 'Alpha', ],
['مرحبا بكم', 'مرحبا بكم', ],
['Foo, Bar, And Baz', 'foo, bar, and baz']
];
}
}

View File

@ -5,8 +5,26 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class ChrTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testChr(string $expected, int $value): void
{
self::assertSame($expected, Str\chr($value));
}
public function provideData(): array
{
return [
['م', 1605],
['0', 48],
['&', 38],
['ا', 1575],
['A', 65]
];
}
}

View File

@ -5,8 +5,28 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class ChunkTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testCapitalize(array $expected, string $value, int $chunk_size = 1): void
{
self::assertSame($expected, Str\chunk($value, $chunk_size));
}
public function provideData(): array
{
return [
[['h', 'e', 'l', 'l', 'o'], 'hello', ],
[['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'], 'hello, world', ],
[['Al', 'ph', 'a ', ' '], 'Alpha ', 2, ],
[['م', 'ر', 'ح', 'ب', 'ا', ' ', 'ب', 'ك', 'م'], 'مرحبا بكم', ],
[['مرحبا بكم'], 'مرحبا بكم', 9, ],
[[], ''],
];
}
}

View File

@ -5,8 +5,14 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class ConcatTest extends TestCase
{
// TODO: add tests.
public function testConcat(): void
{
self::assertSame('', Str\concat(''));
self::assertSame('abc', Str\concat('a', 'b', 'c'));
self::assertSame('مرحبا بكم', Str\concat(...['م', 'ر', 'ح', 'ب', 'ا', ' ', 'ب', 'ك', 'م']));
}
}

View File

@ -5,8 +5,28 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class ContainsCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testContainsCi(bool $expected, string $haystack, string $needle, int $offset = 0): void
{
self::assertSame($expected, Str\contains_ci($haystack, $needle, $offset));
}
public function provideData(): array
{
return [
[true, 'Hello, World', 'Hello', 0],
[true, 'Hello, World', 'world', 0],
[true, 'Hello, World', '', 8],
[false, 'hello, world', 'hey', 5],
[true, 'Azjezz', 'az', 0],
[false, 'azjezz', 'Az', 2],
[true, 'مرحبا بكم', 'بكم', 5],
];
}
}

View File

@ -5,8 +5,68 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class ContainsTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testContains(bool $expected, string $haystack, string $needle, int $offset = 0): void
{
self::assertSame($expected, Str\contains($haystack, $needle, $offset));
}
public function provideData(): array
{
return [
[
true,
'Hello, World',
'Hello',
0
],
[
false,
'Hello, World',
'world',
0
],
[
true,
'Hello, World',
'',
8
],
[
false,
'hello, world',
'hey',
5
],
[
true,
'azjezz',
'az',
0
],
[
false,
'azjezz',
'Az',
2
],
[
true,
'مرحبا بكم',
'بكم',
5
]
];
}
}

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
class EncodingTest extends TestCase
{
// TODO: add tests.
}

View File

@ -5,8 +5,35 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class EndsWithCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testEndsWithCi(bool $expected, string $haystack, string $suffix): void
{
if (null === Str\search_ci($haystack, $suffix)) {
self::assertFalse(Str\ends_with_ci($haystack, $suffix));
} else {
self::assertSame($expected, Str\ends_with_ci($haystack, $suffix));
}
}
public function provideData(): array
{
return [
[true, 'Hello', 'Hello'],
[true, 'Hello, World', 'world', ],
[true, 'Hello, WorlḐ', 'worlḑ', ],
[false, 'T U N I S I A', 'e', ],
[true, 'تونس', 'س'],
[false, 'Hello, World', '', ],
[false, 'hello, world', 'hey', ],
[false, 'hello, world', 'hello cruel world'],
[true, 'azjezz', 'z', ],
[true, 'مرحبا بكم', 'بكم', ],
];
}
}

View File

@ -5,8 +5,30 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class EndsWithTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testEndsWith(bool $expected, string $haystack, string $suffix): void
{
self::assertSame($expected, Str\ends_with($haystack, $suffix));
}
public function provideData(): array
{
return [
[true, 'Hello', 'Hello'],
[false, 'Hello, World', 'world', ],
[false, 'T U N I S I A', 'e', ],
[true, 'تونس', 'س'],
[false, 'Hello, World', '', ],
[false, 'Hello, World', 'Hello, cruel world!', ],
[false, 'hello, world', 'hey', ],
[true, 'azjezz', 'z', ],
[true, 'مرحبا بكم', 'بكم', ],
];
}
}

View File

@ -5,8 +5,12 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class FoldTest extends TestCase
{
// TODO: add tests.
public function testFold(): void
{
self::assertSame('ssoo', Str\fold('ẞOO'));
}
}

View File

@ -5,8 +5,12 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class FormatNumberTest extends TestCase
{
// TODO: add tests.
public function testFormatNumber(): void
{
self::assertSame('487 891,49', Str\format_number(487891.4879, 2, ',', ' '));
}
}

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
class FormatTest extends TestCase
{
// TODO: add tests.
}

View File

@ -5,8 +5,22 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class FromCodePointsTest extends TestCase
{
// TODO: add tests.
public function testFromCodePoints(): void
{
self::assertSame(/* NULL = */ Str\chr(0), Str\from_code_points(0));
self::assertSame('مرحبا بكم', Str\from_code_points(1605, 1585, 1581, 1576, 1575, 32, 1576, 1603, 1605));
self::assertSame('Hello', Str\from_code_points(72, 101, 108, 108, 111));
self::assertSame('ẞoo!', Str\from_code_points(7838, 111, 111, 33));
self::assertSame('ς', Str\from_code_points(962));
self::assertSame("\u{10001}", Str\from_code_points(65537));
}
}

View File

@ -5,8 +5,14 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class IsEmptyTest extends TestCase
{
// TODO: add tests.
public function testIsEmpty(): void
{
self::assertTrue(Str\is_empty(''));
self::assertFalse(Str\is_empty(Str\chr(0)));
self::assertFalse(Str\is_empty('hello'));
}
}

View File

@ -5,8 +5,26 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class IsStringTest extends TestCase
{
// TODO: add tests.
public function testIsEmpty(): void
{
self::assertTrue(Str\is_string(''));
self::assertTrue(Str\is_string(Str\chr(0)));
self::assertFalse(Str\is_string(5));
self::assertFalse(Str\is_string(5.0));
self::assertFalse(Str\is_string(true));
self::assertFalse(Str\is_string(null));
self::assertFalse(Str\is_string(
new class {
public function __toString(): string
{
return 'hello';
}
}
));
}
}

View File

@ -5,8 +5,14 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class JoinTest extends TestCase
{
// TODO: add tests.
public function testJoin(): void
{
self::assertSame('abc', Str\join(['a', 'b', 'c'], ''));
self::assertSame('Hello, World', Str\join(['Hello', 'World'], ', '));
self::assertSame('foo / bar / baz', Str\join(['foo', 'bar', 'baz'], ' / '));
}
}

View File

@ -5,8 +5,29 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class LengthTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testLength(int $expected, string $str): void
{
self::assertSame($expected, Str\length($str));
}
public function provideData(): array
{
return [
[6, 'azjezz'],
[4, 'تونس'],
[3, 'سيف'],
[7, 'こんにちは世界'],
[3, '🥇🥈🥉'],
[2, '你好'],
[6, 'สวัสดี'],
[3, 'ؤخى']
];
}
}

View File

@ -5,8 +5,32 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class LevenshteinTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testLevenshtein(
int $expected,
string $a,
string $b,
?int $coi = null,
?int $cor = null,
?int $cod = null
): void {
self::assertSame($expected, Str\levenshtein($a, $b, $coi, $cor, $cod));
}
public function provideData(): array
{
return [
[0, 'o', 'o'],
[1, 'foo', 'oo'],
[1, 'oo', 'foo'],
[6, 'saif', 'azjezz'],
[48, 'saif', 'azjezz', 9, 8, 5]
];
}
}

View File

@ -5,8 +5,36 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class LowercaseTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testLowercase(string $expected, string $str): void
{
self::assertSame($expected, Str\lowercase($str));
}
public function provideData(): array
{
return [
['hello', 'hello'],
['hello', 'Hello'],
['سيف', 'سيف'],
['1337', '1337'],
['héllö, wôrld!', 'HÉLLÖ, WÔRLD!'],
['héllö, wôrld!', 'héllö, wôrld!'],
['ß', 'ß'],
['ß', 'ẞ'],
['🤷 🔥', '🤷 🔥'],
['سيف', 'سيف'],
['1337', '1337'],
['你好', '你好'],
['こんにちは世界', 'こんにちは世界'],
['สวัสดี', 'สวัสดี'],
['ؤخى', 'ؤخى']
];
}
}

View File

@ -5,8 +5,26 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class MetaphoneTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testMetaphone(?string $expected, string $str, int $phonemes = 0): void
{
self::assertSame($expected, Str\metaphone($str, $phonemes));
}
public function provideData(): array
{
return [
['HL', 'hello'],
['HLWRLT', 'Hello, World !!', 10],
['PPLLNKTBTSTNWLLWSFNTX0R', 'People linked by destiny will always find each other.'],
['', 'سيف'],
['', '1337'],
];
}
}

View File

@ -5,8 +5,26 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class OrdTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testOrd(int $expected, string $value): void
{
self::assertSame($expected, Str\ord($value));
}
public function provideData(): array
{
return [
[1605, 'م'],
[48, '0'],
[38, '&'],
[1575, 'ا'],
[65, 'A'],
];
}
}

View File

@ -5,8 +5,25 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class PadLeftTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testPadLeft(string $expected, string $str, int $total_length, string $pad_string = ' '): void
{
self::assertSame($expected, Str\pad_left($str, $total_length, $pad_string));
}
public function provideData(): array
{
return [
[' aaay', 'aaay', 5],
['Aaaay', 'aaay', 5, 'A'],
['Yeet', 'eet', 4, 'Yeeeee'],
['ممممرحبا', 'مرحبا', 8, 'م'],
];
}
}

View File

@ -5,8 +5,25 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class PadRightTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testPadRight(string $expected, string $str, int $total_length, string $pad_string = ' '): void
{
self::assertSame($expected, Str\pad_right($str, $total_length, $pad_string));
}
public function provideData(): array
{
return [
['aaay ', 'aaay', 5],
['aaayy', 'aaay', 5, 'y'],
['Yeet', 'Yee', 4, 't'],
['مرحباااا', 'مرحبا', 8, 'ا'],
];
}
}

View File

@ -5,8 +5,24 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class RepeatTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testRepeat(string $expected, string $string, int $multiplier): void
{
self::assertSame($expected, Str\repeat($string, $multiplier));
}
public function provideData(): array
{
return [
['a', 'a', 1],
['Go! Go! Go! ', 'Go! ', 3],
['مممممممممممم', 'م', 12],
];
}
}

View File

@ -5,8 +5,25 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class ReplaceCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testReplaceCi(string $expected, string $haystack, string $needle, string $replacement): void
{
self::assertSame($expected, Str\replace_ci($haystack, $needle, $replacement));
}
public function provideData(): array
{
return [
['Hello, World!', 'Hello, you!', 'You', 'World', ],
['Hello, World!', 'Hello, You!', 'You', 'World', ],
['مرحبا بكم', 'مرحبا سيف', 'سيف', 'بكم'],
['foo', 'foo', 'bar', 'baz'],
];
}
}

View File

@ -5,8 +5,49 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class ReplaceEveryCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testReplaceEveryCi(string $expected, string $haystack, iterable $replacements): void
{
self::assertSame($expected, Str\replace_every_ci($haystack, $replacements));
}
public function provideData(): array
{
return [
[
'Hello, World!',
'Hello, you!',
['You' => 'World'],
],
[
'Hello, World!',
'Hello, You!',
['You' => 'World'],
],
[
'مرحبا بكم',
'مرحبا سيف',
['سيف' => 'بكم'],
],
[
'اهلا بكم',
'مرحبا سيف',
[
'سيف' => 'بكم',
'مرحبا' => 'اهلا'
],
],
[
'Foo',
'Foo',
['bar' => 'baz']
]
];
}
}

View File

@ -5,8 +5,47 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class ReplaceEveryTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testReplaceEvery(string $expected, string $haystack, iterable $replacements): void
{
self::assertSame($expected, Str\replace_every($haystack, $replacements));
}
public function provideData(): array
{
return [
[
'Hello, you!',
'Hello, you!',
['You' => 'World'],
],
[
'Hello, World!',
'Hello, You!',
['You' => 'World'],
],
[
'مرحبا بكم',
'مرحبا سيف',
['سيف' => 'بكم'],
],
[
'اهلا بكم',
'مرحبا سيف',
['سيف' => 'بكم', 'مرحبا' => 'اهلا'],
],
[
'Foo',
'Foo',
['bar' => 'baz']
]
];
}
}

View File

@ -5,8 +5,25 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class ReplaceTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testReplace(string $expected, string $haystack, string $needle, string $replacement): void
{
self::assertSame($expected, Str\replace($haystack, $needle, $replacement));
}
public function provideData(): array
{
return [
['Hello, you!', 'Hello, you!', 'You', 'World', ],
['Hello, World!', 'Hello, You!', 'You', 'World', ],
['مرحبا بكم', 'مرحبا سيف', 'سيف', 'بكم'],
['foo', 'foo', 'bar', 'baz'],
];
}
}

View File

@ -5,8 +5,29 @@ declare(strict_types=1);
namespace Psl\Tests\Str;
use PHPUnit\Framework\TestCase;
use Psl\Str;
class SearchCiTest extends TestCase
{
// TODO: add tests.
/**
* @dataProvider provideData
*/
public function testSearchCi(?int $expected, string $haystack, string $needle, int $offset = 0): void
{
self::assertSame($expected, Str\search_ci($haystack, $needle, $offset));
}
public function provideData(): array
{
return [
[7, 'Hello, you!', 'You', ],
[7, 'Hello, You!', 'You', ],
[0, 'Ho! Ho! Ho!', 'ho', ],
[0, 'Ho! Ho! Ho!', 'Ho', ],
[7, 'Hello, You!', 'You', 5],
[null, 'Hello, World!', 'You', 5],
[6, 'مرحبا سيف', 'سيف', 4],
[null, 'foo', 'bar', 2],
];
}
}

Some files were not shown because too many files have changed in this diff Show More