Skip to content

Commit 2058f47

Browse files
committed
test: add test cases for non-js identifier token
1 parent e02f34c commit 2058f47

3 files changed

Lines changed: 116 additions & 25 deletions

File tree

packages/ts-plugin/e2e-test/feature/find-all-references.test.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('Find All References', async () => {
1010
'index.ts': dedent`
1111
import styles from './a.module.css';
1212
styles.a_1;
13+
styles['a-2'];
1314
styles.b_1;
1415
styles.c_1;
1516
styles.c_alias;
@@ -19,6 +20,7 @@ describe('Find All References', async () => {
1920
@value c_1, c_2 as c_alias from './c.module.css';
2021
.a_1 { color: red; }
2122
.a_1 { color: red; }
23+
.a-2 { color: red; }
2224
`,
2325
'b.module.css': dedent`
2426
.b_1 { color: red; }
@@ -51,10 +53,20 @@ describe('Find All References', async () => {
5153
start: { line: 4, offset: 2 },
5254
end: { line: 4, offset: 5 },
5355
};
56+
const a_2_in_index_ts = {
57+
file: formatPath(iff.paths['index.ts']),
58+
start: { line: 3, offset: 9 },
59+
end: { line: 3, offset: 12 },
60+
};
61+
const a_2_in_a_module_css = {
62+
file: formatPath(iff.paths['a.module.css']),
63+
start: { line: 5, offset: 2 },
64+
end: { line: 5, offset: 5 },
65+
};
5466
const b_1_in_index_ts = {
5567
file: formatPath(iff.paths['index.ts']),
56-
start: { line: 3, offset: 8 },
57-
end: { line: 3, offset: 11 },
68+
start: { line: 4, offset: 8 },
69+
end: { line: 4, offset: 11 },
5870
};
5971
const b_1_in_b_module_css = {
6072
file: formatPath(iff.paths['b.module.css']),
@@ -63,8 +75,8 @@ describe('Find All References', async () => {
6375
};
6476
const c_1_in_index_ts = {
6577
file: formatPath(iff.paths['index.ts']),
66-
start: { line: 4, offset: 8 },
67-
end: { line: 4, offset: 11 },
78+
start: { line: 5, offset: 8 },
79+
end: { line: 5, offset: 11 },
6880
};
6981
const c_1_in_a_module_css = {
7082
file: formatPath(iff.paths['a.module.css']),
@@ -78,8 +90,8 @@ describe('Find All References', async () => {
7890
};
7991
const c_alias_in_index_ts = {
8092
file: formatPath(iff.paths['index.ts']),
81-
start: { line: 5, offset: 8 },
82-
end: { line: 5, offset: 15 },
93+
start: { line: 6, offset: 8 },
94+
end: { line: 6, offset: 15 },
8395
};
8496
const c_alias_in_a_module_css = {
8597
file: formatPath(iff.paths['a.module.css']),
@@ -111,6 +123,7 @@ describe('Find All References', async () => {
111123
{ file: formatPath(iff.paths['index.ts']), start: { line: 3, offset: 1 }, end: { line: 3, offset: 7 } },
112124
{ file: formatPath(iff.paths['index.ts']), start: { line: 4, offset: 1 }, end: { line: 4, offset: 7 } },
113125
{ file: formatPath(iff.paths['index.ts']), start: { line: 5, offset: 1 }, end: { line: 5, offset: 7 } },
126+
{ file: formatPath(iff.paths['index.ts']), start: { line: 6, offset: 1 }, end: { line: 6, offset: 7 } },
114127
],
115128
},
116129
{
@@ -152,6 +165,18 @@ describe('Find All References', async () => {
152165
...a_1_1_in_a_module_css.start,
153166
expected: [a_1_in_index_ts, a_1_1_in_a_module_css, a_1_2_in_a_module_css],
154167
},
168+
{
169+
name: 'a-2 in index.ts',
170+
file: a_2_in_index_ts.file,
171+
...a_2_in_index_ts.start,
172+
expected: [a_2_in_index_ts, a_2_in_a_module_css],
173+
},
174+
{
175+
name: 'a-2 in a.module.css',
176+
file: a_2_in_a_module_css.file,
177+
...a_2_in_a_module_css.start,
178+
expected: [a_2_in_index_ts, a_2_in_a_module_css],
179+
},
155180
{
156181
name: 'b_1 in index.ts',
157182
file: b_1_in_index_ts.file,

packages/ts-plugin/e2e-test/feature/go-to-definition.test.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('Go to Definition', async () => {
1111
styles.a_1;
1212
styles.a_2;
1313
styles.a_3;
14+
styles['a-4'];
1415
styles.b_1;
1516
styles.c_1;
1617
styles.c_alias;
@@ -22,6 +23,7 @@ describe('Go to Definition', async () => {
2223
.a_2 { color: red; }
2324
.a_2 { color: red; }
2425
@value a_3: red;
26+
.a-4 { color: red; }
2527
@import url(./b.module.css);
2628
`,
2729
'b.module.css': dedent`
@@ -157,10 +159,40 @@ describe('Go to Definition', async () => {
157159
],
158160
},
159161
{
160-
name: 'b_1 in index.ts',
162+
name: 'a-4 in index.ts',
161163
file: iff.paths['index.ts'],
162164
line: 5,
163165
offset: 8,
166+
expected: [
167+
{
168+
file: formatPath(iff.paths['a.module.css']),
169+
start: { line: 7, offset: 2 },
170+
end: { line: 7, offset: 5 },
171+
contextStart: { line: 7, offset: 1 },
172+
contextEnd: { line: 7, offset: 21 },
173+
},
174+
],
175+
},
176+
{
177+
name: 'a-4 in a.module.css',
178+
file: iff.paths['a.module.css'],
179+
line: 7,
180+
offset: 2,
181+
expected: [
182+
{
183+
file: formatPath(iff.paths['a.module.css']),
184+
start: { line: 7, offset: 2 },
185+
end: { line: 7, offset: 5 },
186+
contextStart: { line: 7, offset: 1 },
187+
contextEnd: { line: 7, offset: 21 },
188+
},
189+
],
190+
},
191+
{
192+
name: 'b_1 in index.ts',
193+
file: iff.paths['index.ts'],
194+
line: 6,
195+
offset: 8,
164196
expected: [
165197
{
166198
file: formatPath(iff.paths['b.module.css']),
@@ -174,7 +206,7 @@ describe('Go to Definition', async () => {
174206
{
175207
name: 'c_1 in index.ts',
176208
file: iff.paths['index.ts'],
177-
line: 6,
209+
line: 7,
178210
offset: 8,
179211
// NOTE: For simplicity of implementation, this is not the ideal behavior. The ideal behavior is as follows:
180212
// expected: [
@@ -226,7 +258,7 @@ describe('Go to Definition', async () => {
226258
{
227259
name: 'c_alias in index.ts',
228260
file: iff.paths['index.ts'],
229-
line: 7,
261+
line: 8,
230262
offset: 8,
231263
// NOTE: For simplicity of implementation, this is not the ideal behavior. The ideal behavior is as follows:
232264
// expected: [
@@ -294,7 +326,7 @@ describe('Go to Definition', async () => {
294326
// NOTE: It is strange that `(` has a definition, but we allow it to keep the implementation simple.
295327
name: '(./b.module.css) in a.module.css',
296328
file: iff.paths['a.module.css'],
297-
line: 7,
329+
line: 8,
298330
offset: 12,
299331
expected: [
300332
{ file: formatPath(iff.paths['b.module.css']), start: { line: 1, offset: 1 }, end: { line: 1, offset: 1 } },

packages/ts-plugin/e2e-test/feature/rename-symbol.test.ts

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('Rename Symbol', async () => {
1111
styles.a_1;
1212
styles.a_1;
1313
styles.a_2;
14+
styles['a-3'];
1415
styles.b_1;
1516
styles.c_1;
1617
styles.c_alias;
@@ -22,6 +23,7 @@ describe('Rename Symbol', async () => {
2223
.a_1 { color: red; }
2324
.a_1 { color: red; }
2425
@value a_2: red;
26+
.a-3 { color: red; }
2527
`,
2628
'b.module.css': dedent`
2729
.b_1 { color: red; }
@@ -124,14 +126,46 @@ describe('Rename Symbol', async () => {
124126
],
125127
},
126128
{
127-
name: 'b_1 in index.ts',
129+
name: 'a-2 in index.ts',
128130
file: iff.paths['index.ts'],
129131
line: 5,
132+
offset: 9,
133+
expected: [
134+
{
135+
file: formatPath(iff.paths['index.ts']),
136+
locs: [{ start: { line: 5, offset: 9 }, end: { line: 5, offset: 12 } }],
137+
},
138+
{
139+
file: formatPath(iff.paths['a.module.css']),
140+
locs: [{ start: { line: 6, offset: 2 }, end: { line: 6, offset: 5 } }],
141+
},
142+
],
143+
},
144+
{
145+
name: 'a-2 in a.module.css',
146+
file: iff.paths['a.module.css'],
147+
line: 6,
148+
offset: 2,
149+
expected: [
150+
{
151+
file: formatPath(iff.paths['index.ts']),
152+
locs: [{ start: { line: 5, offset: 9 }, end: { line: 5, offset: 12 } }],
153+
},
154+
{
155+
file: formatPath(iff.paths['a.module.css']),
156+
locs: [{ start: { line: 6, offset: 2 }, end: { line: 6, offset: 5 } }],
157+
},
158+
],
159+
},
160+
{
161+
name: 'b_1 in index.ts',
162+
file: iff.paths['index.ts'],
163+
line: 6,
130164
offset: 8,
131165
expected: [
132166
{
133167
file: formatPath(iff.paths['index.ts']),
134-
locs: [{ start: { line: 5, offset: 8 }, end: { line: 5, offset: 11 } }],
168+
locs: [{ start: { line: 6, offset: 8 }, end: { line: 6, offset: 11 } }],
135169
},
136170
{
137171
file: formatPath(iff.paths['b.module.css']),
@@ -147,7 +181,7 @@ describe('Rename Symbol', async () => {
147181
expected: [
148182
{
149183
file: formatPath(iff.paths['index.ts']),
150-
locs: [{ start: { line: 5, offset: 8 }, end: { line: 5, offset: 11 } }],
184+
locs: [{ start: { line: 6, offset: 8 }, end: { line: 6, offset: 11 } }],
151185
},
152186
{
153187
file: formatPath(iff.paths['b.module.css']),
@@ -158,13 +192,13 @@ describe('Rename Symbol', async () => {
158192
{
159193
name: 'c_1 in index.ts',
160194
file: iff.paths['index.ts'],
161-
line: 6,
195+
line: 7,
162196
offset: 8,
163197
// NOTE: For simplicity of implementation, this is not the ideal behavior. The ideal behavior is as follows:
164198
// expected: [
165199
// {
166200
// file: formatPath(iff.paths['index.ts']),
167-
// locs: [{ start: { line: 6, offset: 8 }, end: { line: 6, offset: 11 } }],
201+
// locs: [{ start: { line: 7, offset: 8 }, end: { line: 7, offset: 11 } }],
168202
// },
169203
// {
170204
// file: formatPath(iff.paths['a.module.css']),
@@ -174,7 +208,7 @@ describe('Rename Symbol', async () => {
174208
expected: [
175209
{
176210
file: formatPath(iff.paths['index.ts']),
177-
locs: [{ start: { line: 6, offset: 8 }, end: { line: 6, offset: 11 } }],
211+
locs: [{ start: { line: 7, offset: 8 }, end: { line: 7, offset: 11 } }],
178212
},
179213
{
180214
file: formatPath(iff.paths['a.module.css']),
@@ -195,7 +229,7 @@ describe('Rename Symbol', async () => {
195229
// expected: [
196230
// {
197231
// file: formatPath(iff.paths['index.ts']),
198-
// locs: [{ start: { line: 6, offset: 8 }, end: { line: 6, offset: 11 } }],
232+
// locs: [{ start: { line: 7, offset: 8 }, end: { line: 7, offset: 11 } }],
199233
// },
200234
// {
201235
// file: formatPath(iff.paths['a.module.css']),
@@ -205,7 +239,7 @@ describe('Rename Symbol', async () => {
205239
expected: [
206240
{
207241
file: formatPath(iff.paths['index.ts']),
208-
locs: [{ start: { line: 6, offset: 8 }, end: { line: 6, offset: 11 } }],
242+
locs: [{ start: { line: 7, offset: 8 }, end: { line: 7, offset: 11 } }],
209243
},
210244
{
211245
file: formatPath(iff.paths['a.module.css']),
@@ -236,7 +270,7 @@ describe('Rename Symbol', async () => {
236270
expected: [
237271
{
238272
file: formatPath(iff.paths['index.ts']),
239-
locs: [{ start: { line: 6, offset: 8 }, end: { line: 6, offset: 11 } }],
273+
locs: [{ start: { line: 7, offset: 8 }, end: { line: 7, offset: 11 } }],
240274
},
241275
{
242276
file: formatPath(iff.paths['a.module.css']),
@@ -251,13 +285,13 @@ describe('Rename Symbol', async () => {
251285
{
252286
name: 'c_alias in index.ts',
253287
file: iff.paths['index.ts'],
254-
line: 7,
288+
line: 8,
255289
offset: 8,
256290
// NOTE: For simplicity of implementation, this is not the ideal behavior. The ideal behavior is as follows:
257291
// expected: [
258292
// {
259293
// file: formatPath(iff.paths['index.ts']),
260-
// locs: [{ start: { line: 7, offset: 8 }, end: { line: 7, offset: 15 } }],
294+
// locs: [{ start: { line: 8, offset: 8 }, end: { line: 8, offset: 15 } }],
261295
// },
262296
// {
263297
// file: formatPath(iff.paths['a.module.css']),
@@ -267,7 +301,7 @@ describe('Rename Symbol', async () => {
267301
expected: [
268302
{
269303
file: formatPath(iff.paths['index.ts']),
270-
locs: [{ start: { line: 7, offset: 8 }, end: { line: 7, offset: 15 } }],
304+
locs: [{ start: { line: 8, offset: 8 }, end: { line: 8, offset: 15 } }],
271305
},
272306
{
273307
file: formatPath(iff.paths['a.module.css']),
@@ -301,7 +335,7 @@ describe('Rename Symbol', async () => {
301335
expected: [
302336
{
303337
file: formatPath(iff.paths['index.ts']),
304-
locs: [{ start: { line: 7, offset: 8 }, end: { line: 7, offset: 15 } }],
338+
locs: [{ start: { line: 8, offset: 8 }, end: { line: 8, offset: 15 } }],
305339
},
306340
{
307341
file: formatPath(iff.paths['a.module.css']),
@@ -335,7 +369,7 @@ describe('Rename Symbol', async () => {
335369
expected: [
336370
{
337371
file: formatPath(iff.paths['index.ts']),
338-
locs: [{ start: { line: 7, offset: 8 }, end: { line: 7, offset: 15 } }],
372+
locs: [{ start: { line: 8, offset: 8 }, end: { line: 8, offset: 15 } }],
339373
},
340374
{
341375
file: formatPath(iff.paths['a.module.css']),
@@ -369,7 +403,7 @@ describe('Rename Symbol', async () => {
369403
expected: [
370404
{
371405
file: formatPath(iff.paths['index.ts']),
372-
locs: [{ start: { line: 8, offset: 8 }, end: { line: 8, offset: 11 } }],
406+
locs: [{ start: { line: 9, offset: 8 }, end: { line: 9, offset: 11 } }],
373407
},
374408
{
375409
file: formatPath(iff.paths['a.module.css']),

0 commit comments

Comments
 (0)