Skip to content

Commit 35ff0b9

Browse files
committed
test: add filter keywords test case
1 parent 4560e6c commit 35ff0b9

File tree

15 files changed

+105
-1
lines changed

15 files changed

+105
-1
lines changed

src/parser/postgresql/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ export class PostgreSQL extends BasicSQL<PostgreSqlLexer, ProgramContext, Postgr
3333
/**
3434
* The rules that keywords you don't want to be suggested.
3535
*/
36-
protected excludeKeywordRules = new Set([PostgreSqlParser.RULE_nonReservedWord]);
36+
protected excludeKeywordRules = new Set([
37+
PostgreSqlParser.RULE_nonReservedWord,
38+
PostgreSqlParser.RULE_identifier,
39+
PostgreSqlParser.RULE_reservedKeyword,
40+
PostgreSqlParser.RULE_typeFuncNameKeyword,
41+
PostgreSqlParser.RULE_colNameKeyword,
42+
]);
3743

3844
protected preferredRules: Set<number> = new Set([
3945
PostgreSqlParser.RULE_tableNameCreate, // table name

test/parser/flink/suggestion/fixtures/tokenSuggestion.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ CREATE TABLE IF NOT EXISTS
1212
CREATE TABLE tb (id
1313

1414
);
15+
16+
SELECT id FROM ;

test/parser/flink/suggestion/tokenSuggestion.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,16 @@ describe('Flink SQL Token Suggestion', () => {
105105
)?.keywords;
106106
expect(suggestion.length).not.toBe(0);
107107
});
108+
109+
test('filter unreserved keywords', () => {
110+
const pos: CaretPosition = {
111+
lineNumber: 16,
112+
column: 17,
113+
};
114+
const suggestion = flink.getSuggestionAtCaretPosition(
115+
commentOtherLine(tokenSql, pos.lineNumber),
116+
pos
117+
)?.keywords;
118+
expect(suggestion).toMatchUnorderedArray(['TABLE', 'LATERAL', 'UNNEST']);
119+
});
108120
});

test/parser/hive/suggestion/fixtures/tokenSuggestion.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ CREATE TABLE IF NOT EXISTS
2424
CREATE TABLE tb (id
2525

2626
);
27+
28+
SELECT id FROM ;

test/parser/hive/suggestion/tokenSuggestion.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,16 @@ describe('Hive SQL Token Suggestion', () => {
272272
)?.keywords;
273273
expect(suggestion.length).not.toBe(0);
274274
});
275+
276+
test('filter unreserved keywords', () => {
277+
const pos: CaretPosition = {
278+
lineNumber: 28,
279+
column: 16,
280+
};
281+
const suggestion = hive.getSuggestionAtCaretPosition(
282+
commentOtherLine(tokenSql, pos.lineNumber),
283+
pos
284+
)?.keywords;
285+
expect(suggestion).toMatchUnorderedArray(['TABLE', 'UNIQUEJOIN']);
286+
});
275287
});

test/parser/impala/suggestion/fixtures/tokenSuggestion.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ CREATE TABLE IF NOT EXISTS;
1515
CREATE TABLE tb (id
1616

1717
);
18+
19+
SELECT id FROM ;

test/parser/impala/suggestion/tokenSuggestion.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,16 @@ describe('Impala SQL Token Suggestion', () => {
185185
)?.keywords;
186186
expect(suggestion.length).not.toBe(0);
187187
});
188+
189+
test('filter unreserved keywords', () => {
190+
const pos: CaretPosition = {
191+
lineNumber: 19,
192+
column: 17,
193+
};
194+
const suggestion = impala.getSuggestionAtCaretPosition(
195+
commentOtherLine(tokenSql, pos.lineNumber),
196+
pos
197+
)?.keywords;
198+
expect(suggestion).toMatchUnorderedArray(['LATERAL', 'UNNEST']);
199+
});
188200
});

test/parser/mysql/suggestion/fixtures/tokenSuggestion.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ CREATE TABLE IF NOT EXISTS
2020
CREATE TABLE tb (id
2121

2222
);
23+
24+
SELECT id FROM ;

test/parser/mysql/suggestion/tokenSuggestion.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,16 @@ describe('MySQL Token Suggestion', () => {
297297
)?.keywords;
298298
expect(suggestion.length).not.toBe(0);
299299
});
300+
301+
test('filter unreserved keywords', () => {
302+
const pos: CaretPosition = {
303+
lineNumber: 24,
304+
column: 17,
305+
};
306+
const suggestion = mysql.getSuggestionAtCaretPosition(
307+
commentOtherLine(tokenSql, pos.lineNumber),
308+
pos
309+
)?.keywords;
310+
expect(suggestion).toMatchUnorderedArray(['JSON_TABLE', 'LATERAL', 'SELECT']);
311+
});
300312
});

test/parser/postgresql/suggestion/fixtures/tokenSuggestion.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ CREATE TABLE IF NOT EXISTS;
1313
CREATE TABLE tb (id
1414

1515
);
16+
17+
SELECT id as FROM a1

0 commit comments

Comments
 (0)