3c7c59fb70
* feat: optimize the strategy of finding the right range * test: apply commentOtherLine util to all suggestion tests * test: decomment suggestion test cases * test: add suggestion test cases in multiple statements * chore: improve comments * test: update log info in test
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { CaretPosition, SyntaxContextType } from '../../../../src/parser/common/basic-parser-types';
|
|
import FlinkSQL from '../../../../src/parser/flinksql';
|
|
|
|
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(
|
|
(syn) => syn.syntaxContextType === SyntaxContextType.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 = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
|
const suggestion = syntaxes?.find(
|
|
(syn) => syn.syntaxContextType === SyntaxContextType.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 = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
|
const suggestion = syntaxes?.find(
|
|
(syn) => syn.syntaxContextType === SyntaxContextType.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 = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
|
const suggestion = syntaxes?.find(
|
|
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
|
});
|
|
});
|