Skip to content

Commit

Permalink
chore: adds missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Feb 14, 2025
1 parent 0a81906 commit 3493fc3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ final class Str
*/
public static function isRegex(string $target): bool
{
if (strlen($target) < 2) {
if (mb_strlen($target) < 2) {
return false;
}

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

Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/Support/StrTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use Pest\Browser\Support\Str;

it('detects regex expressions', function () {
$regex = '/^.*$/';

$result = Str::isRegex($regex);

expect($result)->toBeTrue();
});

it('detects non-regex expressions', function () {
$string = 'string';

$result = Str::isRegex($string);

expect($result)->toBeFalse();
});

0 comments on commit 3493fc3

Please sign in to comment.