forked from composer/pcre
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreg-match.php
50 lines (43 loc) · 1.34 KB
/
preg-match.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace PregMatchShapes;
use Composer\Pcre\Preg;
use function PHPStan\Testing\assertType;
function doMatch(string $s): void
{
if (Preg::match('/Price: /i', $s, $matches)) {
assertType('array{string}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string}', $matches);
if (Preg::match('/Price: (£|€)\d+/', $s, $matches)) {
assertType('array{string, string|null}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string, string|null}', $matches);
if (Preg::match('/Price: (£|€)?\d+/', $s, $matches)) {
assertType('array{0: string, 1?: string|null}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{0: string, 1?: string|null}', $matches);
}
function identicalMatch(string $s): void
{
if (Preg::match('/Price: /i', $s, $matches) === 1) {
assertType('array{string}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string}', $matches);
}
function equalMatch(string $s): void
{
if (Preg::match('/Price: /i', $s, $matches) == 1) {
assertType('array{string}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string}', $matches);
}