Tests/Tokenizer: fix conditions checking range in T_DEFAULT test#870
Conversation
There was a problem hiding this comment.
@rodrigoprimo To me, this change is difficult to grasp. As the bug is supposed to be with the curly braces (which use the $conditionStop variable), why are you changing the $end for non-curly braced expressions ?
It would seem more logical to me to change line 162 to $end = ($token + $conditionStop + 1);.
|
I considered changing line 162 to
That being said, I think both options are ok, and I'm happy to change to what you are suggesting if you prefer. |
|
@rodrigoprimo Maybe there shouldn't even be any change to the logic, just a change in how the |
|
@jrfnl, if you prefer this approach, that works for me, and I can update the PR. |
|
@rodrigoprimo I have no real preference, other than that the commit message matches what the PR does and that's not the case with the current fix. |
Among other things, the RecurseScopeMapDefaultKeywordConditionsTest ::testSwitchDefault() method checks if tokens within the scope of a `T_DEFAULT` token have `T_DEFAULT` set as one of its `conditions` array. The test was incorrectly checking token `conditions` due to an off-by-one error in the loop range when the `T_DEFAULT` uses curly braces. For a `T_DEFAULT` with curly braces, the tokenizer adds `T_DEFAULT` to the `conditions` array of all the tokens within its scope up to the `T_BREAK|T_RETURN|T_CONTINUE`, but the test was checking only until the token before the `T_BREAK|T_RETURN|T_CONTINUE`.
7723d59 to
c07267e
Compare
|
@jrfnl, I went with your first suggestion and changed line 162 to |
Description
This PR addresses an issue that I missed when working on #850. Among other things, the
RecurseScopeMapDefaultKeywordConditionsTest ::testSwitchDefault()method checks if tokens within the scope of aT_DEFAULTtoken haveT_DEFAULTset as one of itsconditionsarray.The test incorrectly checked token
conditionsdue to an off-by-one error in the loop range when theT_DEFAULTuses curly braces.For a
T_DEFAULTwith curly braces, the tokenizer addsT_DEFAULTto theconditionsarray of all the tokens within its scope up to theT_BREAK|T_RETURN|T_CONTINUE, but the test was checking only until the token before theT_BREAK|T_RETURN|T_CONTINUE. While for aT_DEFAULTwithout curly braces, it adds to all the tokens within the scope until the token before the scope closer.This commit updates the test to ensure that all tokens within a default case scope that should have the
T_DEFAULTtoken in theirconditionsarray are properly checked. To achieve that, the loop was modified:$closer - 1when curly braces are not used.$endis also checked.Types of changes
PR checklist