-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add CommonSuggestion and JoinsSuggestion types, migrate postgresql tests to typescript #105
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
31b9b80
refactor: add CommonSuggestion and JoinsSuggestion types
298c712
refactor: migrate limit_clause tests to typescript
916b04b
refactor: migrate offset_clause tests to typescript
bd9e2b6
refactor: migrate order_by_clause tests to typescript
cc39947
refactor: migrate select_conditions tests to typescript
ee2600a
refactor: migrate postgresql specific select tests to typescript
4709701
refactor: rename CommonSuggestion
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
60 changes: 60 additions & 0 deletions
60
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,60 @@ | ||
import {expect, test} from '@jest/globals'; | ||
|
||
import {CommonSuggestion, KeywordSuggestion, 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: CommonSuggestion = { | ||
prefix: 'GROUP BY', | ||
tables: [{identifierChain: [{name: 'test_table'}]}], | ||
}; | ||
expect(parseResult.suggestGroupBys).toEqual(groupBysSuggestion); | ||
|
||
const orderBysSuggestion: CommonSuggestion = { | ||
prefix: 'ORDER BY', | ||
tables: [{identifierChain: [{name: 'test_table'}]}], | ||
}; | ||
expect(parseResult.suggestOrderBys).toEqual(orderBysSuggestion); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Common suggestion looks too general. Why not just create a FiltersSuggestion, and make GroupBysSuggestion, OrderBysSuggestion aliases?
Or else we need a better naming