-
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: move AggregateFunctionsSuggestion to a separate interface, refactor general parser create tests #92
Merged
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
610285a
refactor: add misc fixes to generic/**/delete.test.ts
NikitaShkaruba f905a1a
refactor: migrate generic/jison/create test to typescript
NikitaShkaruba 6ade402
refactor: migrate generic/jison/create_database test to typescript
NikitaShkaruba 73dfc13
refactor: migrate generic/jison/create_role test to typescript
NikitaShkaruba 5db4ab1
refactor: rename generic/jison/create_database, add todo
NikitaShkaruba 36bcf08
refactor: migrate generic/jison/create_table test to typescript
NikitaShkaruba c7e788a
refactor: migrate generic/jison/create_view test to typescript
NikitaShkaruba e6284f0
refactor: add location tests to generic create tests
NikitaShkaruba cb989d9
docs: add CODE_CONVENTIONS.md
NikitaShkaruba ddfd4ea
refactor: make create tests more strict
NikitaShkaruba bfb289e
refactor: migrate alter tests to typescript
NikitaShkaruba 7b2d61a
feat: move TablesSuggestion to a separate variable, define DatabasesS…
NikitaShkaruba 5c0713b
refactor: add more todos to sql_main.jison
NikitaShkaruba 72d6847
refactor: fix readme
NikitaShkaruba 826e987
fix: fix a test
NikitaShkaruba 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
20 changes: 0 additions & 20 deletions
20
src/parsing/parsers/generic/jison/create/create_common.test.json
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/parsing/parsers/generic/jison/create/create_common.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,14 @@ | ||
import { | ||
KeywordSuggestion, | ||
parseGenericSql, | ||
} from '../../../../index'; | ||
import {expect, test} from '@jest/globals'; | ||
|
||
test('should suggest CREATE', () => { | ||
const parseResult = parseGenericSql('', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestion: KeywordSuggestion = { value: 'CREATE', weight: -1 }; | ||
expect(parseResult.suggestKeywords).toContainEqual(suggestion); | ||
}) |
47 changes: 0 additions & 47 deletions
47
src/parsing/parsers/generic/jison/create/create_database.test.json
This file was deleted.
Oops, something went wrong.
File renamed without changes.
71 changes: 71 additions & 0 deletions
71
src/parsing/parsers/generic/jison/create/create_database_or_schema.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,71 @@ | ||
import { | ||
KeywordSuggestion, | ||
parseGenericSql, parseGenericSqlWithoutCursor, StatementPart, | ||
} from '../../../../index'; | ||
import {expect, test} from '@jest/globals'; | ||
|
||
// TODO: add separate DatabaseOrSchema tests: | ||
// - 'something [IF NOT EXITS]' | ||
// - 'something IF [NOT EXISTS]' | ||
// - 'something IF NOT [exists]' | ||
// - 'something [IF NOT EXISTS] something2' | ||
|
||
test('should suggest creating DATABASE and SCHEMA', () => { | ||
const parseResult = parseGenericSql('CREATE ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestions: KeywordSuggestion[] = [ | ||
{ value: 'DATABASE', weight: -1 }, | ||
{ value: 'SCHEMA', weight: -1 }, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions)) | ||
}) | ||
|
||
// TODO: remove duplicates, because databaseOrSchema should be tested separately | ||
test('should suggest IF NOT EXISTS for database creation', () => { | ||
const parseResult = parseGenericSql('CREATE DATABASE ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestions: KeywordSuggestion[] = [ | ||
{ value: 'IF NOT EXISTS', weight: -1 }, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions)) | ||
}) | ||
|
||
test('should suggest IF NOT EXISTS for schema creation', () => { | ||
const parseResult = parseGenericSql('CREATE SCHEMA ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestions: KeywordSuggestion[] = [ | ||
{ value: 'IF NOT EXISTS', weight: -1 }, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions)) | ||
}) | ||
|
||
// TODO: remove duplicates, because databaseOrSchema should be tested separately | ||
test('should not report errors on full CREATE DATABASE statement', () => { | ||
const parseResult = parseGenericSqlWithoutCursor('CREATE DATABASE test_database;'); | ||
expect(parseResult.errors).toBeUndefined(); | ||
}) | ||
|
||
test('should not report errors on full CREATE SCHEMA statement and fill locations', () => { | ||
const parseResult = parseGenericSqlWithoutCursor('CREATE SCHEMA test_schema;'); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const statementParts: StatementPart[] = [ | ||
{ | ||
type: 'statement', | ||
location: { | ||
first_column: 1, | ||
first_line: 1, | ||
last_column: 26, | ||
last_line: 1 | ||
}, | ||
} | ||
]; | ||
expect(parseResult.locations).toEqual(statementParts); | ||
}) |
21 changes: 0 additions & 21 deletions
21
src/parsing/parsers/generic/jison/create/create_role.test.json
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
src/parsing/parsers/generic/jison/create/create_role.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,35 @@ | ||
import { | ||
KeywordSuggestion, | ||
parseGenericSql, parseGenericSqlWithoutCursor, StatementPart, | ||
} from '../../../../index'; | ||
import {expect, test} from '@jest/globals'; | ||
|
||
test('should suggest creating ROLE', () => { | ||
const parseResult = parseGenericSql('CREATE ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestions: KeywordSuggestion[] = [ | ||
{ value: 'ROLE', weight: -1 }, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions)) | ||
}) | ||
|
||
test('should not report errors on full CREATE ROLE statement and fill locations', () => { | ||
const parseResult = parseGenericSqlWithoutCursor('CREATE ROLE test_role;'); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const statementParts: StatementPart[] = [ | ||
{ | ||
type: 'statement', | ||
location: { | ||
first_column: 1, | ||
first_line: 1, | ||
last_column: 22, | ||
last_line: 1 | ||
}, | ||
} | ||
]; | ||
expect(parseResult.locations).toEqual(statementParts); | ||
}) |
65 changes: 0 additions & 65 deletions
65
src/parsing/parsers/generic/jison/create/create_table.test.json
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
src/parsing/parsers/generic/jison/create/create_table.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,82 @@ | ||
import { | ||
KeywordSuggestion, | ||
parseGenericSql, parseGenericSqlWithoutCursor, StatementPart, | ||
} from '../../../../index'; | ||
import {expect, test} from '@jest/globals'; | ||
|
||
test('should suggest creating TABLE', () => { | ||
const parseResult = parseGenericSql('CREATE ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestions: KeywordSuggestion[] = [ | ||
{ value: 'TABLE', weight: -1 }, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions)) | ||
}) | ||
|
||
test('should suggest IF NOT EXISTS', () => { | ||
const parseResult = parseGenericSql('CREATE TABLE ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestions: KeywordSuggestion[] = [ | ||
{ value: 'IF NOT EXISTS', weight: -1 }, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions)) | ||
}) | ||
|
||
test('should suggest data types', () => { | ||
const parseResult = parseGenericSql('CREATE TABLE food (id ', ''); | ||
|
||
// TODO: fix unhandled error | ||
// expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestions: KeywordSuggestion[] = [ | ||
{ value: 'BIGINT', weight: -1 }, | ||
{ value: 'BOOLEAN', weight: -1 }, | ||
{ value: 'CHAR', weight: -1 }, | ||
{ value: 'DECIMAL', weight: -1 }, | ||
{ value: 'DOUBLE', weight: -1 }, | ||
{ value: 'FLOAT', weight: -1 }, | ||
{ value: 'INT', weight: -1 }, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions)) | ||
}) | ||
|
||
test('should suggest data types when some types are already written', () => { | ||
const parseResult = parseGenericSql('CREATE TABLE food (id INT, age FLOAT, bar ', ''); | ||
|
||
// TODO: fix unhandled error | ||
// expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestions: KeywordSuggestion[] = [ | ||
{ value: 'BIGINT', weight: -1 }, | ||
{ value: 'BOOLEAN', weight: -1 }, | ||
{ value: 'CHAR', weight: -1 }, | ||
{ value: 'DECIMAL', weight: -1 }, | ||
{ value: 'DOUBLE', weight: -1 }, | ||
{ value: 'FLOAT', weight: -1 }, | ||
{ value: 'INT', weight: -1 }, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions)) | ||
}) | ||
|
||
test('should not report errors on full CREATE TABLE statement', () => { | ||
const parseResult = parseGenericSqlWithoutCursor('CREATE TABLE test_table (id INT, age FLOAT);'); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const statementParts: StatementPart[] = [ | ||
{ | ||
type: 'statement', | ||
location: { | ||
first_column: 1, | ||
first_line: 1, | ||
last_column: 44, | ||
last_line: 1 | ||
}, | ||
} | ||
]; | ||
expect(parseResult.locations).toEqual(statementParts); | ||
}) |
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.
All the todos are fine, I'll fix them later