2023-11-15 15:34:42 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-03-27 10:33:25 +08:00
|
|
|
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
|
|
|
|
import { PostgreSQL } from 'src/parser/postgresql';
|
2024-01-19 21:10:00 +08:00
|
|
|
import { commentOtherLine } from 'test/helper';
|
2023-11-15 15:34:42 +08:00
|
|
|
|
|
|
|
const syntaxSql = fs.readFileSync(
|
|
|
|
path.join(__dirname, 'fixtures', 'syntaxSuggestion.sql'),
|
|
|
|
'utf-8'
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('Postgre SQL Syntax Suggestion', () => {
|
2024-03-27 10:33:25 +08:00
|
|
|
const postgresql = new PostgreSQL();
|
2023-11-15 15:34:42 +08:00
|
|
|
|
|
|
|
test('Validate Syntax SQL', () => {
|
2024-03-27 10:33:25 +08:00
|
|
|
expect(postgresql.validate(syntaxSql).length).not.toBe(0);
|
|
|
|
expect(postgresql.validate(syntaxSql).length).not.toBe(0);
|
|
|
|
expect(postgresql.validate(syntaxSql).length).not.toBe(0);
|
2023-11-15 15:34:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Insert table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 3,
|
|
|
|
column: 18,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.', 'tb']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Alter table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 7,
|
|
|
|
column: 15,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db']);
|
|
|
|
});
|
|
|
|
|
2023-11-28 10:07:29 +08:00
|
|
|
test('Select table', () => {
|
2023-11-15 15:34:42 +08:00
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 5,
|
|
|
|
column: 18,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 1,
|
2023-11-28 10:07:29 +08:00
|
|
|
column: 18,
|
|
|
|
};
|
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 1,
|
|
|
|
column: 31,
|
|
|
|
};
|
|
|
|
const pos2: CaretPosition = {
|
|
|
|
lineNumber: 1,
|
|
|
|
column: 67,
|
2023-11-15 15:34:42 +08:00
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos2.lineNumber),
|
|
|
|
pos2
|
|
|
|
)?.syntax;
|
2023-11-15 15:34:42 +08:00
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE_CREATE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
2023-11-28 10:07:29 +08:00
|
|
|
const suggestion1 = syntaxes1?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion2 = syntaxes2?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
2023-11-15 15:34:42 +08:00
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
2023-11-28 10:07:29 +08:00
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.', 's']);
|
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
expect(suggestion2).not.toBeUndefined();
|
|
|
|
expect(suggestion2?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
2023-11-15 15:34:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create view ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 9,
|
|
|
|
column: 28,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.VIEW_CREATE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.', 'v']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Drop view ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 13,
|
|
|
|
column: 14,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.VIEW
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Alter view ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 11,
|
|
|
|
column: 16,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.VIEW
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.', 'v']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create function ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 15,
|
|
|
|
column: 20,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.FUNCTION_CREATE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['fn1']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Drop function', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 17,
|
|
|
|
column: 18,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.FUNCTION
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['fn1']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create database', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 19,
|
|
|
|
column: 19,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.DATABASE_CREATE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Drop database', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 21,
|
|
|
|
column: 17,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.DATABASE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Alter database', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 23,
|
|
|
|
column: 18,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.DATABASE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create schema', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 25,
|
|
|
|
column: 40,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.DATABASE_CREATE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['schema_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Drop schema', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 27,
|
|
|
|
column: 26,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.DATABASE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['sch']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Alter schema', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 29,
|
|
|
|
column: 18,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-15 15:34:42 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.DATABASE
|
2023-11-15 15:34:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['name']);
|
|
|
|
});
|
2023-11-28 10:07:29 +08:00
|
|
|
|
|
|
|
test('Alter Foreign Table With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 31,
|
|
|
|
column: 50,
|
|
|
|
};
|
|
|
|
const posCreate: CaretPosition = {
|
|
|
|
lineNumber: 31,
|
|
|
|
column: 69,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxesCreate = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, posCreate.lineNumber),
|
|
|
|
posCreate
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestionCreate = syntaxesCreate?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
expect(suggestionCreate).not.toBeUndefined();
|
|
|
|
expect(suggestionCreate?.wordRanges.map((token) => token.text)).toEqual([
|
|
|
|
'new_column_name',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Alter MATERIALIZED VIEW With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 33,
|
|
|
|
column: 60,
|
|
|
|
};
|
|
|
|
const posCreate: CaretPosition = {
|
|
|
|
lineNumber: 33,
|
|
|
|
column: 79,
|
|
|
|
};
|
|
|
|
const posAction: CaretPosition = {
|
|
|
|
lineNumber: 35,
|
|
|
|
column: 52,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxesCreate = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, posCreate.lineNumber),
|
|
|
|
posCreate
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxesAction = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, posAction.lineNumber),
|
|
|
|
posAction
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestionCreate = syntaxesCreate?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestionAction = syntaxesAction?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
expect(suggestionCreate).not.toBeUndefined();
|
|
|
|
expect(suggestionCreate?.wordRanges.map((token) => token.text)).toEqual([
|
|
|
|
'new_column_name',
|
|
|
|
]);
|
|
|
|
expect(suggestionAction).not.toBeUndefined();
|
|
|
|
expect(suggestionAction?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Alter PUBLICATION With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 37,
|
|
|
|
column: 58,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Alter SEQUENCE With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 39,
|
|
|
|
column: 52,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
2024-03-19 11:27:23 +08:00
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([
|
|
|
|
'table_name',
|
|
|
|
'.',
|
|
|
|
'column_name',
|
|
|
|
]);
|
2023-11-28 10:07:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Alter Table With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 7,
|
|
|
|
column: 33,
|
|
|
|
};
|
|
|
|
const posCreate: CaretPosition = {
|
|
|
|
lineNumber: 41,
|
|
|
|
column: 34,
|
|
|
|
};
|
|
|
|
const posAction: CaretPosition = {
|
|
|
|
lineNumber: 41,
|
|
|
|
column: 53,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxesCreate = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, posCreate.lineNumber),
|
|
|
|
posCreate
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxesAction = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, posAction.lineNumber),
|
|
|
|
posAction
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestionCreate = syntaxesCreate?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestionAction = syntaxesAction?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
expect(suggestionCreate).not.toBeUndefined();
|
|
|
|
expect(suggestionCreate?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
expect(suggestionAction).not.toBeUndefined();
|
|
|
|
expect(suggestionAction?.wordRanges.map((token) => token.text)).toEqual([
|
|
|
|
'new_column_name',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('ANALYZE With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 43,
|
|
|
|
column: 32,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Comment On With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 45,
|
|
|
|
column: 44,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Copy With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 47,
|
|
|
|
column: 26,
|
|
|
|
};
|
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 47,
|
|
|
|
column: 37,
|
|
|
|
};
|
|
|
|
const pos2: CaretPosition = {
|
|
|
|
lineNumber: 47,
|
|
|
|
column: 84,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos2.lineNumber),
|
|
|
|
pos2
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion1 = syntaxes1?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion2 = syntaxes2?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['col_name']);
|
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['col_name2']);
|
|
|
|
expect(suggestion2).not.toBeUndefined();
|
|
|
|
expect(suggestion2?.wordRanges.map((token) => token.text)).toEqual(['clumn_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create Foreign Table With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 49,
|
|
|
|
column: 45,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create Function With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 51,
|
|
|
|
column: 54,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create Index With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 53,
|
|
|
|
column: 40,
|
|
|
|
};
|
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 53,
|
|
|
|
column: 60,
|
|
|
|
};
|
|
|
|
const pos2: CaretPosition = {
|
|
|
|
lineNumber: 53,
|
|
|
|
column: 71,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos2.lineNumber),
|
|
|
|
pos2
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion1 = syntaxes1?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion2 = syntaxes2?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['col_name1']);
|
|
|
|
expect(suggestion2).not.toBeUndefined();
|
|
|
|
expect(suggestion2?.wordRanges.map((token) => token.text)).toEqual(['col_name2']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create MATERIALIZED VIEW With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 55,
|
|
|
|
column: 46,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['col_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create STATISTICS With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 57,
|
|
|
|
column: 33,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create TRIGGER With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 59,
|
|
|
|
column: 48,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 59,
|
|
|
|
column: 93,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
2023-12-13 11:33:47 +08:00
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
2023-11-28 10:07:29 +08:00
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion1 = syntaxes1?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.FUNCTION
|
2023-12-13 11:33:47 +08:00
|
|
|
);
|
2023-11-28 10:07:29 +08:00
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
2023-12-13 11:33:47 +08:00
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['function_name']);
|
2023-11-28 10:07:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('GRANT With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 61,
|
|
|
|
column: 27,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Insert Into With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 63,
|
|
|
|
column: 36,
|
|
|
|
};
|
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 63,
|
|
|
|
column: 83,
|
|
|
|
};
|
|
|
|
const pos2: CaretPosition = {
|
|
|
|
lineNumber: 63,
|
|
|
|
column: 114,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos2.lineNumber),
|
|
|
|
pos2
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion1 = syntaxes1?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion2 = syntaxes2?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['index_column_name']);
|
|
|
|
expect(suggestion2).not.toBeUndefined();
|
|
|
|
expect(suggestion2?.wordRanges.map((token) => token.text)).toEqual(['column_name_exp']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Merge With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 65,
|
|
|
|
column: 132,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['col_name']);
|
|
|
|
});
|
|
|
|
test('REVOKE With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 67,
|
|
|
|
column: 23,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['co_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('SECURITY With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 69,
|
|
|
|
column: 46,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
2024-03-19 11:27:23 +08:00
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([
|
|
|
|
'tablename',
|
|
|
|
'.',
|
|
|
|
'columnname',
|
|
|
|
]);
|
2023-11-28 10:07:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Select With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 71,
|
|
|
|
column: 31,
|
|
|
|
};
|
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 71,
|
|
|
|
column: 103,
|
|
|
|
};
|
|
|
|
const pos2: CaretPosition = {
|
|
|
|
lineNumber: 71,
|
|
|
|
column: 119,
|
|
|
|
};
|
|
|
|
const pos3: CaretPosition = {
|
|
|
|
lineNumber: 71,
|
|
|
|
column: 134,
|
|
|
|
};
|
|
|
|
const pos4: CaretPosition = {
|
|
|
|
lineNumber: 71,
|
|
|
|
column: 147,
|
|
|
|
};
|
|
|
|
const pos5: CaretPosition = {
|
|
|
|
lineNumber: 71,
|
|
|
|
column: 162,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos2.lineNumber),
|
|
|
|
pos2
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes3 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos3.lineNumber),
|
|
|
|
pos3
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes4 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos4.lineNumber),
|
|
|
|
pos4
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes5 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos5.lineNumber),
|
|
|
|
pos5
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion1 = syntaxes1?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion2 = syntaxes2?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion3 = syntaxes3?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion4 = syntaxes4?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
const suggestion5 = syntaxes5?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['col_name']);
|
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
expect(suggestion2).not.toBeUndefined();
|
|
|
|
expect(suggestion2?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
|
|
|
|
expect(suggestion3).not.toBeUndefined();
|
|
|
|
expect(suggestion3?.wordRanges.map((token) => token.text)).toEqual(['col_name']);
|
|
|
|
expect(suggestion4).not.toBeUndefined();
|
|
|
|
expect(suggestion4?.wordRanges.map((token) => token.text)).toEqual(['col_name']);
|
|
|
|
expect(suggestion5).not.toBeUndefined();
|
|
|
|
expect(suggestion5?.wordRanges.map((token) => token.text)).toEqual(['col_name']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Update With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 73,
|
|
|
|
column: 32,
|
|
|
|
};
|
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 73,
|
|
|
|
column: 47,
|
|
|
|
};
|
|
|
|
const pos2: CaretPosition = {
|
|
|
|
lineNumber: 73,
|
|
|
|
column: 53,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos2.lineNumber),
|
|
|
|
pos2
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion1 = syntaxes1?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion2 = syntaxes2?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['columnname']);
|
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['col1']);
|
|
|
|
expect(suggestion2).not.toBeUndefined();
|
|
|
|
expect(suggestion2?.wordRanges.map((token) => token.text)).toEqual(['col2']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Vacuum With Column', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 75,
|
|
|
|
column: 23,
|
|
|
|
};
|
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 75,
|
|
|
|
column: 29,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion1 = syntaxes1?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['col1']);
|
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['col2']);
|
|
|
|
});
|
|
|
|
test('Select table with expression', () => {
|
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 77,
|
|
|
|
column: 36,
|
|
|
|
};
|
|
|
|
const pos2: CaretPosition = {
|
|
|
|
lineNumber: 77,
|
|
|
|
column: 42,
|
|
|
|
};
|
|
|
|
const pos3: CaretPosition = {
|
|
|
|
lineNumber: 77,
|
|
|
|
column: 57,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos2.lineNumber),
|
|
|
|
pos2
|
|
|
|
)?.syntax;
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes3 = postgresql.getSuggestionAtCaretPosition(
|
2023-11-28 10:07:29 +08:00
|
|
|
commentOtherLine(syntaxSql, pos3.lineNumber),
|
|
|
|
pos3
|
|
|
|
)?.syntax;
|
|
|
|
const suggestion1 = syntaxes1?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion2 = syntaxes2?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
const suggestion3 = syntaxes3?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
2023-11-28 10:07:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['col1']);
|
|
|
|
expect(suggestion2).not.toBeUndefined();
|
|
|
|
expect(suggestion2?.wordRanges.map((token) => token.text)).toEqual(['col2']);
|
|
|
|
expect(suggestion3).not.toBeUndefined();
|
|
|
|
expect(suggestion3?.wordRanges.map((token) => token.text)).toEqual(['col3']);
|
|
|
|
});
|
2024-04-26 09:38:15 +08:00
|
|
|
|
|
|
|
test('TRUNCATE TABLE', () => {
|
|
|
|
const pos1: CaretPosition = {
|
|
|
|
lineNumber: 79,
|
|
|
|
column: 16,
|
|
|
|
};
|
|
|
|
const pos2: CaretPosition = {
|
|
|
|
lineNumber: 81,
|
|
|
|
column: 18,
|
|
|
|
};
|
|
|
|
|
|
|
|
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(syntaxSql, pos1.lineNumber),
|
|
|
|
pos1
|
|
|
|
)?.syntax;
|
|
|
|
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(syntaxSql, pos2.lineNumber),
|
|
|
|
pos2
|
|
|
|
)?.syntax;
|
|
|
|
|
|
|
|
const suggestion1 = syntaxes1?.find(
|
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
|
|
|
);
|
|
|
|
const suggestion2 = syntaxes2?.find(
|
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion1).not.toBeUndefined();
|
|
|
|
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual([]);
|
|
|
|
expect(suggestion2).not.toBeUndefined();
|
|
|
|
expect(suggestion2?.wordRanges.map((token) => token.text)).toEqual(['t1']);
|
|
|
|
});
|
2023-11-15 15:34:42 +08:00
|
|
|
});
|