|
9 | 9 | function doMatch(string $s): void
|
10 | 10 | {
|
11 | 11 | if (Preg::match('/Price: /i', $s, $matches)) {
|
12 |
| - assertType('array{string}', $matches); |
| 12 | + assertType('array{non-falsy-string}', $matches); |
13 | 13 | } else {
|
14 | 14 | assertType('array{}', $matches);
|
15 | 15 | }
|
16 |
| - assertType('array{}|array{string}', $matches); |
| 16 | + assertType('array{}|array{non-falsy-string}', $matches); |
17 | 17 |
|
18 | 18 | if (Preg::match('/Price: (£|€)\d+/', $s, $matches)) {
|
19 |
| - assertType('array{string, \'£\'|\'€\'}', $matches); |
| 19 | + assertType('array{non-falsy-string, \'£\'|\'€\'}', $matches); |
20 | 20 | } else {
|
21 | 21 | assertType('array{}', $matches);
|
22 | 22 | }
|
23 |
| - assertType('array{}|array{string, \'£\'|\'€\'}', $matches); |
| 23 | + assertType('array{}|array{non-falsy-string, \'£\'|\'€\'}', $matches); |
24 | 24 |
|
25 | 25 | if (Preg::match('/Price: (£|€)?\d+/', $s, $matches)) {
|
26 |
| - assertType('array{string, \'£\'|\'€\'|null}', $matches); |
| 26 | + assertType('array{non-falsy-string, \'£\'|\'€\'|null}', $matches); |
27 | 27 | } else {
|
28 | 28 | assertType('array{}', $matches);
|
29 | 29 | }
|
30 |
| - assertType('array{}|array{string, \'£\'|\'€\'|null}', $matches); |
| 30 | + assertType('array{}|array{non-falsy-string, \'£\'|\'€\'|null}', $matches); |
31 | 31 |
|
32 | 32 | // passing the PREG_UNMATCHED_AS_NULL should change nothing compared to above as it is always set
|
33 | 33 | if (Preg::match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
|
34 |
| - assertType('array{string, \'£\'|\'€\'|null}', $matches); |
| 34 | + assertType('array{non-falsy-string, \'£\'|\'€\'|null}', $matches); |
35 | 35 | } else {
|
36 | 36 | assertType('array{}', $matches);
|
37 | 37 | }
|
38 |
| - assertType('array{}|array{string, \'£\'|\'€\'|null}', $matches); |
| 38 | + assertType('array{}|array{non-falsy-string, \'£\'|\'€\'|null}', $matches); |
39 | 39 |
|
40 | 40 | if (Preg::isMatch('/Price: (?<currency>£|€)\d+/', $s, $matches)) {
|
41 |
| - assertType('array{0: string, currency: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches); |
| 41 | + assertType('array{0: non-falsy-string, currency: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches); |
42 | 42 | } else {
|
43 | 43 | assertType('array{}', $matches);
|
44 | 44 | }
|
45 |
| - assertType('array{}|array{0: string, currency: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches); |
| 45 | + assertType('array{}|array{0: non-falsy-string, currency: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches); |
46 | 46 | }
|
47 | 47 |
|
48 | 48 | function doMatchStrictGroups(string $s): void
|
49 | 49 | {
|
50 | 50 | if (Preg::matchStrictGroups('/Price: /i', $s, $matches)) {
|
51 |
| - assertType('array{string}', $matches); |
| 51 | + assertType('array{non-falsy-string}', $matches); |
52 | 52 | } else {
|
53 | 53 | assertType('array{}', $matches);
|
54 | 54 | }
|
55 |
| - assertType('array{}|array{string}', $matches); |
| 55 | + assertType('array{}|array{non-falsy-string}', $matches); |
56 | 56 |
|
57 | 57 | if (Preg::matchStrictGroups('/Price: (£|€)\d+/', $s, $matches)) {
|
58 |
| - assertType('array{string, \'£\'|\'€\'}', $matches); |
| 58 | + assertType('array{non-falsy-string, \'£\'|\'€\'}', $matches); |
59 | 59 | } else {
|
60 | 60 | assertType('array{}', $matches);
|
61 | 61 | }
|
62 |
| - assertType('array{}|array{string, \'£\'|\'€\'}', $matches); |
| 62 | + assertType('array{}|array{non-falsy-string, \'£\'|\'€\'}', $matches); |
63 | 63 |
|
64 | 64 | if (Preg::isMatchStrictGroups('/Price: (?<test>£|€)\d+/', $s, $matches)) {
|
65 |
| - assertType('array{0: string, test: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches); |
| 65 | + assertType('array{0: non-falsy-string, test: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches); |
66 | 66 | } else {
|
67 | 67 | assertType('array{}', $matches);
|
68 | 68 | }
|
69 |
| - assertType('array{}|array{0: string, test: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches); |
| 69 | + assertType('array{}|array{0: non-falsy-string, test: \'£\'|\'€\', 1: \'£\'|\'€\'}', $matches); |
70 | 70 | }
|
71 | 71 |
|
72 | 72 | function doMatchStrictGroupsUnsafe(string $s): void
|
73 | 73 | {
|
74 | 74 | if (Preg::isMatchStrictGroups('{Configure Command(?: *</td><td class="v">| *=> *)(.*)(?:</td>|$)}m', $s, $matches)) {
|
75 | 75 | // does not error because the match group might be empty but is not optional
|
76 |
| - assertType('array{string, string}', $matches); |
| 76 | + assertType('array{non-falsy-string, string}', $matches); |
77 | 77 | }
|
78 | 78 |
|
79 | 79 | // should error as it is unsafe due to the optional group 1
|
|
0 commit comments