Skip to content

Commit ac871af

Browse files
committed
verify indexes
1 parent 2733157 commit ac871af

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/PHPStan/Parser/TypeParserTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,40 @@ public function testVerifyAttributes(string $input, $expectedResult): void
140140
$this->assertNotNull($node->getAttribute(Attribute::END_INDEX), (string) $node);
141141
}
142142

143+
$this->verifyNodeIndexes($node);
144+
143145
$this->assertEquals(
144146
$this->unsetAllAttributesButComments($expectedResult),
145147
$this->unsetAllAttributesButComments($typeNode),
146148
);
147149
}
148150

149151

152+
private function verifyNodeIndexes(Node $node): void
153+
{
154+
$subNodeNames = array_keys(get_object_vars($node));
155+
foreach ($subNodeNames as $subNodeName) {
156+
$subNode = $node->$subNodeName;
157+
if (is_array($subNode)) {
158+
$lastEndIndex = null;
159+
foreach ($subNode as $subSubNode) {
160+
$startIndex = $subSubNode->getAttribute(Attribute::START_INDEX);
161+
$endIndex = $subSubNode->getAttribute(Attribute::END_INDEX);
162+
if ($lastEndIndex !== null) {
163+
$this->assertGreaterThan($startIndex, $lastEndIndex, (string) $subSubNode);
164+
}
165+
166+
$lastEndIndex = $endIndex;
167+
168+
$this->verifyNodeIndexes($subSubNode);
169+
}
170+
} elseif ($subNode instanceof Node) {
171+
$this->verifyNodeIndexes($subNode);
172+
}
173+
}
174+
}
175+
176+
150177
private function unsetAllAttributes(Node $node): Node
151178
{
152179
$visitor = new class extends AbstractNodeVisitor {

0 commit comments

Comments
 (0)