Skip to content

Commit bc262fb

Browse files
committed
Tests/Tokenizer: fix bug in the default keyword tests
This commit fixes a bug in `RecurseScopeMapDefaultKeywordConditionsTest ::testSwitchDefault()`. Among other things, this method checks whether tokens within the scope of a `default` have `T_DEFAULT` set as the scope condition. Due to a bug, `testSwitchDefault()` would never check if the scope condition is set for the tokens within the scope of a `T_DEFAULT` token when `$conditionStop` is not `null`. `$conditionStop` is used when `T_DEFAULT` uses curlies to open and close the scope. In those cases, scope conditions are not set all the way until the scope closer. Instead, they are only until just before a T_BREAK|T_RETURN|T_CONTINUE. `simple_switch_default_with_curlies` test case is the only one that currently sets `$conditionStop` to something other than `null`. But it passes an offset value of the condition stop while the code was expecting an absolute value of the index of the token where the scope condition stops being set. Passing an offset meant that when `$end` was set to be equal to `$conditionStop` it would always be less than `$i` and the assertion inside the `for` loop would never run. The code was now changed to calculate the correct value for `$end` when `$conditionStop` is not null. It was also necessary to update the value for `$conditionStop` in `simple_switch_default_with_curlies` as it was pointing to the wrong token. This uncovered an inconsistency in the tokenizer that might need to be addressed in a separate issue. When `T_DEFAULT` doesn't use curlies the tokenizer sets `scope_condition` for all the tokens until the token just before `T_BREAK|T_RETURN|T_CONTINUE`. But when there are curlies, `scope_condition` is set including for `T_BREAK|T_RETURN|T_CONTINUE`. It needs to be determined if this behavior is intentional or not.
1 parent fb77fa3 commit bc262fb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/Core/Tokenizers/Tokenizer/RecurseScopeMapDefaultKeywordConditionsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function testSwitchDefault($testMarker, $openerOffset, $closerOffset, $co
166166
if (($opener + 1) !== $closer) {
167167
$end = $closer;
168168
if (isset($conditionStop) === true) {
169-
$end = $conditionStop;
169+
$end = ($opener + $conditionStop);
170170
}
171171

172172
for ($i = ($opener + 1); $i < $end; $i++) {
@@ -204,7 +204,7 @@ public static function dataSwitchDefault()
204204
'testMarker' => '/* testSimpleSwitchDefaultWithCurlies */',
205205
'openerOffset' => 3,
206206
'closerOffset' => 12,
207-
'conditionStop' => 6,
207+
'conditionStop' => 3,
208208
],
209209
'switch_default_toplevel' => [
210210
'testMarker' => '/* testSwitchDefault */',

0 commit comments

Comments
 (0)