chroe: devops (#180)
* ci: add dependencies about lint tool * ci: replace eslint with prettier * ci: add husky, cz and commitlint * style: lint fix via prettier * ci: add prettier and check-types to github workflow '
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { CaretPosition, SyntaxContextType } from '../../../../src/parser/common/basic-parser-types';
|
||||
import FlinkSQL from '../../../../src/parser/flinksql'
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
|
||||
const syntaxSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'syntaxSuggestion.sql'), 'utf-8');
|
||||
const syntaxSql = fs.readFileSync(
|
||||
path.join(__dirname, 'fixtures', 'syntaxSuggestion.sql'),
|
||||
'utf-8'
|
||||
);
|
||||
const multipleSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'multipleSql.sql'), 'utf-8');
|
||||
|
||||
describe('Flink SQL Syntax Suggestion', () => {
|
||||
@ -13,187 +16,201 @@ describe('Flink SQL Syntax Suggestion', () => {
|
||||
expect(parser.validate(syntaxSql).length).not.toBe(0);
|
||||
expect(parser.validate(syntaxSql).length).not.toBe(0);
|
||||
expect(parser.validate(syntaxSql).length).not.toBe(0);
|
||||
})
|
||||
});
|
||||
|
||||
test("Multiple SQL use database", () => {
|
||||
test('Multiple SQL use database', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 19,
|
||||
column: 10,
|
||||
}
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(multipleSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat1', '.' ]);
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat1', '.']);
|
||||
});
|
||||
|
||||
test('Drop catalog', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 17
|
||||
}
|
||||
column: 17,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.CATALOG);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.CATALOG
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat' ]);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat']);
|
||||
});
|
||||
|
||||
test('Select table', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 3,
|
||||
column: 19
|
||||
}
|
||||
column: 19,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||
);
|
||||
console.log(syntaxes);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat', '.' ])
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat', '.']);
|
||||
});
|
||||
|
||||
test('Create table', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 5,
|
||||
column: 20
|
||||
}
|
||||
column: 20,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE_CREATE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat', '.', 'db' ])
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat', '.', 'db']);
|
||||
});
|
||||
|
||||
test('Show tables from', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 7,
|
||||
column: 21
|
||||
}
|
||||
column: 21,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat' ])
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat']);
|
||||
});
|
||||
|
||||
test('Alter database', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 9,
|
||||
column: 20
|
||||
}
|
||||
column: 20,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat', '.' ])
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat', '.']);
|
||||
});
|
||||
|
||||
test('Drop view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 11,
|
||||
column: 12
|
||||
}
|
||||
column: 12,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'v' ]);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['v']);
|
||||
});
|
||||
|
||||
test('Select view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 13,
|
||||
column: 15
|
||||
}
|
||||
column: 15,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([]);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
||||
});
|
||||
|
||||
|
||||
test('Create view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 15,
|
||||
column: 15
|
||||
}
|
||||
column: 15,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW_CREATE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['cv']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cv']);
|
||||
});
|
||||
|
||||
test('Function call', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 17,
|
||||
column: 27
|
||||
}
|
||||
column: 27,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.FUNCTION);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.FUNCTION
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['calculate_age']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['calculate_age']);
|
||||
});
|
||||
|
||||
test('Create Function', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 19,
|
||||
column: 20
|
||||
}
|
||||
column: 20,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.FUNCTION_CREATE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.FUNCTION_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['fnc']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['fnc']);
|
||||
});
|
||||
|
||||
test('Show columns from view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 21,
|
||||
column: 22
|
||||
}
|
||||
column: 22,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['vie']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['vie']);
|
||||
});
|
||||
|
||||
test('Show create table', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 23,
|
||||
column: 22
|
||||
}
|
||||
column: 22,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['tb1']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['tb1']);
|
||||
});
|
||||
|
||||
test('Show create view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 25,
|
||||
column: 20
|
||||
}
|
||||
column: 20,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['v1']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['v1']);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { CaretPosition } from '../../../../src/parser/common/basic-parser-types';
|
||||
import FlinkSQL from '../../../../src/parser/flinksql'
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
|
||||
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
|
||||
|
||||
@ -11,47 +11,50 @@ describe('Flink SQL Token Suggestion', () => {
|
||||
test('Use Statement ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 3,
|
||||
column: 5
|
||||
}
|
||||
column: 5,
|
||||
};
|
||||
const suggestion = parser.getSuggestionAtCaretPosition(tokenSql, pos)?.keywords;
|
||||
|
||||
expect(suggestion)
|
||||
.toEqual([ 'MODULES', 'CATALOG' ])
|
||||
})
|
||||
|
||||
expect(suggestion).toEqual(['MODULES', 'CATALOG']);
|
||||
});
|
||||
|
||||
test('Create Statement ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 5,
|
||||
column: 8
|
||||
}
|
||||
column: 8,
|
||||
};
|
||||
const suggestion = parser.getSuggestionAtCaretPosition(tokenSql, pos)?.keywords;
|
||||
|
||||
expect(suggestion)
|
||||
.toEqual([ 'CATALOG', 'FUNCTION', 'TEMPORARY', 'VIEW', 'DATABASE', 'TABLE' ])
|
||||
})
|
||||
|
||||
expect(suggestion).toEqual([
|
||||
'CATALOG',
|
||||
'FUNCTION',
|
||||
'TEMPORARY',
|
||||
'VIEW',
|
||||
'DATABASE',
|
||||
'TABLE',
|
||||
]);
|
||||
});
|
||||
|
||||
test('Show Statement ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 7,
|
||||
column: 6
|
||||
}
|
||||
column: 6,
|
||||
};
|
||||
const suggestion = parser.getSuggestionAtCaretPosition(tokenSql, pos)?.keywords;
|
||||
|
||||
expect(suggestion)
|
||||
.toEqual([
|
||||
'MODULES',
|
||||
'FULL',
|
||||
'FUNCTIONS',
|
||||
'USER',
|
||||
'CREATE',
|
||||
'COLUMNS',
|
||||
'TABLES',
|
||||
'CURRENT',
|
||||
'CATALOGS',
|
||||
'DATABASES',
|
||||
'JARS',
|
||||
'VIEWS'
|
||||
])
|
||||
})
|
||||
|
||||
})
|
||||
expect(suggestion).toEqual([
|
||||
'MODULES',
|
||||
'FULL',
|
||||
'FUNCTIONS',
|
||||
'USER',
|
||||
'CREATE',
|
||||
'COLUMNS',
|
||||
'TABLES',
|
||||
'CURRENT',
|
||||
'CATALOGS',
|
||||
'DATABASES',
|
||||
'JARS',
|
||||
'VIEWS',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user