2023-06-09 11:22:53 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-01-19 21:10:00 +08:00
|
|
|
import FlinkSQL from 'src/parser/flinksql';
|
|
|
|
import { CaretPosition } from 'src/parser/common/basic-parser-types';
|
|
|
|
import { commentOtherLine } from 'test/helper';
|
2023-06-09 11:22:53 +08:00
|
|
|
|
|
|
|
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
|
|
|
|
|
2023-10-10 16:37:49 +08:00
|
|
|
describe('Flink SQL Token Suggestion', () => {
|
2023-06-09 11:22:53 +08:00
|
|
|
const parser = new FlinkSQL();
|
|
|
|
|
|
|
|
test('Use Statement ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 3,
|
2023-10-13 11:16:36 +08:00
|
|
|
column: 5,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-13 11:16:36 +08:00
|
|
|
|
|
|
|
expect(suggestion).toEqual(['MODULES', 'CATALOG']);
|
|
|
|
});
|
2023-06-09 11:22:53 +08:00
|
|
|
|
|
|
|
test('Create Statement ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 5,
|
2023-10-13 11:16:36 +08:00
|
|
|
column: 8,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-13 11:16:36 +08:00
|
|
|
|
|
|
|
expect(suggestion).toEqual([
|
|
|
|
'CATALOG',
|
|
|
|
'FUNCTION',
|
|
|
|
'TEMPORARY',
|
|
|
|
'VIEW',
|
|
|
|
'DATABASE',
|
|
|
|
'TABLE',
|
|
|
|
]);
|
|
|
|
});
|
2023-06-09 11:22:53 +08:00
|
|
|
|
|
|
|
test('Show Statement ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 7,
|
2023-10-13 11:16:36 +08:00
|
|
|
column: 6,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-13 11:16:36 +08:00
|
|
|
|
|
|
|
expect(suggestion).toEqual([
|
|
|
|
'MODULES',
|
|
|
|
'FULL',
|
|
|
|
'FUNCTIONS',
|
|
|
|
'USER',
|
|
|
|
'CREATE',
|
|
|
|
'COLUMNS',
|
|
|
|
'TABLES',
|
|
|
|
'CURRENT',
|
|
|
|
'CATALOGS',
|
|
|
|
'DATABASES',
|
|
|
|
'VIEWS',
|
2023-10-30 17:57:27 +08:00
|
|
|
'JARS',
|
2023-10-13 11:16:36 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|