-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
test/parser/spark/suggestion/completeAfterSyntaxError.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,116 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { SparkSQL } from 'src/parser/spark'; | ||
import { CaretPosition, EntityContextType } from 'src/parser/common/types'; | ||
|
||
const syntaxSql = fs.readFileSync( | ||
path.join(__dirname, 'fixtures', 'completeAfterSyntaxError.sql'), | ||
'utf-8' | ||
); | ||
|
||
describe('SparkSQL Complete After Error Statement', () => { | ||
const spark = new SparkSQL(); | ||
|
||
const keywordResult = [ | ||
'WITH', | ||
'SELECT', | ||
'MAP', | ||
'REDUCE', | ||
'FROM', | ||
'TABLE', | ||
'VALUES', | ||
'INSERT', | ||
'DELETE', | ||
'UPDATE', | ||
'MERGE', | ||
'USE', | ||
'SET', | ||
'CREATE', | ||
'ALTER', | ||
'DROP', | ||
'SHOW', | ||
'REPLACE', | ||
'ANALYZE', | ||
'DECLARE', | ||
'EXPLAIN', | ||
'DESC', | ||
'DESCRIBE', | ||
'COMMENT', | ||
'REFRESH', | ||
'CACHE', | ||
'UNCACHE', | ||
'CLEAR', | ||
'LOAD', | ||
'TRUNCATE', | ||
'MSCK', | ||
'REPAIR', | ||
'ADD', | ||
'LIST', | ||
'RESET', | ||
'OPTIMIZE', | ||
'GRANT', | ||
'REVOKE', | ||
'EXPORT', | ||
'IMPORT', | ||
'LOCK', | ||
'UNLOCK', | ||
'START', | ||
'COMMIT', | ||
'ROLLBACK', | ||
'DFS', | ||
]; | ||
|
||
test('Syntax error but end with semi and in multiline', () => { | ||
const pos: CaretPosition = { | ||
lineNumber: 3, | ||
column: 2, | ||
}; | ||
const keywords = spark.getSuggestionAtCaretPosition(syntaxSql, pos)?.keywords; | ||
expect(keywords).toMatchUnorderedArrary(keywordResult); | ||
}); | ||
|
||
test('Syntax error but end with semi and in single line', () => { | ||
const pos: CaretPosition = { | ||
lineNumber: 5, | ||
column: 20, | ||
}; | ||
const keywords = spark.getSuggestionAtCaretPosition(syntaxSql, pos)?.keywords; | ||
expect(keywords).toMatchUnorderedArrary(keywordResult); | ||
}); | ||
|
||
test('Syntax error but start with keyword and in multiline', () => { | ||
const pos: CaretPosition = { | ||
lineNumber: 10, | ||
column: 13, | ||
}; | ||
const suggestion = spark.getSuggestionAtCaretPosition(syntaxSql, pos); | ||
expect(suggestion).not.toBeUndefined(); | ||
|
||
// syntax | ||
const syntaxes = suggestion?.syntax; | ||
expect(syntaxes.length).toBe(1); | ||
expect(syntaxes[0].syntaxContextType).toBe(EntityContextType.TABLE); | ||
|
||
const keywords = suggestion?.keywords; | ||
expect(keywords.length).toBe(1); | ||
expect(keywords[0]).toBe('TABLE'); | ||
}); | ||
|
||
test('Syntax error but start with keyword and in single line', () => { | ||
const pos: CaretPosition = { | ||
lineNumber: 12, | ||
column: 30, | ||
}; | ||
const suggestion = spark.getSuggestionAtCaretPosition(syntaxSql, pos); | ||
expect(suggestion).not.toBeUndefined(); | ||
|
||
// syntax | ||
const syntaxes = suggestion?.syntax; | ||
expect(syntaxes.length).toBe(1); | ||
expect(syntaxes[0].syntaxContextType).toBe(EntityContextType.TABLE); | ||
|
||
const keywords = suggestion?.keywords; | ||
expect(keywords.length).toBe(1); | ||
expect(keywords[0]).toBe('TABLE'); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
test/parser/spark/suggestion/fixtures/completeAfterSyntaxError.sql
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,12 @@ | ||
-- error syntax but end with semi, should suggestion keywords which can start a single statement | ||
SELECT FROM tb1; | ||
I | ||
|
||
SELECT FROM tb1; I | ||
|
||
|
||
-- error syntax but start with keyword, should suggestion token at caret position | ||
SELECT FROM tb2 | ||
INSERT INTO | ||
|
||
SELECT FROM tb2 INSERT INTO |