Skip to content

Commit 0244678

Browse files
rodrigoprimojrfnl
authored andcommitted
Tests/Tokenizer: add three more test cases to the switch keyword tests
This commit expands a bit the switch keyword tests by adding three more test cases: - switch with closure containing return type in the condition - switch with arrow function in the condition - switch with arrow function containing return type in the condition
1 parent 7954ce3 commit 0244678

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.inc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,28 @@ switch((function () {
3333
return 'test';
3434
/* testSwitchClosureWithinConditionScopeCloser */
3535
}
36+
37+
/* testSwitchClosureWithReturnTypeWithinCondition */
38+
switch((function (): string {
39+
return 'bar';
40+
})()) /* testSwitchClosureWithReturnTypeWithinConditionScopeOpener */ :
41+
/* testSwitchClosureWithReturnTypeWithinConditionEnsureTestWillNotPickUpWrongColon */
42+
case 1:
43+
return 'test';
44+
/* testSwitchClosureWithReturnTypeWithinConditionScopeCloser */
45+
endswitch;
46+
47+
/* testSwitchArrowFunctionWithinCondition */
48+
switch((fn() => $obj->{$foo . $bar})()) /* testSwitchArrowFunctionWithinConditionScopeOpener */ {
49+
case 1:
50+
return 'test';
51+
/* testSwitchArrowFunctionWithinConditionScopeCloser */
52+
}
53+
54+
/* testSwitchArrowFunctionWithReturnTypeWithinCondition */
55+
switch((fn(): string => $condition ? 'foo' : 'bar')()) /* testSwitchArrowFunctionWithReturnTypeWithinConditionScopeOpener */ :
56+
/* testSwitchArrowFunctionWithReturnTypeWithinConditionEnsureTestWillNotPickUpWrongColon */
57+
case 1:
58+
return 'test';
59+
/* testSwitchArrowFunctionWithReturnTypeWithinConditionScopeCloser */
60+
endswitch;

tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testSwitchScope($testMarker, $expectedTokens, $testOpenerMarker=
9797
public static function dataSwitchScope()
9898
{
9999
return [
100-
'switch normal syntax' => [
100+
'switch normal syntax' => [
101101
'testMarker' => '/* testSwitchNormalSyntax */',
102102
'expectedTokens' => [
103103
'scope_opener' => T_OPEN_CURLY_BRACKET,
@@ -106,7 +106,7 @@ public static function dataSwitchScope()
106106
'testOpenerMarker' => null,
107107
'testCloserMarker' => '/* testSwitchNormalSyntaxScopeCloser */',
108108
],
109-
'switch alternative syntax' => [
109+
'switch alternative syntax' => [
110110
'testMarker' => '/* testSwitchAlternativeSyntax */',
111111
'expectedTokens' => [
112112
'scope_opener' => T_COLON,
@@ -115,7 +115,7 @@ public static function dataSwitchScope()
115115
'testOpenerMarker' => null,
116116
'testCloserMarker' => '/* testSwitchAlternativeSyntaxScopeCloser */',
117117
],
118-
'switch with closure in the condition' => [
118+
'switch with closure in the condition' => [
119119
'testMarker' => '/* testSwitchClosureWithinCondition */',
120120
'expectedTokens' => [
121121
'scope_opener' => T_OPEN_CURLY_BRACKET,
@@ -124,6 +124,34 @@ public static function dataSwitchScope()
124124
'testOpenerMarker' => '/* testSwitchClosureWithinConditionScopeOpener */',
125125
'testCloserMarker' => '/* testSwitchClosureWithinConditionScopeCloser */',
126126
],
127+
'switch alternative syntax with closure containing return type in the condition' => [
128+
'testMarker' => '/* testSwitchClosureWithReturnTypeWithinCondition */',
129+
'expectedTokens' => [
130+
'scope_opener' => T_COLON,
131+
'scope_closer' => T_ENDSWITCH,
132+
],
133+
'testOpenerMarker' => '/* testSwitchClosureWithReturnTypeWithinConditionScopeOpener */',
134+
'testCloserMarker' => '/* testSwitchClosureWithReturnTypeWithinConditionScopeCloser */',
135+
],
136+
'switch with arrow function in the condition' => [
137+
'testMarker' => '/* testSwitchArrowFunctionWithinCondition */',
138+
'expectedTokens' => [
139+
'scope_opener' => T_OPEN_CURLY_BRACKET,
140+
'scope_closer' => T_CLOSE_CURLY_BRACKET,
141+
],
142+
'testOpenerMarker' => '/* testSwitchArrowFunctionWithinConditionScopeOpener */',
143+
'testCloserMarker' => '/* testSwitchArrowFunctionWithinConditionScopeCloser */',
144+
],
145+
'switch alternative syntax with arrow function containing return type in the condition' => [
146+
'testMarker' => '/* testSwitchArrowFunctionWithReturnTypeWithinCondition */',
147+
'expectedTokens' => [
148+
'scope_opener' => T_COLON,
149+
'scope_closer' => T_ENDSWITCH,
150+
],
151+
'testOpenerMarker' => '/* testSwitchArrowFunctionWithReturnTypeWithinConditionScopeOpener */',
152+
'testCloserMarker' => '/* testSwitchArrowFunctionWithReturnTypeWithinConditionScopeCloser */',
153+
],
154+
127155
];
128156

129157
}//end dataSwitchScope()

0 commit comments

Comments
 (0)