Skip to content

Commit 3493fc3

Browse files
committed
chore: adds missing tests
1 parent 0a81906 commit 3493fc3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Support/Str.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ final class Str
1414
*/
1515
public static function isRegex(string $target): bool
1616
{
17-
if (strlen($target) < 2) {
17+
if (mb_strlen($target) < 2) {
1818
return false;
1919
}
2020

2121
// If the first and last characters are not the same, it's not a regex
22-
if (($delimiter = substr($target, 0, 1)) !== substr($target, -1, 1)) {
22+
if (($delimiter = mb_substr($target, 0, 1)) !== mb_substr($target, -1, 1)) {
2323
return false;
2424
}
2525

tests/Unit/Support/StrTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Pest\Browser\Support\Str;
6+
7+
it('detects regex expressions', function () {
8+
$regex = '/^.*$/';
9+
10+
$result = Str::isRegex($regex);
11+
12+
expect($result)->toBeTrue();
13+
});
14+
15+
it('detects non-regex expressions', function () {
16+
$string = 'string';
17+
18+
$result = Str::isRegex($string);
19+
20+
expect($result)->toBeFalse();
21+
});

0 commit comments

Comments
 (0)