-
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: move AggregateFunctionsSuggestion to a separate interface, refa…
…ctor general parser create tests (#92) * refactor: add misc fixes to generic/**/delete.test.ts * refactor: migrate generic/jison/create test to typescript * refactor: migrate generic/jison/create_database test to typescript * refactor: migrate generic/jison/create_role test to typescript * refactor: rename generic/jison/create_database, add todo * refactor: migrate generic/jison/create_table test to typescript * refactor: migrate generic/jison/create_view test to typescript * refactor: add location tests to generic create tests * docs: add CODE_CONVENTIONS.md * refactor: make create tests more strict * refactor: migrate alter tests to typescript * feat: move TablesSuggestion to a separate variable, define DatabasesSuggestion, add todos * refactor: add more todos to sql_main.jison * refactor: fix readme * fix: fix a test
- Loading branch information
1 parent
7402be4
commit 08e8c26
Showing
25 changed files
with
681 additions
and
416 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Code conventions | ||
|
||
A set of rules all contributors should follow. | ||
You can always link those rules in your PR without hesitation if you see that they are not followed. | ||
|
||
## Testing | ||
|
||
- Each test should only test a granular added piece of logic, and shouldn't test functionality of other's. E.g. if you are using OptionalIfNotExists, you shouldn't test if you get suggestions when writing '', 'IF ', 'IF NOT', just test if `IF NOT EXISTS` is suggesting, and it's enough. | ||
- Each test file should contain at least: | ||
- A test that checks a complete statement for errors | ||
- A test that checks a complete statement locations (can be merged with the one above) | ||
- Don't use `foo` or `bar` custom names, always use `test_{object}`, e.g. `SELECT * FROM test_table`, not `SELECT * FROM hehe_haha`. If you need multiple names, use `_{number}` suffix, e.g. `SELECT test_field, test_field_2 FROM test_table;` | ||
- Write all the static tokens in UPPER_CASE, and all the custom variables in lower_case, e.g. `SELECT test_field` | ||
- Always test your statements on errors, and if there's an unexpected error, just add `TODO: fix unhandled error` error |
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/alter/alter_common.test.json
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/parsing/parsers/generic/jison/alter/alter_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 ALTER', () => { | ||
const parseResult = parseGenericSql('', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestion: KeywordSuggestion = { value: 'ALTER', weight: -1 }; | ||
expect(parseResult.suggestKeywords).toContainEqual(suggestion); | ||
}) |
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/parsing/parsers/generic/jison/alter/alter_table.test.json
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/parsing/parsers/generic/jison/alter/alter_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,33 @@ | ||
import { | ||
DatabasesSuggestion, | ||
KeywordSuggestion, | ||
parseGenericSql, TablesSuggestion, | ||
} from '../../../../index'; | ||
import {expect, test} from '@jest/globals'; | ||
|
||
test('should suggest altering table', () => { | ||
const parseResult = parseGenericSql('ALTER ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestion: KeywordSuggestion = { value: 'TABLE', weight: -1 }; | ||
expect(parseResult.suggestKeywords).toContainEqual(suggestion); | ||
}) | ||
|
||
test('should suggest tables to alter', () => { | ||
const parseResult = parseGenericSql('ALTER TABLE ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const tablesSuggestion: TablesSuggestion = { | ||
onlyTables: true, | ||
}; | ||
expect(parseResult.suggestTables).toEqual(tablesSuggestion); | ||
|
||
const databasesSuggestion: DatabasesSuggestion = { | ||
appendDot: true, | ||
} | ||
expect(parseResult.suggestDatabases).toEqual(databasesSuggestion); | ||
}) | ||
|
||
// TODO: add full tests + locations test |
81 changes: 0 additions & 81 deletions
81
src/parsing/parsers/generic/jison/alter/alter_view.test.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.