-
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.
refactor: migrate explain and insert tests to typescript (#98)
* refactor: migrate explain, insert tests to typescript * refactor: add eslint fixes to new tests
- Loading branch information
1 parent
2c66e7a
commit 7520b13
Showing
4 changed files
with
367 additions
and
372 deletions.
There are no files selected for viewing
69 changes: 0 additions & 69 deletions
69
src/parsing/parsers/generic/jison/explain/explain.test.json
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
src/parsing/parsers/generic/jison/explain/explain.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,132 @@ | ||
import {expect, test} from '@jest/globals'; | ||
|
||
import { | ||
KeywordSuggestion, | ||
StatementPart, | ||
parseGenericSql, | ||
parseGenericSqlWithoutCursor, | ||
} from '../../../../index'; | ||
|
||
test('should suggest EXPLAIN', () => { | ||
const parseResult = parseGenericSql('', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestion: KeywordSuggestion = {value: 'EXPLAIN', weight: -1}; | ||
expect(parseResult.suggestKeywords).toContainEqual(suggestion); | ||
}); | ||
|
||
test('should suggest query beginnings', () => { | ||
const parseResult = parseGenericSql('EXPLAIN ', ''); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const suggestion: KeywordSuggestion[] = [ | ||
{value: 'CREATE', weight: -1}, | ||
{value: 'ALTER', weight: -1}, | ||
{value: 'DELETE', weight: -1}, | ||
{value: 'SELECT', weight: -1}, | ||
]; | ||
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestion)); | ||
}); | ||
|
||
test('should report an error', () => { | ||
const parseResult = parseGenericSql('EXPLAIN EXPLAIN ', ''); | ||
|
||
expect(parseResult.errors).not.toBeUndefined(); | ||
|
||
// TODO: check errors more thoroughly | ||
// Currently, we are unable to check that the first element exists, and that it's token is explain properly | ||
// expect(errors[0].token).toEqual("EXPLAIN"); + we should check locations | ||
}); | ||
|
||
test('should not report errors on full statement and fill locations', () => { | ||
const parseResult = parseGenericSqlWithoutCursor('EXPLAIN SELECT * FROM test_database;'); | ||
|
||
expect(parseResult.errors).toBeUndefined(); | ||
|
||
const statementParts: StatementPart[] = [ | ||
{ | ||
location: { | ||
first_column: 1, | ||
first_line: 1, | ||
last_column: 36, | ||
last_line: 1, | ||
}, | ||
type: 'statement', | ||
}, | ||
{ | ||
identifier: 'SELECT', | ||
location: { | ||
first_column: 9, | ||
first_line: 1, | ||
last_column: 15, | ||
last_line: 1, | ||
}, | ||
type: 'statementType', | ||
}, | ||
{ | ||
location: { | ||
first_column: 16, | ||
first_line: 1, | ||
last_column: 17, | ||
last_line: 1, | ||
}, | ||
missing: false, | ||
type: 'selectList', | ||
}, | ||
{ | ||
location: { | ||
first_column: 16, | ||
first_line: 1, | ||
last_column: 17, | ||
last_line: 1, | ||
}, | ||
tables: [ | ||
{ | ||
identifierChain: [ | ||
{ | ||
name: 'test_database', | ||
}, | ||
], | ||
}, | ||
], | ||
type: 'asterisk', | ||
}, | ||
{ | ||
identifierChain: [ | ||
{ | ||
name: 'test_database', | ||
}, | ||
], | ||
location: { | ||
first_column: 23, | ||
first_line: 1, | ||
last_column: 36, | ||
last_line: 1, | ||
}, | ||
type: 'table', | ||
}, | ||
{ | ||
location: { | ||
first_column: 36, | ||
first_line: 1, | ||
last_column: 36, | ||
last_line: 1, | ||
}, | ||
missing: true, | ||
type: 'whereClause', | ||
}, | ||
{ | ||
location: { | ||
first_column: 36, | ||
first_line: 1, | ||
last_column: 36, | ||
last_line: 1, | ||
}, | ||
missing: true, | ||
type: 'limitClause', | ||
}, | ||
]; | ||
expect(parseResult.locations).toEqual(statementParts); | ||
}); |
Oops, something went wrong.