Skip to content

Commit 7238d52

Browse files
Add tests for database entities containing a hyphen in their name
1 parent 947fb3f commit 7238d52

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

packages/server/src/complete/utils/getLastToken.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Gets the last token from the given string considering that tokens can contain dots.
1+
// Gets the last token from the given string considering that tokens can contain dots and dashes.
22
export function getLastToken(sql: string): string {
3-
const match = sql.match(/^(?:.|\s)*[^A-z0-9\\.:'"](.*?)$/)
3+
const match = sql.match(/^(?:.|\s)*[^A-z0-9\\.\-:'"](.*?)$/)
44
if (match) {
55
let prevToken = ''
66
let currentToken = match[1]

packages/server/test/complete.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,3 +999,47 @@ describe('DROP statement', () => {
999999
expect(result.candidates[0].label).toEqual('TABLE1')
10001000
})
10011001
})
1002+
1003+
const SIMPLE_NESTED_SCHEMA_WITH_HYPHEN = {
1004+
tables: [
1005+
{
1006+
catalog: 'catalog-3',
1007+
database: 'schema3',
1008+
tableName: 'table3',
1009+
columns: [{ columnName: 'abc', description: 'def' }],
1010+
},
1011+
],
1012+
functions: [],
1013+
}
1014+
1015+
describe('Fully qualified table names with dash', () => {
1016+
test('complete catalog name', () => {
1017+
const result = complete(
1018+
'SELECT * FROM catalog-3.sch',
1019+
{ line: 0, column: 26 },
1020+
SIMPLE_NESTED_SCHEMA_WITH_HYPHEN
1021+
)
1022+
expect(result.candidates.length).toEqual(1)
1023+
const expected = [expect.objectContaining({ label: 'schema3' })]
1024+
expect(result.candidates).toEqual(expect.arrayContaining(expected))
1025+
})
1026+
test('complete table name', () => {
1027+
const result = complete(
1028+
'SELECT * FROM catalog-3.schema3.tab',
1029+
{ line: 0, column: 34 },
1030+
SIMPLE_NESTED_SCHEMA_WITH_HYPHEN
1031+
)
1032+
expect(result.candidates.length).toEqual(1)
1033+
const expected = [expect.objectContaining({ label: 'table3' })]
1034+
expect(result.candidates).toEqual(expect.arrayContaining(expected))
1035+
})
1036+
test('complete table name on dot', () => {
1037+
const result = complete(
1038+
'SELECT * FROM catalog-3.schema3.',
1039+
{ line: 0, column: 32 },
1040+
SIMPLE_NESTED_SCHEMA_WITH_HYPHEN
1041+
)
1042+
const expected = [expect.objectContaining({ label: 'table3' })]
1043+
expect(result.candidates).toEqual(expect.arrayContaining(expected))
1044+
})
1045+
})

0 commit comments

Comments
 (0)