Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit e287426

Browse files
authored
Add more tests for constants in tree-sitter grammar (#247)
### Requirements * Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion. * All new code requires tests to ensure against regressions ### Description of the Change The PR adds more tests for various types of constants in situations when they are used as class fields, method names, field names, and in switch statements. ### Alternate Designs N/A ### Benefits N/A ### Possible Drawbacks N/A ### Applicable Issues <!-- Enter any applicable Issues here -->
1 parent 29f977d commit e287426

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

spec/tree-sitter-java-spec.coffee

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ describe 'Tree-sitter based Java grammar', ->
242242

243243
it 'tokenizes constants', ->
244244
tokens = tokenizeLines '''
245-
String CONSTANT_STR = "abc";
245+
String CONSTANT_STR = "value";
246+
int CONST0 = 0;
247+
int CONST_1 = 1;
248+
String A1_B2_C3 = "abc";
249+
String A$_B$_C$ = "abc";
246250
a = CONSTANT + obj.func();
247251
b = conf.get(CONSTANT_ANOTHER);
248252
c = Integer.MAX_VALUE;
@@ -252,12 +256,36 @@ describe 'Tree-sitter based Java grammar', ->
252256
'''
253257

254258
expect(tokens[0][2]).toEqual value: 'CONSTANT_STR', scopes: ['source.java', 'constant.other']
255-
expect(tokens[1][3]).toEqual value: 'CONSTANT', scopes: ['source.java', 'constant.other']
256-
expect(tokens[2][6]).toEqual value: 'CONSTANT_ANOTHER', scopes: ['source.java', 'constant.other']
257-
expect(tokens[3][5]).toEqual value: 'MAX_VALUE', scopes: ['source.java', 'constant.other']
258-
expect(tokens[4][3]).toEqual value: 'A1_B2_C3', scopes: ['source.java', 'constant.other']
259-
expect(tokens[5][3]).toEqual value: 'A1_B2_C$', scopes: ['source.java', 'constant.other']
260-
expect(tokens[6][5]).toEqual value: 'A1_B2_C3', scopes: ['source.java', 'constant.other']
259+
expect(tokens[1][2]).toEqual value: 'CONST0', scopes: ['source.java', 'constant.other']
260+
expect(tokens[2][2]).toEqual value: 'CONST_1', scopes: ['source.java', 'constant.other']
261+
expect(tokens[3][2]).toEqual value: 'A1_B2_C3', scopes: ['source.java', 'constant.other']
262+
expect(tokens[4][2]).toEqual value: 'A$_B$_C$', scopes: ['source.java', 'constant.other']
263+
expect(tokens[5][3]).toEqual value: 'CONSTANT', scopes: ['source.java', 'constant.other']
264+
expect(tokens[6][6]).toEqual value: 'CONSTANT_ANOTHER', scopes: ['source.java', 'constant.other']
265+
expect(tokens[7][5]).toEqual value: 'MAX_VALUE', scopes: ['source.java', 'constant.other']
266+
expect(tokens[8][3]).toEqual value: 'A1_B2_C3', scopes: ['source.java', 'constant.other']
267+
expect(tokens[9][3]).toEqual value: 'A1_B2_C$', scopes: ['source.java', 'constant.other']
268+
expect(tokens[10][5]).toEqual value: 'A1_B2_C3', scopes: ['source.java', 'constant.other']
269+
270+
it 'tokenizes constants in switch statement', ->
271+
tokens = tokenizeLines '''
272+
switch (value) {
273+
case CONST: break;
274+
case CONST_STR: break;
275+
case CONST0: break;
276+
case CONST_1: break;
277+
case C0_STR1_DEF2: break;
278+
case C$_STR$_DEF$: break;
279+
default: break;
280+
}
281+
'''
282+
283+
expect(tokens[1][3]).toEqual value: 'CONST', scopes: ['source.java', 'constant.other']
284+
expect(tokens[2][3]).toEqual value: 'CONST_STR', scopes: ['source.java', 'constant.other']
285+
expect(tokens[3][3]).toEqual value: 'CONST0', scopes: ['source.java', 'constant.other']
286+
expect(tokens[4][3]).toEqual value: 'CONST_1', scopes: ['source.java', 'constant.other']
287+
expect(tokens[5][3]).toEqual value: 'C0_STR1_DEF2', scopes: ['source.java', 'constant.other']
288+
expect(tokens[6][3]).toEqual value: 'C$_STR$_DEF$', scopes: ['source.java', 'constant.other']
261289

262290
it 'tokenizes reserved keywords', ->
263291
tokens = tokenizeLine 'const value;'

0 commit comments

Comments
 (0)