-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathmultipleStatement.test.ts
87 lines (77 loc) · 2.73 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
import fs from 'fs';
import path from 'path';
import { MySQL } from 'src/parser/mysql';
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
const syntaxSql = fs.readFileSync(
path.join(__dirname, 'fixtures', 'multipleStatement.sql'),
'utf-8'
);
describe('MySQL Multiple Statements Syntax Suggestion', () => {
const mysql = new MySQL();
test('Select from table ', () => {
const pos: CaretPosition = {
lineNumber: 1,
column: 15,
};
const syntaxes = mysql.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('Create table ', () => {
const pos: CaretPosition = {
lineNumber: 9,
column: 17,
};
const syntaxes = mysql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
const suggestion = syntaxes?.find(
(syn) => syn.syntaxContextType === EntityContextType.TABLE_CREATE
);
expect(suggestion).not.toBeUndefined();
expect(suggestion?.wordRanges?.length).toBe(2);
expect(suggestion?.wordRanges).toEqual([
{
text: 'db',
line: 9,
startIndex: 306,
endIndex: 307,
startColumn: 14,
endColumn: 16,
},
{
text: '.',
line: 9,
startIndex: 308,
endIndex: 308,
startColumn: 16,
endColumn: 17,
},
]);
});
test('Insert into table ', () => {
const pos: CaretPosition = {
lineNumber: 15,
column: 13,
};
const syntaxes = mysql.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: 87,
};
const syntaxes = mysql.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([]);
});
});