1 /**
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "lsp/include/internal_api.h"
17 #include "lsp/include/classifier.h"
18 #include "lsp_api_test.h"
19 #include "public/es2panda_lib.h"
20
21 using ark::es2panda::lsp::Initializer;
22
23 class LspClassificationTests : public LSPAPITests {};
24
TEST_F(LspClassificationTests,GetSyntacticClassifications1)25 TEST_F(LspClassificationTests, GetSyntacticClassifications1)
26 {
27 Initializer initializer = Initializer();
28 es2panda_Context *ctx = initializer.CreateContext("class-name.ets", ES2PANDA_STATE_PARSED, R"(class A {};)");
29 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
30
31 size_t const start = 6;
32 size_t const length = 1;
33 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
34 const size_t expectedCount = 1;
35 std::string expectedName = "class name";
36 ASSERT_EQ(result.size(), expectedCount);
37 ASSERT_EQ(result.at(0)->start, start);
38 ASSERT_EQ(result.at(0)->length, length);
39 ASSERT_EQ(result.at(0)->name, expectedName);
40 initializer.DestroyContext(ctx);
41 }
42
TEST_F(LspClassificationTests,GetSyntacticClassifications2)43 TEST_F(LspClassificationTests, GetSyntacticClassifications2)
44 {
45 Initializer initializer = Initializer();
46 es2panda_Context *ctx =
47 initializer.CreateContext("enum-name.ets", ES2PANDA_STATE_PARSED, R"(enum Color {Red, Blue, Green};)");
48 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
49
50 size_t const start = 5;
51 size_t const length = 5;
52 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
53 const size_t expectedCount = 1;
54 std::string expectedName = "enum name";
55 ASSERT_EQ(result.size(), expectedCount);
56 ASSERT_EQ(result.at(0)->start, start);
57 ASSERT_EQ(result.at(0)->length, length);
58 ASSERT_EQ(result.at(0)->name, expectedName);
59 initializer.DestroyContext(ctx);
60 }
61
TEST_F(LspClassificationTests,GetSyntacticClassifications3)62 TEST_F(LspClassificationTests, GetSyntacticClassifications3)
63 {
64 Initializer initializer = Initializer();
65 es2panda_Context *ctx =
66 initializer.CreateContext("interface-name.ets", ES2PANDA_STATE_PARSED, R"(interface I {};)");
67 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
68
69 size_t const start = 10;
70 size_t const length = 1;
71 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
72 const size_t expectedCount = 1;
73 std::string expectedName = "interface name";
74 ASSERT_EQ(result.size(), expectedCount);
75 ASSERT_EQ(result.at(0)->start, start);
76 ASSERT_EQ(result.at(0)->length, length);
77 ASSERT_EQ(result.at(0)->name, expectedName);
78 initializer.DestroyContext(ctx);
79 }
80
TEST_F(LspClassificationTests,GetSyntacticClassifications4)81 TEST_F(LspClassificationTests, GetSyntacticClassifications4)
82 {
83 Initializer initializer = Initializer();
84 es2panda_Context *ctx =
85 initializer.CreateContext("type-parameter-name.ets", ES2PANDA_STATE_PARSED, R"(class Foo<T> {};)");
86 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
87
88 size_t const start = 10;
89 size_t const length = 1;
90 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
91 const size_t expectedCount = 1;
92 std::string expectedName = "type parameter name";
93 ASSERT_EQ(result.size(), expectedCount);
94 ASSERT_EQ(result.at(0)->start, start);
95 ASSERT_EQ(result.at(0)->length, length);
96 ASSERT_EQ(result.at(0)->name, expectedName);
97 initializer.DestroyContext(ctx);
98 }
99
TEST_F(LspClassificationTests,GetSyntacticClassifications5)100 TEST_F(LspClassificationTests, GetSyntacticClassifications5)
101 {
102 Initializer initializer = Initializer();
103 es2panda_Context *ctx =
104 initializer.CreateContext("type-alias-name.ets", ES2PANDA_STATE_PARSED, R"(type tmp = Long|null;)");
105 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
106
107 size_t const start = 5;
108 size_t const length = 3;
109 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
110 const size_t expectedCount = 1;
111 std::string expectedName = "type alias name";
112 ASSERT_EQ(result.size(), expectedCount);
113 ASSERT_EQ(result.at(0)->start, start);
114 ASSERT_EQ(result.at(0)->length, length);
115 ASSERT_EQ(result.at(0)->name, expectedName);
116 initializer.DestroyContext(ctx);
117 }
118
TEST_F(LspClassificationTests,GetSyntacticClassifications6)119 TEST_F(LspClassificationTests, GetSyntacticClassifications6)
120 {
121 Initializer initializer = Initializer();
122 es2panda_Context *ctx =
123 initializer.CreateContext("parameter-name.ets", ES2PANDA_STATE_PARSED, R"(function A(a:number) {};)");
124 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
125
126 size_t const start = 11;
127 size_t const length = 1;
128 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
129 const size_t expectedCount = 1;
130 std::string expectedName = "parameter name";
131 ASSERT_EQ(result.size(), expectedCount);
132 ASSERT_EQ(result.at(0)->start, start);
133 ASSERT_EQ(result.at(0)->length, length);
134 ASSERT_EQ(result.at(0)->name, expectedName);
135 initializer.DestroyContext(ctx);
136 }
137
TEST_F(LspClassificationTests,GetSyntacticClassifications7)138 TEST_F(LspClassificationTests, GetSyntacticClassifications7)
139 {
140 Initializer initializer = Initializer();
141 es2panda_Context *ctx = initializer.CreateContext("number-type.ets", ES2PANDA_STATE_PARSED, R"(let num = 1;)");
142 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
143
144 size_t const start = 10;
145 size_t const length = 1;
146 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
147 const size_t expectedCount = 1;
148 std::string expectedName = "number";
149 ASSERT_EQ(result.size(), expectedCount);
150 ASSERT_EQ(result.at(0)->start, start);
151 ASSERT_EQ(result.at(0)->length, length);
152 ASSERT_EQ(result.at(0)->name, expectedName);
153 initializer.DestroyContext(ctx);
154 }
155
TEST_F(LspClassificationTests,GetSyntacticClassifications8)156 TEST_F(LspClassificationTests, GetSyntacticClassifications8)
157 {
158 Initializer initializer = Initializer();
159 es2panda_Context *ctx = initializer.CreateContext("string-type.ets", ES2PANDA_STATE_PARSED, R"(let str = "123";)");
160 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
161
162 size_t const start = 10;
163 size_t const length = 5;
164 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
165 const size_t expectedCount = 1;
166 std::string expectedName = "string";
167 ASSERT_EQ(result.size(), expectedCount);
168 ASSERT_EQ(result.at(0)->start, start);
169 ASSERT_EQ(result.at(0)->length, length);
170 ASSERT_EQ(result.at(0)->name, expectedName);
171 initializer.DestroyContext(ctx);
172 }
173
TEST_F(LspClassificationTests,GetSyntacticClassifications9)174 TEST_F(LspClassificationTests, GetSyntacticClassifications9)
175 {
176 Initializer initializer = Initializer();
177 es2panda_Context *ctx = initializer.CreateContext("boolean-type.ets", ES2PANDA_STATE_PARSED, R"(let a = true;
178 let b = false;)");
179 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
180
181 size_t const start = 0;
182 size_t const length = 28;
183 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
184 // NOLINTBEGIN(readability-magic-numbers)
185 std::vector<std::tuple<size_t, size_t, std::string>> expectedResult = {
186 {0, 3, "keyword"}, {4, 1, "identifier"}, {6, 1, "punctuation"}, {8, 4, "boolean"}, {12, 1, "punctuation"},
187 {14, 3, "keyword"}, {18, 1, "identifier"}, {20, 1, "punctuation"}, {22, 5, "boolean"}, {27, 1, "punctuation"}};
188 // NOLINTEND(readability-magic-numbers)
189 ASSERT_EQ(result.size(), expectedResult.size());
190
191 for (size_t i = 0; i < result.size(); i++) {
192 auto expectedStart = std::get<0>(expectedResult.at(i));
193 auto expectedLength = std::get<1>(expectedResult.at(i));
194 auto expectedName = std::get<2>(expectedResult.at(i));
195 ASSERT_EQ(result.at(i)->start, expectedStart);
196 ASSERT_EQ(result.at(i)->length, expectedLength);
197 ASSERT_EQ(result.at(i)->name, expectedName);
198 }
199 initializer.DestroyContext(ctx);
200 }
201
TEST_F(LspClassificationTests,GetSyntacticClassifications10)202 TEST_F(LspClassificationTests, GetSyntacticClassifications10)
203 {
204 Initializer initializer = Initializer();
205 es2panda_Context *ctx = initializer.CreateContext("null-type.ets", ES2PANDA_STATE_PARSED, R"(type tmp = null;)");
206 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
207
208 size_t const start = 0;
209 size_t const length = 28;
210 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
211 // NOLINTBEGIN(readability-magic-numbers)
212 std::vector<std::tuple<size_t, size_t, std::string>> expectedResult = {
213 {0, 4, "keyword"}, {5, 3, "type alias name"}, {9, 1, "punctuation"}, {11, 4, "null"}, {15, 1, "punctuation"}};
214 // NOLINTEND(readability-magic-numbers)
215 ASSERT_EQ(result.size(), expectedResult.size());
216
217 for (size_t i = 0; i < result.size(); i++) {
218 auto expectedStart = std::get<0>(expectedResult.at(i));
219 auto expectedLength = std::get<1>(expectedResult.at(i));
220 auto expectedName = std::get<2>(expectedResult.at(i));
221 ASSERT_EQ(result.at(i)->start, expectedStart);
222 ASSERT_EQ(result.at(i)->length, expectedLength);
223 ASSERT_EQ(result.at(i)->name, expectedName);
224 }
225 initializer.DestroyContext(ctx);
226 }
227
TEST_F(LspClassificationTests,GetSyntacticClassifications11)228 TEST_F(LspClassificationTests, GetSyntacticClassifications11)
229 {
230 Initializer initializer = Initializer();
231 es2panda_Context *ctx = initializer.CreateContext(
232 "punctuator-type1.ets", ES2PANDA_STATE_PARSED,
233 "let a = 1;\nlet b = 2;\nclass C {foo(){}};\nlet c = new C();\na + b;\na & b;\na += b;\na |= b;\na &= b;\na < "
234 "b;\nc?.foo;\na - b;\na | b;\na -= b;\na ^= b;\na && b;\na > b;\n!a;\na * b;\na ^ b;\na *= b;\na <<= b;\na || "
235 "b;\n");
236 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
237 size_t const start = 0;
238 size_t const length = 428;
239 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
240 // NOLINTBEGIN(readability-magic-numbers)
241 std::vector<std::tuple<size_t, size_t, std::string>> expectedResult = {
242 {0, 3, "keyword"}, {4, 1, "identifier"}, {6, 1, "punctuation"}, {8, 1, "number"},
243 {9, 1, "punctuation"}, {11, 3, "keyword"}, {15, 1, "identifier"}, {17, 1, "punctuation"},
244 {19, 1, "number"}, {20, 1, "punctuation"}, {22, 5, "keyword"}, {28, 1, "class name"},
245 {30, 1, "punctuation"}, {31, 3, "identifier"}, {34, 1, "punctuation"}, {35, 1, "punctuation"},
246 {36, 1, "punctuation"}, {37, 1, "punctuation"}, {38, 1, "punctuation"}, {39, 1, "punctuation"},
247 {41, 3, "keyword"}, {45, 1, "identifier"}, {47, 1, "punctuation"}, {49, 3, "keyword"},
248 {53, 1, "identifier"}, {54, 1, "punctuation"}, {55, 1, "punctuation"}, {56, 1, "punctuation"},
249 {58, 1, "identifier"}, {60, 1, "punctuation"}, {62, 1, "identifier"}, {63, 1, "punctuation"},
250 {65, 1, "identifier"}, {67, 1, "punctuation"}, {69, 1, "identifier"}, {70, 1, "punctuation"},
251 {72, 1, "identifier"}, {74, 2, "punctuation"}, {77, 1, "identifier"}, {78, 1, "punctuation"},
252 {80, 1, "identifier"}, {82, 2, "punctuation"}, {85, 1, "identifier"}, {86, 1, "punctuation"},
253 {88, 1, "identifier"}, {90, 2, "punctuation"}, {93, 1, "identifier"}, {94, 1, "punctuation"},
254 {96, 1, "identifier"}, {98, 1, "punctuation"}, {100, 1, "identifier"}, {101, 1, "punctuation"},
255 {103, 1, "identifier"}, {104, 2, "punctuation"}, {106, 3, "identifier"}, {109, 1, "punctuation"},
256 {111, 1, "identifier"}, {113, 1, "punctuation"}, {115, 1, "identifier"}, {116, 1, "punctuation"},
257 {118, 1, "identifier"}, {120, 1, "punctuation"}, {122, 1, "identifier"}, {123, 1, "punctuation"},
258 {125, 1, "identifier"}, {127, 2, "punctuation"}, {130, 1, "identifier"}, {131, 1, "punctuation"},
259 {133, 1, "identifier"}, {135, 2, "punctuation"}, {138, 1, "identifier"}, {139, 1, "punctuation"},
260 {141, 1, "identifier"}, {143, 2, "punctuation"}, {146, 1, "identifier"}, {147, 1, "punctuation"},
261 {149, 1, "identifier"}, {151, 1, "punctuation"}, {153, 1, "identifier"}, {154, 1, "punctuation"},
262 {156, 1, "punctuation"}, {157, 1, "identifier"}, {158, 1, "punctuation"}, {160, 1, "identifier"},
263 {162, 1, "punctuation"}, {164, 1, "identifier"}, {165, 1, "punctuation"}, {167, 1, "identifier"},
264 {169, 1, "punctuation"}, {171, 1, "identifier"}, {172, 1, "punctuation"}, {174, 1, "identifier"},
265 {176, 2, "punctuation"}, {179, 1, "identifier"}, {180, 1, "punctuation"}, {182, 1, "identifier"},
266 {184, 3, "punctuation"}, {188, 1, "identifier"}, {189, 1, "punctuation"}, {191, 1, "identifier"},
267 {193, 2, "punctuation"}, {196, 1, "identifier"}, {197, 1, "punctuation"}};
268 // NOLINTEND(readability-magic-numbers)
269 ASSERT_EQ(result.size(), expectedResult.size());
270 for (size_t i = 0; i < result.size(); i++) {
271 auto expectedStart = std::get<0>(expectedResult.at(i));
272 auto expectedLength = std::get<1>(expectedResult.at(i));
273 auto expectedName = std::get<2>(expectedResult.at(i));
274 ASSERT_EQ(result.at(i)->start, expectedStart);
275 ASSERT_EQ(result.at(i)->length, expectedLength);
276 ASSERT_EQ(result.at(i)->name, expectedName);
277 }
278 initializer.DestroyContext(ctx);
279 }
280
TEST_F(LspClassificationTests,GetSyntacticClassifications12)281 TEST_F(LspClassificationTests, GetSyntacticClassifications12)
282 {
283 Initializer initializer = Initializer();
284 es2panda_Context *ctx = initializer.CreateContext(
285 "punctuator-type2.ets", ES2PANDA_STATE_PARSED,
286 "a === b;\na <= b;\na / b;\na >> b;\na /= b;\na >>= b;\na++;\na == b;\na >= b;\na % b;\na << b;\na %= "
287 "b;\na >>>= b;\na--;\na = b;\nlet var1: [number[]];\n(a);\nlet d:[];\n{a};\nc??b;\na != b;\na !== b;\n");
288 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_PARSED);
289 size_t const start = 0;
290 size_t const length = 428;
291 auto result = ark::es2panda::lsp::GetSyntacticClassifications(ctx, start, length);
292 // NOLINTBEGIN(readability-magic-numbers)
293 std::vector<std::tuple<size_t, size_t, std::string>> expectedResult = {
294 {0, 1, "identifier"}, {2, 3, "punctuation"}, {6, 1, "identifier"}, {7, 1, "punctuation"},
295 {9, 1, "identifier"}, {11, 2, "punctuation"}, {14, 1, "identifier"}, {15, 1, "punctuation"},
296 {17, 1, "identifier"}, {19, 1, "punctuation"}, {21, 1, "identifier"}, {22, 1, "punctuation"},
297 {24, 1, "identifier"}, {26, 2, "punctuation"}, {29, 1, "identifier"}, {30, 1, "punctuation"},
298 {32, 1, "identifier"}, {34, 2, "punctuation"}, {37, 1, "identifier"}, {38, 1, "punctuation"},
299 {40, 1, "identifier"}, {42, 3, "punctuation"}, {46, 1, "identifier"}, {47, 1, "punctuation"},
300 {49, 1, "identifier"}, {50, 2, "punctuation"}, {52, 1, "punctuation"}, {54, 1, "identifier"},
301 {56, 2, "punctuation"}, {59, 1, "identifier"}, {60, 1, "punctuation"}, {62, 1, "identifier"},
302 {64, 2, "punctuation"}, {67, 1, "identifier"}, {68, 1, "punctuation"}, {70, 1, "identifier"},
303 {72, 1, "punctuation"}, {74, 1, "identifier"}, {75, 1, "punctuation"}, {77, 1, "identifier"},
304 {79, 2, "punctuation"}, {82, 1, "identifier"}, {83, 1, "punctuation"}, {85, 1, "identifier"},
305 {87, 2, "punctuation"}, {90, 1, "identifier"}, {91, 1, "punctuation"}, {93, 1, "identifier"},
306 {95, 4, "punctuation"}, {100, 1, "identifier"}, {101, 1, "punctuation"}, {103, 1, "identifier"},
307 {104, 2, "punctuation"}, {106, 1, "punctuation"}, {108, 1, "identifier"}, {110, 1, "punctuation"},
308 {112, 1, "identifier"}, {113, 1, "punctuation"}, {115, 3, "keyword"}, {119, 4, "identifier"},
309 {123, 1, "punctuation"}, {125, 1, "punctuation"}, {126, 6, "identifier"}, {132, 1, "punctuation"},
310 {133, 1, "punctuation"}, {134, 1, "punctuation"}, {135, 1, "punctuation"}, {137, 1, "punctuation"},
311 {138, 1, "identifier"}, {139, 1, "punctuation"}, {140, 1, "punctuation"}, {142, 3, "keyword"},
312 {146, 1, "identifier"}, {147, 1, "punctuation"}, {148, 1, "punctuation"}, {149, 1, "punctuation"},
313 {150, 1, "punctuation"}, {152, 1, "punctuation"}, {153, 1, "identifier"}, {154, 1, "punctuation"},
314 {155, 1, "punctuation"}, {157, 1, "identifier"}, {158, 2, "punctuation"}, {160, 1, "identifier"},
315 {161, 1, "punctuation"}, {163, 1, "identifier"}, {165, 2, "punctuation"}, {168, 1, "identifier"},
316 {169, 1, "punctuation"}, {171, 1, "identifier"}, {173, 3, "punctuation"}, {177, 1, "identifier"},
317 {178, 1, "punctuation"}};
318 // NOLINTEND(readability-magic-numbers)
319 ASSERT_EQ(result.size(), expectedResult.size());
320 for (size_t i = 0; i < result.size(); i++) {
321 auto expectedStart = std::get<0>(expectedResult.at(i));
322 auto expectedLength = std::get<1>(expectedResult.at(i));
323 auto expectedName = std::get<2>(expectedResult.at(i));
324 ASSERT_EQ(result.at(i)->start, expectedStart);
325 ASSERT_EQ(result.at(i)->length, expectedLength);
326 ASSERT_EQ(result.at(i)->name, expectedName);
327 }
328 initializer.DestroyContext(ctx);
329 }
330
TEST_F(LspClassificationTests,GetSemanticClassifications1)331 TEST_F(LspClassificationTests, GetSemanticClassifications1)
332 {
333 Initializer initializer = Initializer();
334 es2panda_Context *ctx =
335 initializer.CreateContext("class-name.ets", ES2PANDA_STATE_CHECKED, "class Foo{};\nlet a:Foo = new Foo();");
336 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_CHECKED);
337
338 size_t const start = 19;
339 size_t const length = 3;
340 auto result = ark::es2panda::lsp::GetSemanticClassifications(ctx, start, length);
341
342 const size_t expectedCount = 1;
343 std::string expectedName = "class name";
344 ASSERT_EQ(result.size(), expectedCount);
345 ASSERT_EQ(result.at(0)->start, start);
346 ASSERT_EQ(result.at(0)->length, length);
347 ASSERT_EQ(result.at(0)->name, expectedName);
348 initializer.DestroyContext(ctx);
349 }
350
TEST_F(LspClassificationTests,GetSemanticClassifications2)351 TEST_F(LspClassificationTests, GetSemanticClassifications2)
352 {
353 Initializer initializer = Initializer();
354 es2panda_Context *ctx =
355 initializer.CreateContext("class-name.ets", ES2PANDA_STATE_CHECKED, "class Foo{};\nlet a:Foo = new Foo();");
356 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_CHECKED);
357
358 size_t const start = 29;
359 size_t const length = 3;
360 auto result = ark::es2panda::lsp::GetSemanticClassifications(ctx, start, length);
361
362 const size_t expectedCount = 1;
363 std::string expectedName = "class name";
364 ASSERT_EQ(result.size(), expectedCount);
365 ASSERT_EQ(result.at(0)->start, start);
366 ASSERT_EQ(result.at(0)->length, length);
367 ASSERT_EQ(result.at(0)->name, expectedName);
368 initializer.DestroyContext(ctx);
369 }
370
TEST_F(LspClassificationTests,GetSemanticClassifications3)371 TEST_F(LspClassificationTests, GetSemanticClassifications3)
372 {
373 Initializer initializer = Initializer();
374 es2panda_Context *ctx = initializer.CreateContext("enum-name.ets", ES2PANDA_STATE_CHECKED,
375 "enum Color {Red, Blue, Green};\nlet a:Color");
376 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_CHECKED);
377
378 size_t const start = 37;
379 size_t const length = 5;
380 auto result = ark::es2panda::lsp::GetSemanticClassifications(ctx, start, length);
381 const size_t expectedCount = 1;
382 std::string expectedName = "enum name";
383 ASSERT_EQ(result.size(), expectedCount);
384 ASSERT_EQ(result.at(0)->start, start);
385 ASSERT_EQ(result.at(0)->length, length);
386 ASSERT_EQ(result.at(0)->name, expectedName);
387 initializer.DestroyContext(ctx);
388 }
389
TEST_F(LspClassificationTests,GetSemanticClassifications4)390 TEST_F(LspClassificationTests, GetSemanticClassifications4)
391 {
392 Initializer initializer = Initializer();
393 es2panda_Context *ctx =
394 initializer.CreateContext("interface-name.ets", ES2PANDA_STATE_CHECKED, "interface I {};\nlet a:I");
395 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_CHECKED);
396
397 size_t const start = 22;
398 size_t const length = 1;
399 auto result = ark::es2panda::lsp::GetSemanticClassifications(ctx, start, length);
400 const size_t expectedCount = 1;
401 std::string expectedName = "interface name";
402 ASSERT_EQ(result.size(), expectedCount);
403 ASSERT_EQ(result.at(0)->start, start);
404 ASSERT_EQ(result.at(0)->length, length);
405 ASSERT_EQ(result.at(0)->name, expectedName);
406 initializer.DestroyContext(ctx);
407 }
408
TEST_F(LspClassificationTests,GetSemanticClassifications5)409 TEST_F(LspClassificationTests, GetSemanticClassifications5)
410 {
411 Initializer initializer = Initializer();
412 es2panda_Context *ctx =
413 initializer.CreateContext("type-alias-name.ets", ES2PANDA_STATE_CHECKED, "type tmp = Long|null;\nlet a:tmp");
414 ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_CHECKED);
415
416 size_t const start = 28;
417 size_t const length = 3;
418 auto result = ark::es2panda::lsp::GetSemanticClassifications(ctx, start, length);
419 const size_t expectedCount = 1;
420 std::string expectedName = "type alias name";
421 ASSERT_EQ(result.size(), expectedCount);
422 ASSERT_EQ(result.at(0)->start, start);
423 ASSERT_EQ(result.at(0)->length, length);
424 ASSERT_EQ(result.at(0)->name, expectedName);
425 initializer.DestroyContext(ctx);
426 }
427