ecbbee32c7
* test: remove barrier files to improve unit testing performance * chore: change check-types command
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import PostgresSQL from 'src/parser/pgsql';
|
|
import { CaretPosition, SyntaxContextType } from 'src/parser/common/basic-parser-types';
|
|
|
|
const syntaxSql = fs.readFileSync(
|
|
path.join(__dirname, 'fixtures', 'multipleStatement.sql'),
|
|
'utf-8'
|
|
);
|
|
|
|
describe('PgSQL Multiple Statements Syntax Suggestion', () => {
|
|
const parser = new PostgresSQL();
|
|
|
|
test('Create table ', () => {
|
|
const pos: CaretPosition = {
|
|
lineNumber: 1,
|
|
column: 14,
|
|
};
|
|
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([]);
|
|
});
|
|
|
|
test('Select from table', () => {
|
|
const pos: CaretPosition = {
|
|
lineNumber: 9,
|
|
column: 18,
|
|
};
|
|
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', '.']);
|
|
});
|
|
|
|
test('Insert into table ', () => {
|
|
const pos: CaretPosition = {
|
|
lineNumber: 15,
|
|
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: 21,
|
|
column: 65,
|
|
};
|
|
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', '.']);
|
|
});
|
|
});
|