Skip to content

Commit 9162c4c

Browse files
committed
Missing tests for regExpMatch
1 parent 1294292 commit 9162c4c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Runtime\Functions\Util;
6+
7+
use Fp\Functional\Option\Option;
8+
use PHPUnit\Framework\TestCase;
9+
10+
use function Fp\Util\regExpMatch;
11+
12+
final class RegExpTest extends TestCase
13+
{
14+
/**
15+
* @param Option<non-empty-string> $expected
16+
* @dataProvider provideRegExpMatchCases
17+
*/
18+
public function testRegExpMatch(string $expr, string $text, Option $expected, int|string $capturingGroup = 0): void
19+
{
20+
$this->assertEquals($expected, regExpMatch($expr, $text, $capturingGroup));
21+
}
22+
23+
public function provideRegExpMatchCases(): iterable
24+
{
25+
yield 'No match' => [
26+
'/[0-9]/', 'a', Option::none(),
27+
];
28+
yield 'Match' => [
29+
'/[0-9]/', '1', Option::some('1'),
30+
];
31+
yield 'Capturing group' => [
32+
'/([0-9])([a-z])/', '1a', Option::some('a'), 2,
33+
];
34+
yield 'Named capturing group' => [
35+
'/(?<num>[0-9])(?<str>[a-z])/', '1a', Option::some('a'), 'str',
36+
];
37+
}
38+
}

0 commit comments

Comments
 (0)