2023-12-13 11:33:47 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-01-19 21:10:00 +08:00
|
|
|
import FlinkSQL from 'src/parser/flinksql';
|
2024-03-26 14:28:27 +08:00
|
|
|
import { CaretPosition, EntityContextType } from 'src/parser/common/basic-parser-types';
|
2023-12-13 11:33:47 +08:00
|
|
|
|
|
|
|
const syntaxSql = fs.readFileSync(
|
|
|
|
path.join(__dirname, 'fixtures', 'multipleStatement.sql'),
|
|
|
|
'utf-8'
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('FlinkSQL Multiple Statements Syntax Suggestion', () => {
|
|
|
|
const parser = new FlinkSQL();
|
|
|
|
|
|
|
|
test('Select from table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 1,
|
|
|
|
column: 15,
|
|
|
|
};
|
|
|
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
2023-12-13 11:33:47 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 16,
|
|
|
|
column: 17,
|
|
|
|
};
|
|
|
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE_CREATE
|
2023-12-13 11:33:47 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Insert into table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 22,
|
|
|
|
column: 13,
|
|
|
|
};
|
|
|
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
2023-12-13 11:33:47 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Insert into select from table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 31,
|
|
|
|
column: 9,
|
|
|
|
};
|
|
|
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
2023-12-13 11:33:47 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
|
|
|
});
|
|
|
|
});
|