|
1 | 1 | import * as path from 'path';
|
2 | 2 | import {describe, expect, it} from 'vitest';
|
| 3 | +import {Position} from 'vscode-languageserver-protocol'; |
3 | 4 | import {
|
4 | 5 | filePathToClassnameDict,
|
5 | 6 | findImportPath,
|
6 | 7 | getTransformer,
|
| 8 | + getWords, |
7 | 9 | } from '../utils';
|
8 | 10 |
|
9 | 11 | describe('filePathToClassnameDict', () => {
|
@@ -228,3 +230,33 @@ describe('getTransformer', () => {
|
228 | 230 | });
|
229 | 231 | });
|
230 | 232 | });
|
| 233 | +describe('getWords', () => { |
| 234 | + it('returns null for a line with no .', () => { |
| 235 | + const line = 'nostyles'; |
| 236 | + const position = Position.create(0, 1); |
| 237 | + const result = getWords(line, position); |
| 238 | + |
| 239 | + expect(result).toEqual(null); |
| 240 | + }); |
| 241 | + it('returns pair of obj and field for line with property accessor expression', () => { |
| 242 | + const line = 'styles.myclass'; |
| 243 | + const position = Position.create(0, 'styles.'.length); |
| 244 | + const result = getWords(line, position); |
| 245 | + |
| 246 | + expect(result).toEqual(['styles', 'myclass']); |
| 247 | + }); |
| 248 | + it('returns pair of obj and field for line with subscript accessor expression (single quoted)', () => { |
| 249 | + const line = "styles['myclass']"; |
| 250 | + const position = Position.create(0, "styles['".length); |
| 251 | + const result = getWords(line, position); |
| 252 | + |
| 253 | + expect(result).toEqual(['styles', 'myclass']); |
| 254 | + }); |
| 255 | + it('returns pair of obj and field for line with subscript accessor expression (double quoted)', () => { |
| 256 | + const line = 'styles["myclass"]'; |
| 257 | + const position = Position.create(0, 'styles["'.length); |
| 258 | + const result = getWords(line, position); |
| 259 | + |
| 260 | + expect(result).toEqual(['styles', 'myclass']); |
| 261 | + }); |
| 262 | +}); |
0 commit comments