sql-autocomplete-parsers
Advanced tools
Comparing version 1.7.0 to 1.8.0
# Changelog | ||
## [1.8.0](https://github.com/gravity-ui/sql-autocomplete-parsers/compare/v1.7.0...v1.8.0) (2023-06-23) | ||
### Features | ||
* support explain statement ([#30](https://github.com/gravity-ui/sql-autocomplete-parsers/issues/30)) ([27aef7c](https://github.com/gravity-ui/sql-autocomplete-parsers/commit/27aef7c00d5a3fb247d9ddb55819607881ba8c30)) | ||
## [1.7.0](https://github.com/gravity-ui/sql-autocomplete-parsers/compare/v1.6.1...v1.7.0) (2023-06-21) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "sql-autocomplete-parsers", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "A library that provides autocompletion and errors highlighting for various sql dialects", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -19,2 +19,3 @@ { | ||
"drop/drop_view.jison", | ||
"explain/explain.jison", | ||
"insert/insert.jison", | ||
@@ -21,0 +22,0 @@ "select/cte_select_statement.jison", |
@@ -40,5 +40,12 @@ // Licensed to Cloudera, Inc. under one | ||
containsKeywords?: string[]; | ||
doesNotContainKeywords?: string[]; | ||
containsColRefKeywords?: string[]; | ||
noErrors?: boolean; | ||
locationsOnly?: boolean; | ||
noLocations?: boolean; | ||
expectedDefinitions: unknown, | ||
expectedLocations?: unknown; | ||
expectedResult: { | ||
lowerCase?: boolean; | ||
locations?: unknown; | ||
suggestTables?: { | ||
@@ -52,2 +59,12 @@ identifierChain?: { name: string }[]; | ||
}; | ||
expectedErrors?: { | ||
text: string, | ||
token: string, | ||
loc: { | ||
first_line: number, | ||
last_line: number, | ||
first_column: number, | ||
last_column: number | ||
}, | ||
}[] | ||
} | ||
@@ -78,4 +95,4 @@ | ||
export function toEqualDefinition(actualResponse, testDefinition) { | ||
if (typeof testDefinition.noErrors === 'undefined' && actualResponse.errors) { | ||
export function toEqualDefinition(actualResponse, testDefinition: TestCase) { | ||
if (typeof testDefinition.noErrors === 'undefined' && actualResponse.errors && !testDefinition.expectedErrors) { | ||
let allRecoverable = true; | ||
@@ -93,13 +110,6 @@ actualResponse.errors.forEach(error => { | ||
pass: false, | ||
message: () => | ||
'\n Statement: ' + | ||
testDefinition.beforeCursor + | ||
'|' + | ||
testDefinition.afterCursor + | ||
'\n' + | ||
' noErrors set to: ' + | ||
testDefinition.noErrors + | ||
'\n' + | ||
' Found errors: ' + | ||
JSON.stringify(actualResponse.errors) | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Expected': 'no errors', | ||
'Found errors': actualResponse.errors, | ||
}), | ||
}; | ||
@@ -126,14 +136,6 @@ } | ||
pass: false, | ||
message: () => | ||
'\n Statement: ' + | ||
testDefinition.beforeCursor + | ||
'|' + | ||
testDefinition.afterCursor + | ||
'\n' + | ||
'Expected definitions: ' + | ||
jsonStringToJsString(JSON.stringify(testDefinition.expectedDefinitions)) + | ||
'\n' + | ||
' Parser definitions: ' + | ||
jsonStringToJsString(JSON.stringify(actualResponse.definitions)) + | ||
'\n' | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Expected definitions': testDefinition.expectedDefinitions, | ||
'Found definitions': actualResponse.definitions, | ||
}), | ||
}; | ||
@@ -148,14 +150,6 @@ } | ||
pass: resultEquals(actualResponse.locations, testDefinition.expectedLocations), | ||
message: () => | ||
'\n Statement: ' + | ||
testDefinition.beforeCursor + | ||
'|' + | ||
testDefinition.afterCursor + | ||
'\n' + | ||
'Expected locations: ' + | ||
jsonStringToJsString(JSON.stringify(testDefinition.expectedLocations)) + | ||
'\n' + | ||
' Parser locations: ' + | ||
jsonStringToJsString(JSON.stringify(actualResponse.locations)) + | ||
'\n' | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Expected': 'only locations', | ||
'Found': 'other fields', | ||
}), | ||
}; | ||
@@ -176,10 +170,6 @@ } | ||
pass: false, | ||
message: () => | ||
'\nStatement: ' + | ||
testDefinition.beforeCursor + | ||
'|' + | ||
testDefinition.afterCursor + | ||
'\n' + | ||
' Expected no locations, found ' + | ||
actualResponse.locations.length | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Expected locations': 'none', | ||
'Found locations': actualResponse.locations.length, | ||
}), | ||
}; | ||
@@ -196,9 +186,5 @@ } | ||
pass: false, | ||
message: () => | ||
'\nStatement: ' + | ||
testDefinition.beforeCursor + | ||
'|' + | ||
testDefinition.afterCursor + | ||
'\n' + | ||
' No colRef keywords found' | ||
message: constructTestCaseMessage(testDefinition, { | ||
'colRef keywords': 'not found', | ||
}), | ||
}; | ||
@@ -217,15 +203,6 @@ } else if (testDefinition.containsColRefKeywords !== true) { | ||
pass: false, | ||
message: () => | ||
'\nStatement: ' + | ||
testDefinition.beforeCursor + | ||
'|' + | ||
testDefinition.afterCursor + | ||
'\n' + | ||
' Expected colRef keywords not found ' + | ||
'Expected keywords: ' + | ||
JSON.stringify(testDefinition.containsColRefKeywords) + | ||
'\n' + | ||
' Parser keywords: ' + | ||
JSON.stringify(actualResponse.suggestColRefKeywords) + | ||
'\n' | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Expected colRef keywords': testDefinition.containsColRefKeywords, | ||
'Parser colRef keywords': actualResponse.suggestColRefKeywords, | ||
}), | ||
}; | ||
@@ -249,14 +226,6 @@ } | ||
pass: false, | ||
message: () => | ||
'\n Statement: ' + | ||
testDefinition.beforeCursor + | ||
'|' + | ||
testDefinition.afterCursor + | ||
'\n' + | ||
'Expected keywords: ' + | ||
JSON.stringify(testDefinition.containsKeywords) + | ||
'\n' + | ||
' Parser keywords: ' + | ||
JSON.stringify(keywords) + | ||
'\n' | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Expected keywords': testDefinition.containsKeywords, | ||
'Found keywords': keywords, | ||
}), | ||
}; | ||
@@ -278,14 +247,6 @@ } | ||
pass: false, | ||
message: () => | ||
'\n Statement: ' + | ||
testDefinition.beforeCursor + | ||
'|' + | ||
testDefinition.afterCursor + | ||
'\n' + | ||
'Not expected keywords: ' + | ||
JSON.stringify(testDefinition.doesNotContainKeywords) + | ||
'\n' + | ||
' Parser keywords: ' + | ||
JSON.stringify(keywords) + | ||
'\n' | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Not expected keywords': testDefinition.doesNotContainKeywords, | ||
'Found keywords': keywords, | ||
}) | ||
}; | ||
@@ -307,2 +268,43 @@ } | ||
if (testDefinition.expectedErrors) { | ||
if (!Array.isArray(testDefinition.expectedErrors)) { | ||
return { | ||
pass: false, | ||
message: constructTestCaseMessage(testDefinition, { | ||
'expectedErrors': 'should be an array', | ||
}), | ||
} | ||
} | ||
if (!actualResponse.errors) { | ||
return { | ||
pass: false, | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Expected errors': testDefinition.expectedErrors, | ||
'Parser errors': 'none', | ||
}), | ||
} | ||
} | ||
const filteredResponseErrors = actualResponse.errors.map((responseError, index) => { | ||
const expectedKeys = Object.keys(testDefinition.expectedErrors[index]); | ||
return expectedKeys.reduce((acc, expectedKey) => { | ||
acc[expectedKey] = responseError[expectedKey]; | ||
return acc | ||
}, {}); | ||
}) | ||
if (!resultEquals(testDefinition.expectedErrors, filteredResponseErrors)) { | ||
return { | ||
pass: false, | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Expected errors': testDefinition.expectedErrors, | ||
'Parser errors': filteredResponseErrors, | ||
}), | ||
} | ||
} | ||
delete actualResponse.errors; | ||
} | ||
return { | ||
@@ -312,9 +314,26 @@ pass: | ||
resultEquals(actualResponse, testDefinition.expectedResult), | ||
message: () => | ||
'-------- Statement: ' + testDefinition.beforeCursor + '|' + testDefinition.afterCursor + '\n' + | ||
'-- Expected response: ' + jsonStringToJsString(JSON.stringify(testDefinition.expectedResult)) + '\n' + | ||
'-- Parser response: ' + jsonStringToJsString(JSON.stringify(actualResponse)) + '\n' | ||
message: constructTestCaseMessage(testDefinition, { | ||
'Expected errors': testDefinition.expectedResult, | ||
'Parser errors': actualResponse, | ||
}), | ||
}; | ||
} | ||
function constructTestCaseMessage(testCase: TestCase, details: Record<string, any>): () => string { | ||
let message = `- Query: ${testCase.beforeCursor + '|' + testCase.afterCursor} \n`; | ||
for (let key in details) { | ||
let value = details[key]; | ||
if (value === undefined) { | ||
value = 'undefined'; | ||
} else if (typeof value !== 'string') { | ||
value = jsonStringToJsString(JSON.stringify(value)) | ||
} | ||
message += `- ${key}: ${value} \n`; | ||
} | ||
return () => message | ||
} | ||
function resultEquals(a, b): boolean { | ||
@@ -321,0 +340,0 @@ if (typeof a !== typeof b) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6451861
654
89678