-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CommonSuggestion and JoinsSuggestion types, migrate postgre…
…sql tests to typescript (#105) * refactor: add CommonSuggestion and JoinsSuggestion types * refactor: migrate limit_clause tests to typescript * refactor: migrate offset_clause tests to typescript * refactor: migrate order_by_clause tests to typescript * refactor: migrate select_conditions tests to typescript * refactor: migrate postgresql specific select tests to typescript * refactor: rename CommonSuggestion --------- Co-authored-by: robhovsepyan <[email protected]>
- Loading branch information
1 parent
73bd7b8
commit 36b291c
Showing
10 changed files
with
795 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.json
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
src/autocomplete/parsers/postgresql/grammar/select/limit_clause.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {expect, test} from '@jest/globals'; | ||
|
||
import {KeywordSuggestion, ParserSyntaxError, parsePostgreSql} from '../../../../index'; | ||
|
||
test('should suggest values', () => { | ||
const parseResult = parsePostgreSql( | ||
'SELECT COUNT(*) AS test_count FROM test_table GROUP BY test_count LIMIT ', | ||
'', | ||
); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestions: KeywordSuggestion[] = [ | ||
{value: '10', weight: 10000}, | ||
{value: '100', weight: 10000}, | ||
{value: '1000', weight: 10000}, | ||
{value: '10000', weight: 10000}, | ||
{value: '5000', weight: 10000}, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(suggestions); | ||
}); | ||
|
||
test('should contain LIMIT in suggestions', () => { | ||
const parseResult = parsePostgreSql( | ||
'SELECT COUNT(*) AS test_count FROM test_table GROUP BY test_count OFFSET 10 ', | ||
'', | ||
); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestion: KeywordSuggestion = {value: 'LIMIT', weight: 2.2}; | ||
expect(parseResult.suggestKeywords).toContainEqual(suggestion); | ||
}); | ||
|
||
test('should not allow to include offset after comma', () => { | ||
const parseResult = parsePostgreSql( | ||
'SELECT COUNT(*) AS test_count FROM test_table GROUP BY test_count LIMIT 100, 100 ', | ||
'', | ||
); | ||
|
||
const error: Partial<ParserSyntaxError> = { | ||
text: ',', | ||
token: ',', | ||
line: 0, | ||
loc: { | ||
first_line: 1, | ||
last_line: 1, | ||
first_column: 75, | ||
last_column: 76, | ||
}, | ||
}; | ||
expect(parseResult.errors).toContainEqual(expect.objectContaining(error)); | ||
}); |
70 changes: 0 additions & 70 deletions
70
src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.json
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/autocomplete/parsers/postgresql/grammar/select/offset_clause.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {expect, test} from '@jest/globals'; | ||
|
||
import { | ||
GroupBysSuggestion, | ||
KeywordSuggestion, | ||
OrderBysSuggestion, | ||
parsePostgreSql, | ||
} from '../../../../index'; | ||
|
||
test('should suggest OFFSET', () => { | ||
const parseResult = parsePostgreSql('SELECT * FROM test_table LIMIT 100 ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestion: KeywordSuggestion = {value: 'OFFSET', weight: 2.2}; | ||
expect(parseResult.suggestKeywords).toContainEqual(suggestion); | ||
}); | ||
|
||
test('should not throw errors with OFFSET statement', () => { | ||
const parseResult = parsePostgreSql('SELECT * FROM test_table OFFSET 100;', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
}); | ||
|
||
test('should not throw errors with LIMIT OFFSET statement', () => { | ||
const parseResult = parsePostgreSql('SELECT * FROM test_table LIMIT 1 OFFSET 12;', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
}); | ||
|
||
test('should not throw errors with OFFSET LIMIT statement', () => { | ||
const parseResult = parsePostgreSql('SELECT * FROM test_table OFFSET 12 LIMIT 1;', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
}); | ||
|
||
test('should not throw errors with LIMIT statement', () => { | ||
const parseResult = parsePostgreSql('SELECT * FROM test_table LIMIT 1;', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
}); | ||
|
||
test('should suggest OFFSET, LIMIT, GROUP BY, ORDER BY', () => { | ||
const parseResult = parsePostgreSql('SELECT * FROM test_table WHERE test_column = 1 ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const offsetSuggestion: KeywordSuggestion = {value: 'OFFSET', weight: 2.2}; | ||
expect(parseResult.suggestKeywords).toContainEqual(offsetSuggestion); | ||
|
||
const limitSuggestion: KeywordSuggestion = {value: 'LIMIT', weight: 2.3}; | ||
expect(parseResult.suggestKeywords).toContainEqual(limitSuggestion); | ||
|
||
const groupBysSuggestion: GroupBysSuggestion = { | ||
prefix: 'GROUP BY', | ||
tables: [{identifierChain: [{name: 'test_table'}]}], | ||
}; | ||
expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); | ||
|
||
const orderBysSuggestion: OrderBysSuggestion = { | ||
prefix: 'ORDER BY', | ||
tables: [{identifierChain: [{name: 'test_table'}]}], | ||
}; | ||
expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); | ||
}); |
Oops, something went wrong.