Skip to content

Commit

Permalink
test more quantifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed May 18, 2024
1 parent 228bdfe commit 47982b5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/PHPStan/Analyser/data/preg_match_shapes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,36 @@ function doMatch(string $s): void {
assertType('array{0: string, 1: string, 2: string, 3?: string, 4?: string}', $matches);
}
assertType('array<string>', $matches);

if (preg_match('/(a|b)|(?:c)/', $s, $matches)) {
assertType('array{0: string, 1?: string}', $matches);
}
assertType('array<string>', $matches);

if (preg_match('/(foo)(bar)(baz)+/', $s, $matches)) {
assertType('array{string, string, string, string}', $matches);
}
assertType('array<string>', $matches);

if (preg_match('/(foo)(bar)(baz)*/', $s, $matches)) {
assertType('array{0: string, 1: string, 2: string, 3?: string}', $matches);
}
assertType('array<string>', $matches);

if (preg_match('/(foo)(bar)(baz)?/', $s, $matches)) {
assertType('array{0: string, 1: string, 2: string, 3?: string}', $matches);
}
assertType('array<string>', $matches);

if (preg_match('/(foo)(bar)(baz){0,3}/', $s, $matches)) {
assertType('array{0: string, 1: string, 2: string, 3?: string}', $matches);
}
assertType('array<string>', $matches);

if (preg_match('/(foo)(bar)(baz){2,3}/', $s, $matches)) {
assertType('array{string, string, string, string}', $matches);
}
assertType('array<string>', $matches);
}

function doNonCapturingGroup(string $s): void {
Expand Down

0 comments on commit 47982b5

Please sign in to comment.