2023-05-30 14:44:03 +08:00
|
|
|
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
|
|
|
|
import { PlSqlParserVisitor } from '../../../src/lib/plsql/PlSqlParserVisitor';
|
2023-05-04 10:13:05 +08:00
|
|
|
import PLSQL from '../../../src/parser/plsql';
|
2020-09-11 17:39:10 +08:00
|
|
|
|
|
|
|
describe('PLSQL Visitor Tests', () => {
|
|
|
|
const expectTableName = 'user1';
|
|
|
|
const sql = `select id,name,sex from ${expectTableName};`;
|
2021-01-05 17:49:34 +08:00
|
|
|
const parser = new PLSQL();
|
2020-09-11 17:39:10 +08:00
|
|
|
|
|
|
|
const parserTree = parser.parse(sql);
|
|
|
|
|
|
|
|
test('Visitor visitTable_ref_list', () => {
|
|
|
|
let result = '';
|
2023-05-30 14:44:03 +08:00
|
|
|
class MyVisitor extends AbstractParseTreeVisitor<any> implements PlSqlParserVisitor<any> {
|
|
|
|
protected defaultResult() {
|
|
|
|
return result;
|
|
|
|
}
|
2020-12-28 19:07:13 +08:00
|
|
|
// eslint-disable-next-line camelcase
|
2023-05-04 10:13:05 +08:00
|
|
|
visitTable_ref_list = (ctx): void => {
|
2023-05-30 14:44:03 +08:00
|
|
|
result = ctx.text.toLowerCase();
|
2020-09-11 17:39:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const visitor: any = new MyVisitor();
|
|
|
|
visitor.visit(parserTree);
|
|
|
|
|
|
|
|
expect(result).toBe(expectTableName);
|
|
|
|
});
|
|
|
|
});
|