forked from DTStack/dt-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultipleStatement.test.ts
92 lines (82 loc) · 3.04 KB
/
multipleStatement.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
import fs from 'fs';
import path from 'path';
import { PostgreSQL } from 'src/parser/postgresql';
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
const syntaxSql = fs.readFileSync(
path.join(__dirname, 'fixtures', 'multipleStatement.sql'),
'utf-8'
);
describe('PgSQL Multiple Statements Syntax Suggestion', () => {
const postgresql = new PostgreSQL();
test('Create table ', () => {
const pos: CaretPosition = {
lineNumber: 1,
column: 14,
};
const syntaxes = postgresql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
const suggestion = syntaxes?.find(
(syn) => syn.syntaxContextType === EntityContextType.TABLE_CREATE
);
expect(suggestion).not.toBeUndefined();
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
});
test('Select from table or view', () => {
const pos: CaretPosition = {
lineNumber: 9,
column: 18,
};
const syntaxes = postgresql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
const suggestion = syntaxes?.find(
(syn) => syn.syntaxContextType === EntityContextType.TABLE
);
const suggestionVw = syntaxes?.find(
(syn) => syn.syntaxContextType === EntityContextType.VIEW
);
expect(suggestion).not.toBeUndefined();
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
expect(suggestionVw).not.toBeUndefined();
expect(suggestionVw?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
});
test('Insert into table ', () => {
const pos: CaretPosition = {
lineNumber: 15,
column: 13,
};
const syntaxes = postgresql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
const suggestion = syntaxes?.find(
(syn) => syn.syntaxContextType === EntityContextType.TABLE
);
expect(suggestion).not.toBeUndefined();
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
});
test('Insert into select from table ', () => {
const pos: CaretPosition = {
lineNumber: 21,
column: 65,
};
const syntaxes = postgresql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
const suggestion = syntaxes?.find(
(syn) => syn.syntaxContextType === EntityContextType.TABLE
);
expect(suggestion).not.toBeUndefined();
expect(suggestion?.wordRanges?.length).toBe(2);
expect(suggestion?.wordRanges).toEqual([
{
text: 'db',
line: 21,
startIndex: 682,
endIndex: 683,
startColumn: 62,
endColumn: 64,
},
{
text: '.',
line: 21,
startIndex: 684,
endIndex: 684,
startColumn: 64,
endColumn: 65,
},
]);
});
});