forked from DTStack/dt-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompleteAfterSyntaxError.test.ts
More file actions
65 lines (54 loc) · 2.19 KB
/
completeAfterSyntaxError.test.ts
File metadata and controls
65 lines (54 loc) · 2.19 KB
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
import { FlinkSQL } from 'src/parser/flink';
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
describe('FlinkSQL Complete After Syntax Error', () => {
const flink = new FlinkSQL();
const sql1 = `SELECT FROM tb2;\nINSERT INTO `;
const sql2 = `SELECT FROM tb3;\nCREATE TABLE `;
const sql3 = `SELECT FROM t1;\nSL`;
test('Syntax error but end with semi, should suggest tableName', () => {
const pos: CaretPosition = {
lineNumber: 2,
column: 13,
};
const suggestion = flink.getSuggestionAtCaretPosition(sql1, pos);
expect(suggestion).not.toBeUndefined();
// syntax
const syntaxes = suggestion?.syntax;
expect(syntaxes.length).toBe(1);
expect(syntaxes[0].syntaxContextType).toBe(EntityContextType.TABLE);
// keyword
const keywords = suggestion?.keywords;
expect(keywords.length).toBe(0);
});
test('Syntax error but end with semi, should suggest tableNameCreate', () => {
const pos: CaretPosition = {
lineNumber: 2,
column: 14,
};
const suggestion = flink.getSuggestionAtCaretPosition(sql2, pos);
expect(suggestion).not.toBeUndefined();
// syntax
const syntaxes = suggestion?.syntax;
expect(syntaxes.length).toBe(1);
expect(syntaxes[0].syntaxContextType).toBe(EntityContextType.TABLE_CREATE);
// keyword
const keywords = suggestion?.keywords;
expect(keywords).toMatchUnorderedArray(['IF', 'IF NOT EXISTS']);
});
test('Syntax error but end with semi, should suggest filter token', () => {
const pos: CaretPosition = {
lineNumber: 2,
column: 2,
};
const suggestion = flink.getSuggestionAtCaretPosition(sql3, pos);
expect(suggestion).not.toBeUndefined();
// syntax
const syntaxes = suggestion?.syntax;
expect(syntaxes.length).toBe(0);
// keyword
const filterKeywords = suggestion?.keywords?.filter(
(item) => item.startsWith('S') && /S(?=.*L)/.test(item)
);
expect(filterKeywords).toMatchUnorderedArray(['SELECT']);
});
});