2023-11-15 15:34:42 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-01-19 21:10:00 +08:00
|
|
|
import PostgresSQL from 'src/parser/pgsql';
|
|
|
|
import { CaretPosition } from 'src/parser/common/basic-parser-types';
|
|
|
|
import { commentOtherLine } from 'test/helper';
|
2023-11-15 15:34:42 +08:00
|
|
|
|
|
|
|
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
|
|
|
|
|
|
|
|
describe('Postgres SQL Token Suggestion', () => {
|
|
|
|
const parser = new PostgresSQL();
|
|
|
|
test('After ALTER', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 3,
|
|
|
|
column: 7,
|
|
|
|
};
|
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
expect(suggestion).toEqual([
|
|
|
|
'TYPE',
|
|
|
|
'TEXT',
|
|
|
|
'STATISTICS',
|
|
|
|
'TABLESPACE',
|
|
|
|
'USER',
|
|
|
|
'ROLE',
|
|
|
|
'EVENT',
|
|
|
|
'TRIGGER',
|
|
|
|
'RULE',
|
|
|
|
'FOREIGN',
|
|
|
|
'TABLE',
|
|
|
|
'MATERIALIZED',
|
|
|
|
'VIEW',
|
|
|
|
'INDEX',
|
|
|
|
'SEQUENCE',
|
|
|
|
'SUBSCRIPTION',
|
|
|
|
'SERVER',
|
|
|
|
'SCHEMA',
|
|
|
|
'ROUTINE',
|
|
|
|
'PUBLICATION',
|
|
|
|
'PROCEDURE',
|
|
|
|
'POLICY',
|
|
|
|
'OPERATOR',
|
|
|
|
'LANGUAGE',
|
|
|
|
'PROCEDURAL',
|
|
|
|
'GROUP',
|
|
|
|
'FUNCTION',
|
|
|
|
'DOMAIN',
|
|
|
|
'DATABASE',
|
|
|
|
'CONVERSION',
|
|
|
|
'COLLATION',
|
|
|
|
'AGGREGATE',
|
|
|
|
'SYSTEM',
|
|
|
|
'LARGE',
|
|
|
|
'EXTENSION',
|
|
|
|
'DEFAULT',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After CREATE', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 9,
|
|
|
|
column: 8,
|
|
|
|
};
|
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
expect(suggestion).toEqual([
|
|
|
|
'RECURSIVE',
|
|
|
|
'VIEW',
|
|
|
|
'TEMPORARY',
|
|
|
|
'TEMP',
|
|
|
|
'LOCAL',
|
|
|
|
'GLOBAL',
|
|
|
|
'UNLOGGED',
|
|
|
|
'OR',
|
|
|
|
'RULE',
|
|
|
|
'INDEX',
|
|
|
|
'UNIQUE',
|
|
|
|
'TABLE',
|
|
|
|
'COLLATION',
|
|
|
|
'TEXT',
|
|
|
|
'TYPE',
|
|
|
|
'OPERATOR',
|
|
|
|
'AGGREGATE',
|
|
|
|
'DATABASE',
|
|
|
|
'USER',
|
|
|
|
'ROLE',
|
|
|
|
'EVENT',
|
|
|
|
'TRIGGER',
|
|
|
|
'CONSTRAINT',
|
|
|
|
'TRANSFORM',
|
|
|
|
'TABLESPACE',
|
|
|
|
'STATISTICS',
|
|
|
|
'SUBSCRIPTION',
|
|
|
|
'SEQUENCE',
|
|
|
|
'SCHEMA',
|
|
|
|
'LANGUAGE',
|
|
|
|
'PROCEDURAL',
|
|
|
|
'TRUSTED',
|
|
|
|
'POLICY',
|
|
|
|
'PUBLICATION',
|
|
|
|
'MATERIALIZED',
|
|
|
|
'GROUP',
|
|
|
|
'PROCEDURE',
|
|
|
|
'FUNCTION',
|
|
|
|
'FOREIGN',
|
|
|
|
'SERVER',
|
|
|
|
'EXTENSION',
|
|
|
|
'DOMAIN',
|
|
|
|
'CONVERSION',
|
|
|
|
'DEFAULT',
|
|
|
|
'CAST',
|
|
|
|
'ASSERTION',
|
|
|
|
'ACCESS',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After DELETE', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 7,
|
|
|
|
column: 8,
|
|
|
|
};
|
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
expect(suggestion).toEqual(['FROM']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After DROP', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 1,
|
|
|
|
column: 6,
|
|
|
|
};
|
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
expect(suggestion).toEqual([
|
|
|
|
'OPERATOR',
|
|
|
|
'ROUTINE',
|
|
|
|
'PROCEDURE',
|
|
|
|
'FUNCTION',
|
|
|
|
'AGGREGATE',
|
|
|
|
'DATABASE',
|
|
|
|
'USER',
|
|
|
|
'GROUP',
|
|
|
|
'ROLE',
|
|
|
|
'TRANSFORM',
|
|
|
|
'TABLESPACE',
|
|
|
|
'SUBSCRIPTION',
|
2023-11-17 16:32:53 +08:00
|
|
|
'VIEW',
|
|
|
|
'OWNED',
|
|
|
|
'CAST',
|
2023-11-15 15:34:42 +08:00
|
|
|
'INDEX',
|
|
|
|
'DOMAIN',
|
|
|
|
'TYPE',
|
|
|
|
'TRIGGER',
|
2023-11-17 16:32:53 +08:00
|
|
|
'RULE',
|
2023-11-15 15:34:42 +08:00
|
|
|
'POLICY',
|
|
|
|
'SCHEMA',
|
|
|
|
'SERVER',
|
2023-11-17 16:02:38 +08:00
|
|
|
'PUBLICATION',
|
|
|
|
'LANGUAGE',
|
|
|
|
'PROCEDURAL',
|
|
|
|
'FOREIGN',
|
|
|
|
'EXTENSION',
|
|
|
|
'EVENT',
|
|
|
|
'ACCESS',
|
2023-11-15 15:34:42 +08:00
|
|
|
'TEXT',
|
2023-11-17 16:32:53 +08:00
|
|
|
'STATISTICS',
|
|
|
|
'CONVERSION',
|
|
|
|
'COLLATION',
|
|
|
|
'MATERIALIZED',
|
|
|
|
'SEQUENCE',
|
|
|
|
'TABLE',
|
2023-11-15 15:34:42 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After INSERT', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 5,
|
|
|
|
column: 8,
|
|
|
|
};
|
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
expect(suggestion).toEqual(['INTO']);
|
|
|
|
});
|
|
|
|
});
|