-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathtokenSuggestion.test.ts
98 lines (87 loc) · 2.74 KB
/
tokenSuggestion.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import fs from 'fs';
import path from 'path';
import { FlinkSQL } from 'src/parser/flink';
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
import { commentOtherLine } from 'test/helper';
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
describe('Flink SQL Token Suggestion', () => {
const flink = new FlinkSQL();
test('Use Statement ', () => {
const pos: CaretPosition = {
lineNumber: 3,
column: 5,
};
const suggestion = flink.getSuggestionAtCaretPosition(
commentOtherLine(tokenSql, pos.lineNumber),
pos
)?.keywords;
expect(suggestion).toMatchUnorderedArrary(['MODULES', 'CATALOG']);
});
test('Create Statement ', () => {
const pos: CaretPosition = {
lineNumber: 5,
column: 8,
};
const suggestion = flink.getSuggestionAtCaretPosition(
commentOtherLine(tokenSql, pos.lineNumber),
pos
)?.keywords;
expect(suggestion).toMatchUnorderedArrary([
'CATALOG',
'FUNCTION',
'TEMPORARY',
'VIEW',
'DATABASE',
'TABLE',
]);
});
test('Show Statement ', () => {
const pos: CaretPosition = {
lineNumber: 7,
column: 6,
};
const suggestion = flink.getSuggestionAtCaretPosition(
commentOtherLine(tokenSql, pos.lineNumber),
pos
)?.keywords;
expect(suggestion).toMatchUnorderedArrary([
'MODULES',
'FULL',
'FUNCTIONS',
'USER',
'CREATE',
'COLUMNS',
'TABLES',
'CURRENT',
'CATALOGS',
'DATABASES',
'VIEWS',
'JARS',
]);
});
test('Create Statement table properties', () => {
const scenarios = [
{
caretPosition: {
lineNumber: 9,
column: 45,
},
entityContextType: EntityContextType.TABLE_PROPERTY_KEY,
},
{
caretPosition: {
lineNumber: 9,
column: 55,
},
entityContextType: EntityContextType.TABLE_PROPERTY_VALUE,
},
];
scenarios.forEach((scenario) => {
const suggestion = flink.getSuggestionAtCaretPosition(
commentOtherLine(tokenSql, scenario.caretPosition.lineNumber),
scenario.caretPosition
)?.syntax;
expect(suggestion[0].syntaxContextType).toBe(scenario.entityContextType);
});
});
});