Skip to content

Commit 5468a8d

Browse files
committed
OtherContextSensitiveKeywordsTest: add silly number of extra tests
... to safeguard that the `true`/`false`/`null`/`self`/`parent` keywords, when used in type declarations, are correctly tokenized.
1 parent 30b3148 commit 5468a8d

File tree

2 files changed

+523
-33
lines changed

2 files changed

+523
-33
lines changed

tests/Core/Tokenizer/OtherContextSensitiveKeywordsTest.inc

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,141 @@ class TypedConstProp {
6565
var /* testSelfIsKeywordAsPropertyType */ self $self = new /* testSelfIsKeywordAsPropertyDefault */ self;
6666
protected /* testParentIsKeywordAsPropertyType */ parent $parent = new /* testParentIsKeywordAsPropertyDefault */ parent;
6767
}
68+
69+
class UseInUnionTypes {
70+
/* testFalseIsKeywordAsConstUnionTypeFirst */
71+
const false|Foo UNION_WITH_FALSE_FIRST = SOMETHING;
72+
/* testTrueIsKeywordAsConstUnionTypeFirst */
73+
const true|string UNION_WITH_TRUE_FIRST = SOMETHING;
74+
/* testNullIsKeywordAsConstUnionTypeFirst */
75+
const null|int UNION_WITH_NULL_FIRST = SOMETHING;
76+
/* testSelfIsKeywordAsConstUnionTypeFirst */
77+
const self|Foo UNION_WITH_SELF_FIRST = SOMETHING;
78+
/* testParentIsKeywordAsConstUnionTypeFirst */
79+
const parent|Bar UNION_WITH_PARENT_FIRST = SOMETHING;
80+
81+
const int|/* testFalseIsKeywordAsConstUnionTypeMiddle */false|string UNION_WITH_FALSE_MIDDLE = SOMETHING;
82+
const bool|/* testTrueIsKeywordAsConstUnionTypeMiddle */ true|Stringable UNION_WITH_TRUE_MIDDLE = SOMETHING;
83+
const object|/* testNullIsKeywordAsConstUnionTypeMiddle */null|iterable UNION_WITH_NULL_MIDDLE = SOMETHING;
84+
const array | /* testSelfIsKeywordAsConstUnionTypeMiddle */ self | /*comment*/ string UNION_WITH_SELF_MIDDLE = SOMETHING;
85+
const Foo|/* testParentIsKeywordAsConstUnionTypeMiddle */parent|float UNION_WITH_PARENT_MIDDLE = SOMETHING;
86+
87+
const string|/* testFalseIsKeywordAsConstUnionTypeLast */false UNION_WITH_FALSE_LAST = SOMETHING;
88+
const float|/* testTrueIsKeywordAsConstUnionTypeLast */true UNION_WITH_TRUE_LAST = SOMETHING;
89+
const Something|/* testNullIsKeywordAsConstUnionTypeLast */null UNION_WITH_NULL_LAST = SOMETHING;
90+
const Foo|/* testSelfIsKeywordAsConstUnionTypeLast */self UNION_WITH_SELF_LAST = SOMETHING;
91+
const Bar|/* testParentIsKeywordAsConstUnionTypeLast */parent UNION_WITH_PARENT_LAST = SOMETHING;
92+
93+
/* testFalseIsKeywordAsPropertyUnionTypeFirst */
94+
public false|string $false = SOMETHING;
95+
/* testTrueIsKeywordAsPropertyUnionTypeFirst */
96+
protected readonly true|int $true = SOMETHING;
97+
/* testNullIsKeywordAsPropertyUnionTypeFirst */
98+
static private null|object $null = SOMETHING;
99+
/* testSelfIsKeywordAsPropertyUnionTypeFirst */
100+
var self|iterable $self = SOMETHING;
101+
/* testParentIsKeywordAsPropertyUnionTypeFirst */
102+
protected parent|array $parent = SOMETHING;
103+
104+
public Foo|/* testFalseIsKeywordAsPropertyUnionTypeMiddle */false|Bar $false = SOMETHING;
105+
protected readonly Foo|/* testTrueIsKeywordAsPropertyUnionTypeMiddle */true|Bar $true = SOMETHING;
106+
static private Foo/* testNullIsKeywordAsPropertyUnionTypeMiddle */|null|Bar $null = SOMETHING;
107+
var Foo|/* testSelfIsKeywordAsPropertyUnionTypeMiddle */self|Bar $self = SOMETHING;
108+
protected Foo/* testParentIsKeywordAsPropertyUnionTypeMiddle */|parent|Bar $parent = SOMETHING;
109+
110+
public array|/* testFalseIsKeywordAsPropertyUnionTypeLast */false $false = SOMETHING;
111+
protected readonly string /* testTrueIsKeywordAsPropertyUnionTypeLast */| true $true = SOMETHING;
112+
static private int|/* testNullIsKeywordAsPropertyUnionTypeLast */null $null = SOMETHING;
113+
var object|/* testSelfIsKeywordAsPropertyUnionTypeLast */self $self = SOMETHING;
114+
protected Foo/* testParentIsKeywordAsPropertyUnionTypeLast */|parent $parent = SOMETHING;
115+
116+
function KeywordsInParamUnionTypeFirst(
117+
/* testFalseIsKeywordAsParamUnionTypeFirst */ false|Foo $paramA,
118+
/* testTrueIsKeywordAsParamUnionTypeFirst */ true|string $paramB,
119+
/* testNullIsKeywordAsParamUnionTypeFirst */ null|Bar $paramC,
120+
/* testSelfIsKeywordAsParamUnionTypeFirst */ self|float $paramD,
121+
/* testParentIsKeywordAsParamUnionTypeFirst */ parent|object $paramE,
122+
) {}
123+
124+
function KeywordsInParamUnionTypeMiddle(
125+
Foo/* testFalseIsKeywordAsParamUnionTypeMiddle */|false|Bar $paramA,
126+
Foo|/* testTrueIsKeywordAsParamUnionTypeMiddle */ true|Bar $paramB,
127+
Foo/* testNullIsKeywordAsParamUnionTypeMiddle */ |null|Bar $paramC,
128+
Foo|/* testSelfIsKeywordAsParamUnionTypeMiddle */ self|Bar $paramD,
129+
Foo/* testParentIsKeywordAsParamUnionTypeMiddle */ |parent|Bar $paramE
130+
) {}
131+
132+
function KeywordsInParamUnionTypeLast (
133+
string|/* testFalseIsKeywordAsParamUnionTypeLast */ false $paramA,
134+
Something/* testTrueIsKeywordAsParamUnionTypeLast */ |true $paramB,
135+
bool|/* testNullIsKeywordAsParamUnionTypeLast */ null $paramC,
136+
MeMe/* testSelfIsKeywordAsParamUnionTypeLast */ |self $paramD,
137+
int|/* testParentIsKeywordAsParamUnionTypeLast */ parent $paramE,
138+
) {}
139+
140+
function FalseIsKeywordInReturnTypeFirst(): /* testFalseIsKeywordAsReturnUnionTypeFirst */ false|int {}
141+
function TrueIsKeywordInReturnTypeFirst(): /* testTrueIsKeywordAsReturnUnionTypeFirst */ true|bool {}
142+
function NullIsKeywordInReturnTypeFirst(): /* testNullIsKeywordAsReturnUnionTypeFirst */ null|float {}
143+
function SelfIsKeywordInReturnTypeFirst(): /* testSelfIsKeywordAsReturnUnionTypeFirst */ self|object {}
144+
function ParentIsKeywordInReturnTypeFirst(): /* testParentIsKeywordAsReturnUnionTypeFirst */ parent|iterable {}
145+
146+
function FalseIsKeywordInReturnTypeMiddle(): Foo|/* testFalseIsKeywordAsReturnUnionTypeMiddle */ false|Bar {}
147+
function TrueIsKeywordInReturnTypeMiddle(): Foo/* testTrueIsKeywordAsReturnUnionTypeMiddle */ |true|Bar {}
148+
function NullIsKeywordInReturnTypeMiddle(): Foo|/* testNullIsKeywordAsReturnUnionTypeMiddle */null|Bar {}
149+
function SelfIsKeywordInReturnTypeMiddle(): Foo /* testSelfIsKeywordAsReturnUnionTypeMiddle */ |self|Bar {}
150+
function ParentIsKeywordInReturnTypeMiddle(): Foo| /* testParentIsKeywordAsReturnUnionTypeMiddle */ parent|Bar {}
151+
152+
function FalseIsKeywordInReturnTypeLast(): void|/* testFalseIsKeywordAsReturnUnionTypeLast */false {}
153+
function TrueIsKeywordInReturnTypeLast(): Bar|/* testTrueIsKeywordAsReturnUnionTypeLast */true {}
154+
function NullIsKeywordInReturnTypeLast(): string/* testNullIsKeywordAsReturnUnionTypeLast */|null {}
155+
function SelfIsKeywordInReturnTypeLast(): Foo|/* testSelfIsKeywordAsReturnUnionTypeLast */self {}
156+
function ParentIsKeywordInReturnTypeLast(): bool/* testParentIsKeywordAsReturnUnionTypeLast */|parent {}
157+
}
158+
159+
class UseInIntersectionTypes {
160+
/* testSelfIsKeywordAsConstIntersectionTypeFirst */
161+
const self&Foo INTERSECTION_SELF_FIRST = SOMETHING;
162+
/* testParentIsKeywordAsConstIntersectionTypeFirst */
163+
const parent&Bar INTERSECTION_PARENT_FIRST = SOMETHING;
164+
165+
const Foo&/* testSelfIsKeywordAsConstIntersectionTypeMiddle */self&Bar INTERSECTION_SELF_MIDDLE = SOMETHING;
166+
const Foo/* testParentIsKeywordAsConstIntersectionTypeMiddle */&parent&Bar INTERSECTION_PARENT_MIDDLE = SOMETHING;
167+
168+
const Foo&/* testSelfIsKeywordAsConstIntersectionTypeLast */self INTERSECTION_SELF_LAST = SOMETHING;
169+
const Bar/* testParentIsKeywordAsConstIntersectionTypeLast */&parent INTERSECTION_PARENT_LAST = SOMETHING;
170+
171+
/* testSelfIsKeywordAsPropertyIntersectionTypeFirst */
172+
var self&Countable $self = SOMETHING;
173+
/* testParentIsKeywordAsPropertyIntersectionTypeFirst */
174+
protected parent&DateTime $parent = SOMETHING;
175+
176+
var Foo/* testSelfIsKeywordAsPropertyIntersectionTypeMiddle */&self&Bar $self = SOMETHING;
177+
protected Foo&/* testParentIsKeywordAsPropertyIntersectionTypeMiddle */parent&Bar $parent = SOMETHING;
178+
179+
var Exception/* testSelfIsKeywordAsPropertyIntersectionTypeLast */&self $self = SOMETHING;
180+
protected Foo&/* testParentIsKeywordAsPropertyIntersectionTypeLast */parent $parent = SOMETHING;
181+
182+
function KeywordsInParamIntersectionTypeFirst(
183+
/* testSelfIsKeywordAsParamIntersectionTypeFirst */ self&float $paramD,
184+
/* testParentIsKeywordAsParamIntersectionTypeFirst */ parent&object $paramE,
185+
) {}
186+
187+
function KeywordsInParamIntersectionTypeMiddle(
188+
Foo/* testSelfIsKeywordAsParamIntersectionTypeMiddle */ &self&Bar $paramD,
189+
Foo&/* testParentIsKeywordAsParamIntersectionTypeMiddle */ parent&Bar $paramE
190+
) {}
191+
192+
function KeywordsInParamIntersectionTypeLast (
193+
MeMe/* testSelfIsKeywordAsParamIntersectionTypeLast */ &self $paramD,
194+
int&/* testParentIsKeywordAsParamIntersectionTypeLast */ parent $paramE
195+
) {}
196+
197+
function SelfIsKeywordInReturnTypeFirst()/* testSelfIsKeywordAsReturnIntersectionTypeFirst */: self&string {}
198+
function ParentIsKeywordInReturnTypeFirst():/* testParentIsKeywordAsReturnIntersectionTypeFirst */ parent&iterable {}
199+
200+
function SelfIsKeywordInReturnTypeMiddle(): Foo/* testSelfIsKeywordAsReturnIntersectionTypeMiddle */&self&Bar {}
201+
function ParentIsKeywordInReturnTypeMiddle(): Foo&/* testParentIsKeywordAsReturnIntersectionTypeMiddle */parent&Bar {}
202+
203+
function SelfIsKeywordInReturnTypeLast(): Foo&/* testSelfIsKeywordAsReturnIntersectionTypeLast */self {}
204+
function ParentIsKeywordInReturnTypeLast(): bool&/* testParentIsKeywordAsReturnIntersectionTypeLast */parent {}
205+
}

0 commit comments

Comments
 (0)