bb0fad1dbe
* refactor: rename flinksql to flink * refactor: rename pgsql to postgresql * refactor: rename trinosql to trino * refactor: replace all default exports with named export * refactor: rename basicParser to basicSQL * refactor: rename basic-parser-types to types * refactor: replace arrow func with plain func
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { FlinkSQL } from 'src/parser/flink';
|
|
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
|
|
|
|
const syntaxSql = fs.readFileSync(
|
|
path.join(__dirname, 'fixtures', 'multipleStatement.sql'),
|
|
'utf-8'
|
|
);
|
|
|
|
describe('FlinkSQL Multiple Statements Syntax Suggestion', () => {
|
|
const flink = new FlinkSQL();
|
|
|
|
test('Select from table ', () => {
|
|
const pos: CaretPosition = {
|
|
lineNumber: 1,
|
|
column: 15,
|
|
};
|
|
const syntaxes = flink.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: 16,
|
|
column: 17,
|
|
};
|
|
const syntaxes = flink.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(['db', '.']);
|
|
});
|
|
|
|
test('Insert into table ', () => {
|
|
const pos: CaretPosition = {
|
|
lineNumber: 22,
|
|
column: 13,
|
|
};
|
|
const syntaxes = flink.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: 31,
|
|
column: 9,
|
|
};
|
|
const syntaxes = flink.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(['db', '.']);
|
|
});
|
|
});
|