refactor: standard naming (#278)
* refactor: rename flinksql to flink * refactor: rename pgsql to postgresql * refactor: rename trinosql to trino * refactor: replace all default exports with named export * refactor: rename basicParser to basicSQL * refactor: rename basic-parser-types to types * refactor: replace arrow func with plain func
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
CREATE TABLE VALUES -- unfinished
|
||||
|
||||
CREATE UNLOGGED TABLE table1 (col1 int) INHERITS (table_parent) WITHOUT OIDS ON COMMIT DROP;
|
||||
|
||||
CREATE SCHEMA schemaname AUTHORIZATION username;
|
||||
|
||||
ALTER TABLE products ADD FOREIGN KEY (product_group_id) REFERENCES product_groups;
|
||||
|
||||
SELECT * FROM db. ; -- unfinished
|
||||
|
||||
INSERT INTO weather (date, city, temp_hi, temp_lo) VALUES ('1994-11-29', 'Hayward', 54, 37);
|
||||
|
||||
ANALYZE VERBOSE table_name ( column_name, column_name2);
|
||||
|
||||
INSERT INTO weather (date, city, temp_hi, temp_lo) VALUES ('1994-11-29', 'Hayward', 54, 37); -- unfinished
|
||||
|
||||
DROP TABLE products CASCADE;
|
||||
|
||||
DROP AGGREGATE aggname2(int);
|
||||
|
||||
INSERT INTO products (product_no, name, price) SELECT * FROM db. ; -- unfinished
|
@ -0,0 +1,11 @@
|
||||
SELECT FROM my_db.tb;
|
||||
|
||||
SELECT name, calculate_age(birthdate) AS age, FROM students;
|
||||
|
||||
INSERT INTO insert_tb SELECT FROM from_tb;
|
||||
|
||||
INSERT INTO insert_tb SELECT id, age, FROM from_tb;
|
||||
|
||||
CREATE TABLE sorted_census_data AS SELECT FROM unsorted_census_data;
|
||||
|
||||
CREATE TABLE sorted_census_data AS SELECT id, age, FROM unsorted_census_data;
|
@ -0,0 +1,77 @@
|
||||
CREATE TABLE db.s (column_name int) PARTITION BY LIST (column_name);
|
||||
|
||||
INSERT INTO db.tb ;
|
||||
|
||||
SELECT * FROM db. ;
|
||||
|
||||
ALTER TABLE db ALTER column_name DROP NOT NULL;
|
||||
|
||||
CREATE OR REPLACE VIEW db.v;
|
||||
|
||||
ALTER VIEW db.v ;
|
||||
|
||||
DROP VIEW db. ;
|
||||
|
||||
CREATE FUNCTION fn1;
|
||||
|
||||
DROP FUNCTION fn1;
|
||||
|
||||
CREATE DATABASE db;
|
||||
|
||||
DROP DATABASE db ;
|
||||
|
||||
ALTER DATABASE db ;
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS schema_name;
|
||||
|
||||
DROP SCHEMA IF EXISTS sch;
|
||||
|
||||
ALTER SCHEMA name RENAME TO new_name;
|
||||
|
||||
ALTER FOREIGN TABLE table_name RENAME column_name TO new_column_name;
|
||||
|
||||
ALTER MATERIALIZED VIEW view_name RENAME COLUMN column_name TO new_column_name;
|
||||
|
||||
ALTER MATERIALIZED VIEW view_name ALTER column_name SET STATISTICS 45;
|
||||
|
||||
ALTER PUBLICATION name ADD TABLE table_name ( column_name);
|
||||
|
||||
ALTER SEQUENCE name OWNED BY table_name.column_name;
|
||||
|
||||
ALTER TABLE db RENAME column_name TO new_column_name;
|
||||
|
||||
ANALYZE table_name (column_name);
|
||||
|
||||
COMMENT ON COLUMN relation_name.column_name IS NULL;
|
||||
|
||||
COPY table_name (col_name, col_name2) FROM 'filename' WITH (FORCE_QUOTE (clumn_name));
|
||||
|
||||
CREATE FOREIGN TABLE table_name (column_name int) SERVER server_name;
|
||||
|
||||
CREATE FUNCTION name (int) RETURNS TABLE (column_name column_type) LANGUAGE lang_name;
|
||||
|
||||
CREATE INDEX ON table_name (column_name) INCLUDE (col_name1, col_name2);
|
||||
|
||||
CREATE MATERIALIZED VIEW table_name (col_name);
|
||||
|
||||
CREATE STATISTICS ON column_name FROM table_name;
|
||||
|
||||
CREATE TRIGGER name AFTER UPDATE OF column_name ON table_name EXECUTE FUNCTION function_name;
|
||||
|
||||
GRANT SELECT ( column_name) ON table_name TO role_specification;
|
||||
|
||||
INSERT INTO table_name (column_name) DEFAULT VALUES ON CONFLICT (index_column_name) DO UPDATE SET column_name_exp = DEFAULT;
|
||||
|
||||
MERGE INTO wines w USING wine_stock_changes s ON s.winename = w.winename WHEN NOT MATCHED AND stock_delta > 0 THEN INSERT (col_name) VALUES(s.winename, s.stock_delta);
|
||||
|
||||
REVOKE SELECT (co_name) ON table_name FROM PUBLIC;
|
||||
|
||||
SECURITY LABEL ON COLUMN tablename.columnname IS string_literal;
|
||||
|
||||
WITH with_query_name (col_name) AS (SELECT id FROM table_expression) SEARCH DEPTH FIRST BY column_name SET column_name CYCLE col_name SET col_name USING col_name SELECT;
|
||||
|
||||
UPDATE tablename SET columnname = a + b, (col1, col2) = (a+3, b+4);
|
||||
|
||||
VACUUM tablename (col1, col2);
|
||||
|
||||
SELECT * FROM db.tbs GROUP BY (col1, col2) ORDER BY col3;
|
@ -0,0 +1,12 @@
|
||||
DROP ;
|
||||
|
||||
ALTER ;
|
||||
|
||||
INSERT ;
|
||||
|
||||
DELETE ;
|
||||
|
||||
CREATE ;
|
||||
|
||||
|
||||
|
74
test/parser/postgresql/suggestion/multipleStatement.test.ts
Normal file
74
test/parser/postgresql/suggestion/multipleStatement.test.ts
Normal file
@ -0,0 +1,74 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { PostgreSQL } from 'src/parser/postgresql';
|
||||
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
|
||||
|
||||
const syntaxSql = fs.readFileSync(
|
||||
path.join(__dirname, 'fixtures', 'multipleStatement.sql'),
|
||||
'utf-8'
|
||||
);
|
||||
|
||||
describe('PgSQL Multiple Statements Syntax Suggestion', () => {
|
||||
const postgresql = new PostgreSQL();
|
||||
|
||||
test('Create table ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 14,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.TABLE_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
||||
});
|
||||
|
||||
test('Select from table or view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 9,
|
||||
column: 18,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
||||
);
|
||||
const suggestionVw = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
||||
expect(suggestionVw).not.toBeUndefined();
|
||||
expect(suggestionVw?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
||||
});
|
||||
|
||||
test('Insert into table ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 15,
|
||||
column: 13,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.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 = postgresql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
||||
});
|
||||
});
|
156
test/parser/postgresql/suggestion/suggestionWithEntity.test.ts
Normal file
156
test/parser/postgresql/suggestion/suggestionWithEntity.test.ts
Normal file
@ -0,0 +1,156 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { PostgreSQL } from 'src/parser/postgresql';
|
||||
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
|
||||
import { commentOtherLine } from 'test/helper';
|
||||
|
||||
const syntaxSql = fs.readFileSync(
|
||||
path.join(__dirname, 'fixtures', 'suggestionWithEntity.sql'),
|
||||
'utf-8'
|
||||
);
|
||||
|
||||
describe('PostgreSql Syntax Suggestion with collect entity', () => {
|
||||
const postgre = new PostgreSQL();
|
||||
|
||||
test('select with no column', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 8,
|
||||
};
|
||||
const sql = commentOtherLine(syntaxSql, pos.lineNumber);
|
||||
|
||||
const syntaxes = postgre.getSuggestionAtCaretPosition(sql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
||||
|
||||
const entities = postgre.getAllEntities(sql, pos);
|
||||
expect(entities.length).toBe(1);
|
||||
expect(entities[0].text).toBe('my_db.tb');
|
||||
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
|
||||
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
|
||||
});
|
||||
|
||||
test('select with columns with trailing comma', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 3,
|
||||
column: 47,
|
||||
};
|
||||
const sql = commentOtherLine(syntaxSql, pos.lineNumber);
|
||||
|
||||
const syntaxes = postgre.getSuggestionAtCaretPosition(sql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
||||
|
||||
const entities = postgre.getAllEntities(sql, pos);
|
||||
expect(entities.length).toBe(1);
|
||||
expect(entities[0].text).toBe('students');
|
||||
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
|
||||
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
|
||||
});
|
||||
|
||||
test('insert into table as select with no column', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 5,
|
||||
column: 30,
|
||||
};
|
||||
const sql = commentOtherLine(syntaxSql, pos.lineNumber);
|
||||
|
||||
const syntaxes = postgre.getSuggestionAtCaretPosition(sql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
||||
|
||||
const entities = postgre.getAllEntities(sql, pos);
|
||||
expect(entities.length).toBe(2);
|
||||
expect(entities[0].text).toBe('insert_tb');
|
||||
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
|
||||
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
|
||||
|
||||
expect(entities[1].text).toBe('from_tb');
|
||||
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
|
||||
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
|
||||
});
|
||||
|
||||
test('insert into table as select with trailing comma', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 7,
|
||||
column: 39,
|
||||
};
|
||||
const sql = commentOtherLine(syntaxSql, pos.lineNumber);
|
||||
|
||||
const syntaxes = postgre.getSuggestionAtCaretPosition(sql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
||||
|
||||
const entities = postgre.getAllEntities(sql, pos);
|
||||
expect(entities.length).toBe(2);
|
||||
expect(entities[0].text).toBe('insert_tb');
|
||||
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
|
||||
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
|
||||
|
||||
expect(entities[1].text).toBe('from_tb');
|
||||
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
|
||||
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
|
||||
});
|
||||
|
||||
test('create table as select with no column', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 9,
|
||||
column: 43,
|
||||
};
|
||||
const sql = commentOtherLine(syntaxSql, pos.lineNumber);
|
||||
|
||||
const syntaxes = postgre.getSuggestionAtCaretPosition(sql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
||||
|
||||
const entities = postgre.getAllEntities(sql, pos);
|
||||
expect(entities.length).toBe(2);
|
||||
expect(entities[0].text).toBe('sorted_census_data');
|
||||
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE_CREATE);
|
||||
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
|
||||
|
||||
expect(entities[1].text).toBe('unsorted_census_data');
|
||||
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
|
||||
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
|
||||
});
|
||||
|
||||
test('create table as select with trailing comma', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 11,
|
||||
column: 52,
|
||||
};
|
||||
const sql = commentOtherLine(syntaxSql, pos.lineNumber);
|
||||
|
||||
const syntaxes = postgre.getSuggestionAtCaretPosition(sql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
||||
|
||||
const entities = postgre.getAllEntities(sql, pos);
|
||||
expect(entities.length).toBe(2);
|
||||
expect(entities[0].text).toBe('sorted_census_data');
|
||||
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE_CREATE);
|
||||
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
|
||||
|
||||
expect(entities[1].text).toBe('unsorted_census_data');
|
||||
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
|
||||
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
|
||||
});
|
||||
});
|
973
test/parser/postgresql/suggestion/syntaxSuggestion.test.ts
Normal file
973
test/parser/postgresql/suggestion/syntaxSuggestion.test.ts
Normal file
@ -0,0 +1,973 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
|
||||
import { PostgreSQL } from 'src/parser/postgresql';
|
||||
import { commentOtherLine } from 'test/helper';
|
||||
|
||||
const syntaxSql = fs.readFileSync(
|
||||
path.join(__dirname, 'fixtures', 'syntaxSuggestion.sql'),
|
||||
'utf-8'
|
||||
);
|
||||
|
||||
describe('Postgre SQL Syntax Suggestion', () => {
|
||||
const postgresql = new PostgreSQL();
|
||||
|
||||
test('Validate Syntax SQL', () => {
|
||||
expect(postgresql.validate(syntaxSql).length).not.toBe(0);
|
||||
expect(postgresql.validate(syntaxSql).length).not.toBe(0);
|
||||
expect(postgresql.validate(syntaxSql).length).not.toBe(0);
|
||||
});
|
||||
|
||||
test('Insert table ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 3,
|
||||
column: 18,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.', 'tb']);
|
||||
});
|
||||
|
||||
test('Alter table ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 7,
|
||||
column: 15,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db']);
|
||||
});
|
||||
|
||||
test('Select table', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 5,
|
||||
column: 18,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
||||
});
|
||||
|
||||
test('Create table ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 18,
|
||||
};
|
||||
const pos1: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 31,
|
||||
};
|
||||
const pos2: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 67,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos1.lineNumber),
|
||||
pos1
|
||||
)?.syntax;
|
||||
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos2.lineNumber),
|
||||
pos2
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.TABLE_CREATE
|
||||
);
|
||||
const suggestion1 = syntaxes1?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
||||
);
|
||||
const suggestion2 = syntaxes2?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
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']);
|
||||
});
|
||||
|
||||
test('Create view ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 9,
|
||||
column: 28,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.VIEW_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.', 'v']);
|
||||
});
|
||||
|
||||
test('Drop view ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 13,
|
||||
column: 14,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
||||
});
|
||||
|
||||
test('Alter view ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 11,
|
||||
column: 16,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.', 'v']);
|
||||
});
|
||||
|
||||
test('Create function ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 15,
|
||||
column: 20,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.FUNCTION_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['fn1']);
|
||||
});
|
||||
|
||||
test('Drop function', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 17,
|
||||
column: 18,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.FUNCTION
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['fn1']);
|
||||
});
|
||||
|
||||
test('Create database', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 19,
|
||||
column: 19,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.DATABASE_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db']);
|
||||
});
|
||||
|
||||
test('Drop database', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 21,
|
||||
column: 17,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db']);
|
||||
});
|
||||
|
||||
test('Alter database', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 23,
|
||||
column: 18,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db']);
|
||||
});
|
||||
|
||||
test('Create schema', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 25,
|
||||
column: 40,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.DATABASE_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['schema_name']);
|
||||
});
|
||||
|
||||
test('Drop schema', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 27,
|
||||
column: 26,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['sch']);
|
||||
});
|
||||
|
||||
test('Alter schema', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 29,
|
||||
column: 18,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['name']);
|
||||
});
|
||||
|
||||
test('Alter Foreign Table With Column', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 31,
|
||||
column: 50,
|
||||
};
|
||||
const posCreate: CaretPosition = {
|
||||
lineNumber: 31,
|
||||
column: 69,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxesCreate = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, posCreate.lineNumber),
|
||||
posCreate
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestionCreate = syntaxesCreate?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
||||
);
|
||||
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxesCreate = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, posCreate.lineNumber),
|
||||
posCreate
|
||||
)?.syntax;
|
||||
const syntaxesAction = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, posAction.lineNumber),
|
||||
posAction
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestionCreate = syntaxesCreate?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
||||
);
|
||||
const suggestionAction = syntaxesAction?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([
|
||||
'table_name',
|
||||
'.',
|
||||
'column_name',
|
||||
]);
|
||||
});
|
||||
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxesCreate = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, posCreate.lineNumber),
|
||||
posCreate
|
||||
)?.syntax;
|
||||
const syntaxesAction = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, posAction.lineNumber),
|
||||
posAction
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestionCreate = syntaxesCreate?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestionAction = syntaxesAction?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
||||
);
|
||||
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos1.lineNumber),
|
||||
pos1
|
||||
)?.syntax;
|
||||
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos2.lineNumber),
|
||||
pos2
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion1 = syntaxes1?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion2 = syntaxes2?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos1.lineNumber),
|
||||
pos1
|
||||
)?.syntax;
|
||||
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos2.lineNumber),
|
||||
pos2
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion1 = syntaxes1?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion2 = syntaxes2?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN_CREATE
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const pos1: CaretPosition = {
|
||||
lineNumber: 59,
|
||||
column: 93,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos1.lineNumber),
|
||||
pos1
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion1 = syntaxes1?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.FUNCTION
|
||||
);
|
||||
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(['function_name']);
|
||||
});
|
||||
|
||||
test('GRANT With Column', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 61,
|
||||
column: 27,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos1.lineNumber),
|
||||
pos1
|
||||
)?.syntax;
|
||||
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos2.lineNumber),
|
||||
pos2
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion1 = syntaxes1?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion2 = syntaxes2?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([
|
||||
'tablename',
|
||||
'.',
|
||||
'columnname',
|
||||
]);
|
||||
});
|
||||
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos1.lineNumber),
|
||||
pos1
|
||||
)?.syntax;
|
||||
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos2.lineNumber),
|
||||
pos2
|
||||
)?.syntax;
|
||||
const syntaxes3 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos3.lineNumber),
|
||||
pos3
|
||||
)?.syntax;
|
||||
const syntaxes4 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos4.lineNumber),
|
||||
pos4
|
||||
)?.syntax;
|
||||
const syntaxes5 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos5.lineNumber),
|
||||
pos5
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion1 = syntaxes1?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion2 = syntaxes2?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion3 = syntaxes3?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion4 = syntaxes4?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
|
||||
const suggestion5 = syntaxes5?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos1.lineNumber),
|
||||
pos1
|
||||
)?.syntax;
|
||||
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos2.lineNumber),
|
||||
pos2
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion1 = syntaxes1?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion2 = syntaxes2?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos.lineNumber),
|
||||
pos
|
||||
)?.syntax;
|
||||
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos1.lineNumber),
|
||||
pos1
|
||||
)?.syntax;
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion1 = syntaxes1?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
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,
|
||||
};
|
||||
const syntaxes1 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos1.lineNumber),
|
||||
pos1
|
||||
)?.syntax;
|
||||
const syntaxes2 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos2.lineNumber),
|
||||
pos2
|
||||
)?.syntax;
|
||||
const syntaxes3 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(syntaxSql, pos3.lineNumber),
|
||||
pos3
|
||||
)?.syntax;
|
||||
const suggestion1 = syntaxes1?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion2 = syntaxes2?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
const suggestion3 = syntaxes3?.find(
|
||||
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
|
||||
);
|
||||
|
||||
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']);
|
||||
});
|
||||
});
|
193
test/parser/postgresql/suggestion/tokenSuggestion.test.ts
Normal file
193
test/parser/postgresql/suggestion/tokenSuggestion.test.ts
Normal file
@ -0,0 +1,193 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { PostgreSQL } from 'src/parser/postgresql';
|
||||
import { CaretPosition } from 'src/parser/common/types';
|
||||
import { commentOtherLine } from 'test/helper';
|
||||
|
||||
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
|
||||
|
||||
describe('Postgres SQL Token Suggestion', () => {
|
||||
const postgresql = new PostgreSQL();
|
||||
test('After ALTER', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 3,
|
||||
column: 7,
|
||||
};
|
||||
const suggestion = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(tokenSql, pos.lineNumber),
|
||||
pos
|
||||
)?.keywords;
|
||||
expect(suggestion).toMatchUnorderedArrary([
|
||||
'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 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(tokenSql, pos.lineNumber),
|
||||
pos
|
||||
)?.keywords;
|
||||
expect(suggestion).toMatchUnorderedArrary([
|
||||
'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 = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(tokenSql, pos.lineNumber),
|
||||
pos
|
||||
)?.keywords;
|
||||
expect(suggestion).toMatchUnorderedArrary(['FROM']);
|
||||
});
|
||||
|
||||
test('After DROP', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 6,
|
||||
};
|
||||
const suggestion = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(tokenSql, pos.lineNumber),
|
||||
pos
|
||||
)?.keywords;
|
||||
expect(suggestion).toMatchUnorderedArrary([
|
||||
'OPERATOR',
|
||||
'ROUTINE',
|
||||
'PROCEDURE',
|
||||
'FUNCTION',
|
||||
'AGGREGATE',
|
||||
'DATABASE',
|
||||
'USER',
|
||||
'GROUP',
|
||||
'ROLE',
|
||||
'TRANSFORM',
|
||||
'TABLESPACE',
|
||||
'SUBSCRIPTION',
|
||||
'VIEW',
|
||||
'OWNED',
|
||||
'CAST',
|
||||
'INDEX',
|
||||
'DOMAIN',
|
||||
'TYPE',
|
||||
'TRIGGER',
|
||||
'RULE',
|
||||
'POLICY',
|
||||
'SCHEMA',
|
||||
'SERVER',
|
||||
'PUBLICATION',
|
||||
'LANGUAGE',
|
||||
'PROCEDURAL',
|
||||
'FOREIGN',
|
||||
'EXTENSION',
|
||||
'EVENT',
|
||||
'ACCESS',
|
||||
'TEXT',
|
||||
'STATISTICS',
|
||||
'CONVERSION',
|
||||
'COLLATION',
|
||||
'MATERIALIZED',
|
||||
'SEQUENCE',
|
||||
'TABLE',
|
||||
]);
|
||||
});
|
||||
|
||||
test('After INSERT', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 5,
|
||||
column: 8,
|
||||
};
|
||||
const suggestion = postgresql.getSuggestionAtCaretPosition(
|
||||
commentOtherLine(tokenSql, pos.lineNumber),
|
||||
pos
|
||||
)?.keywords;
|
||||
expect(suggestion).toMatchUnorderedArrary(['INTO']);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user