195878da9b
* feat: replace antlr4ts with antlr4ng * feat: switch caseInsensitive option on * feat: recompile all g4 file * feat: update parser to fit antlr4ng * test: update test to fit antlr4ng
62 lines
2.4 KiB
TypeScript
62 lines
2.4 KiB
TypeScript
import FlinkSQL, { FlinkSqlSplitListener } from 'src/parser/flinksql';
|
|
import { FlinkSqlParserListener } from 'src/lib/flinksql/FlinkSqlParserListener';
|
|
|
|
const validSQL1 = `INSERT INTO country_page_view
|
|
VALUES ('Chinese', 'mumiao', 18),
|
|
('Amercian', 'georage', 22);`;
|
|
const validSQL2 = 'SELECT * FROM tb;';
|
|
const inValidSQL = 'CREATE TABLE VALUES;';
|
|
|
|
describe('FlinkSQL ErrorStrategy test', () => {
|
|
const flinkSQL = new FlinkSQL();
|
|
test('begin inValid', () => {
|
|
const sql = [inValidSQL, validSQL1, validSQL2].join('\n');
|
|
// parse with empty errorListener
|
|
const parseTree = flinkSQL.parse(sql, () => {});
|
|
const splitListener = new FlinkSqlSplitListener();
|
|
flinkSQL.listen(splitListener as FlinkSqlParserListener, parseTree);
|
|
|
|
const statementCount = splitListener.statementsContext.length;
|
|
splitListener.statementsContext.map((item, index) => {
|
|
if (index !== statementCount - 1 && index !== statementCount - 2) {
|
|
expect(item.exception).not.toBe(null);
|
|
} else {
|
|
expect(item.exception).toBe(null);
|
|
}
|
|
});
|
|
});
|
|
|
|
test('middle inValid', () => {
|
|
const sql = [validSQL1, inValidSQL, validSQL2].join('\n');
|
|
// parse with empty errorListener
|
|
const parseTree = flinkSQL.parse(sql, () => {});
|
|
const splitListener = new FlinkSqlSplitListener();
|
|
flinkSQL.listen(splitListener as FlinkSqlParserListener, parseTree);
|
|
|
|
const statementCount = splitListener.statementsContext.length;
|
|
splitListener.statementsContext.map((item, index) => {
|
|
if (index !== statementCount - 1 && index !== 0) {
|
|
expect(item.exception).not.toBe(null);
|
|
} else {
|
|
expect(item.exception).toBe(null);
|
|
}
|
|
});
|
|
});
|
|
|
|
test('end inValid', () => {
|
|
const sql = [validSQL1, validSQL2, inValidSQL].join('\n');
|
|
// parse with empty errorListener
|
|
const parseTree = flinkSQL.parse(sql, () => {});
|
|
const splitListener = new FlinkSqlSplitListener();
|
|
flinkSQL.listen(splitListener as FlinkSqlParserListener, parseTree);
|
|
|
|
splitListener.statementsContext.map((item, index) => {
|
|
if (index !== 0 && index !== 1) {
|
|
expect(item.exception).not.toBe(null);
|
|
} else {
|
|
expect(item.exception).toBe(null);
|
|
}
|
|
});
|
|
});
|
|
});
|