refactor: standard naming (#278)
* refactor: rename flinksql to flink * refactor: rename pgsql to postgresql * refactor: rename trinosql to trino * refactor: replace all default exports with named export * refactor: rename basicParser to basicSQL * refactor: rename basic-parser-types to types * refactor: replace arrow func with plain func
This commit is contained in:
		@ -1,10 +1,10 @@
 | 
			
		||||
import fs from 'fs';
 | 
			
		||||
import path from 'path';
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { MySqlEntityCollector, MysqlSplitListener } from 'src/parser/mysql';
 | 
			
		||||
import { ParseTreeListener } from 'antlr4ng';
 | 
			
		||||
import { MySqlParserListener } from 'src/lib/mysql/MySqlParserListener';
 | 
			
		||||
import { EntityContextType } from 'src/parser/common/basic-parser-types';
 | 
			
		||||
import { EntityContextType } from 'src/parser/common/types';
 | 
			
		||||
import { StmtContextType } from 'src/parser/common/entityCollector';
 | 
			
		||||
 | 
			
		||||
const commonSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'common.sql'), 'utf-8');
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
import MySQL, { MysqlSplitListener } from 'src/parser/mysql';
 | 
			
		||||
import { MySQL, MysqlSplitListener } from 'src/parser/mysql';
 | 
			
		||||
import { MySqlParserListener } from 'src/lib/mysql/MySqlParserListener';
 | 
			
		||||
 | 
			
		||||
const validSQL1 = `INSERT INTO country_page_view
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,10 @@
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
 | 
			
		||||
describe('MySQL Lexer tests', () => {
 | 
			
		||||
    const parser = new MySQL();
 | 
			
		||||
    const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
    const sql = 'select id,name,sex from user1;';
 | 
			
		||||
    const tokens = parser.getAllTokens(sql);
 | 
			
		||||
    const tokens = mysql.getAllTokens(sql);
 | 
			
		||||
 | 
			
		||||
    test('token counts', () => {
 | 
			
		||||
        expect(tokens.length).toBe(12);
 | 
			
		||||
 | 
			
		||||
@ -1,13 +1,13 @@
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { MySqlParserListener } from 'src/lib/mysql/MySqlParserListener';
 | 
			
		||||
import { ParseTreeListener } from 'antlr4ng';
 | 
			
		||||
 | 
			
		||||
describe('MySQL Listener Tests', () => {
 | 
			
		||||
    const expectTableName = 'user1';
 | 
			
		||||
    const sql = `select id,name,sex from ${expectTableName};`;
 | 
			
		||||
    const parser = new MySQL();
 | 
			
		||||
    const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
    const parseTree = parser.parse(sql);
 | 
			
		||||
    const parseTree = mysql.parse(sql);
 | 
			
		||||
 | 
			
		||||
    test('Listener enterTableName', async () => {
 | 
			
		||||
        let result = '';
 | 
			
		||||
@ -22,7 +22,7 @@ describe('MySQL Listener Tests', () => {
 | 
			
		||||
        }
 | 
			
		||||
        const listenTableName: any = new MyListener();
 | 
			
		||||
 | 
			
		||||
        await parser.listen(listenTableName as ParseTreeListener, parseTree);
 | 
			
		||||
        await mysql.listen(listenTableName as ParseTreeListener, parseTree);
 | 
			
		||||
        expect(result).toBe(expectTableName);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
@ -43,7 +43,7 @@ describe('MySQL Listener Tests', () => {
 | 
			
		||||
            `;`,
 | 
			
		||||
        ];
 | 
			
		||||
        const sql = singleStatementArr.join('\n');
 | 
			
		||||
        const sqlSlices = parser.splitSQLByStatement(sql);
 | 
			
		||||
        const sqlSlices = mysql.splitSQLByStatement(sql);
 | 
			
		||||
 | 
			
		||||
        expect(sqlSlices).not.toBeNull();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
import fs from 'fs';
 | 
			
		||||
import path from 'path';
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { CaretPosition, EntityContextType } from 'src/parser/common/basic-parser-types';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
 | 
			
		||||
 | 
			
		||||
const syntaxSql = fs.readFileSync(
 | 
			
		||||
    path.join(__dirname, 'fixtures', 'multipleStatement.sql'),
 | 
			
		||||
@ -9,14 +9,14 @@ const syntaxSql = fs.readFileSync(
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
describe('MySQL Multiple Statements Syntax Suggestion', () => {
 | 
			
		||||
    const parser = new MySQL();
 | 
			
		||||
    const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
    test('Select from table ', () => {
 | 
			
		||||
        const pos: CaretPosition = {
 | 
			
		||||
            lineNumber: 1,
 | 
			
		||||
            column: 15,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
 | 
			
		||||
        const suggestion = syntaxes?.find(
 | 
			
		||||
            (syn) => syn.syntaxContextType === EntityContextType.TABLE
 | 
			
		||||
        );
 | 
			
		||||
@ -30,7 +30,7 @@ describe('MySQL Multiple Statements Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 9,
 | 
			
		||||
            column: 17,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
 | 
			
		||||
        const suggestion = syntaxes?.find(
 | 
			
		||||
            (syn) => syn.syntaxContextType === EntityContextType.TABLE_CREATE
 | 
			
		||||
        );
 | 
			
		||||
@ -44,7 +44,7 @@ describe('MySQL Multiple Statements Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 15,
 | 
			
		||||
            column: 13,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
 | 
			
		||||
        const suggestion = syntaxes?.find(
 | 
			
		||||
            (syn) => syn.syntaxContextType === EntityContextType.TABLE
 | 
			
		||||
        );
 | 
			
		||||
@ -58,7 +58,7 @@ describe('MySQL Multiple Statements Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 21,
 | 
			
		||||
            column: 87,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
 | 
			
		||||
        const suggestion = syntaxes?.find(
 | 
			
		||||
            (syn) => syn.syntaxContextType === EntityContextType.TABLE
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
import fs from 'fs';
 | 
			
		||||
import path from 'path';
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { CaretPosition, EntityContextType } from 'src/parser/common/basic-parser-types';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
 | 
			
		||||
import { commentOtherLine } from 'test/helper';
 | 
			
		||||
 | 
			
		||||
const syntaxSql = fs.readFileSync(
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
import fs from 'fs';
 | 
			
		||||
import path from 'path';
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { EntityContextType, CaretPosition } from 'src/parser/common/basic-parser-types';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { EntityContextType, CaretPosition } from 'src/parser/common/types';
 | 
			
		||||
import { commentOtherLine } from 'test/helper';
 | 
			
		||||
 | 
			
		||||
const syntaxSql = fs.readFileSync(
 | 
			
		||||
@ -10,10 +10,10 @@ const syntaxSql = fs.readFileSync(
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
    const parser = new MySQL();
 | 
			
		||||
    const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
    test('Validate Syntax SQL', () => {
 | 
			
		||||
        expect(parser.validate(syntaxSql).length).not.toBe(0);
 | 
			
		||||
        expect(mysql.validate(syntaxSql).length).not.toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Insert table ', () => {
 | 
			
		||||
@ -21,7 +21,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 1,
 | 
			
		||||
            column: 18,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -38,7 +38,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 3,
 | 
			
		||||
            column: 18,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -55,7 +55,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 5,
 | 
			
		||||
            column: 17,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -72,7 +72,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 7,
 | 
			
		||||
            column: 26,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -89,7 +89,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 9,
 | 
			
		||||
            column: 28,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -106,7 +106,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 11,
 | 
			
		||||
            column: 15,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -123,7 +123,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 13,
 | 
			
		||||
            column: 20,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -140,7 +140,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 15,
 | 
			
		||||
            column: 27,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -157,7 +157,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 17,
 | 
			
		||||
            column: 19,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -174,7 +174,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 19,
 | 
			
		||||
            column: 26,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -191,7 +191,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 21,
 | 
			
		||||
            column: 39,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -208,7 +208,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 23,
 | 
			
		||||
            column: 17,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -225,7 +225,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 25,
 | 
			
		||||
            column: 39,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -242,7 +242,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 27,
 | 
			
		||||
            column: 48,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -259,7 +259,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 29,
 | 
			
		||||
            column: 22,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -276,7 +276,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 31,
 | 
			
		||||
            column: 41,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -293,7 +293,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 33,
 | 
			
		||||
            column: 24,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -310,7 +310,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 35,
 | 
			
		||||
            column: 29,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -327,7 +327,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 37,
 | 
			
		||||
            column: 8,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -344,7 +344,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 39,
 | 
			
		||||
            column: 13,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -361,7 +361,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 41,
 | 
			
		||||
            column: 8,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -378,7 +378,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 43,
 | 
			
		||||
            column: 13,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -395,7 +395,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 45,
 | 
			
		||||
            column: 32,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -412,7 +412,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 47,
 | 
			
		||||
            column: 39,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -429,7 +429,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 49,
 | 
			
		||||
            column: 37,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -446,7 +446,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 51,
 | 
			
		||||
            column: 31,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -463,7 +463,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 53,
 | 
			
		||||
            column: 27,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -480,7 +480,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 55,
 | 
			
		||||
            column: 43,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
@ -497,7 +497,7 @@ describe('MySQL Syntax Suggestion', () => {
 | 
			
		||||
            lineNumber: 57,
 | 
			
		||||
            column: 24,
 | 
			
		||||
        };
 | 
			
		||||
        const syntaxes = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const syntaxes = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(syntaxSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.syntax;
 | 
			
		||||
 | 
			
		||||
@ -1,20 +1,20 @@
 | 
			
		||||
import fs from 'fs';
 | 
			
		||||
import path from 'path';
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { CaretPosition } from 'src/parser/common/basic-parser-types';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { CaretPosition } from 'src/parser/common/types';
 | 
			
		||||
import { commentOtherLine } from 'test/helper';
 | 
			
		||||
 | 
			
		||||
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
 | 
			
		||||
 | 
			
		||||
describe('MySQL Token Suggestion', () => {
 | 
			
		||||
    const parser = new MySQL();
 | 
			
		||||
    const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
    test('After ALTER', () => {
 | 
			
		||||
        const pos: CaretPosition = {
 | 
			
		||||
            lineNumber: 1,
 | 
			
		||||
            column: 7,
 | 
			
		||||
        };
 | 
			
		||||
        const suggestion = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const suggestion = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(tokenSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.keywords;
 | 
			
		||||
@ -45,7 +45,7 @@ describe('MySQL Token Suggestion', () => {
 | 
			
		||||
            lineNumber: 3,
 | 
			
		||||
            column: 8,
 | 
			
		||||
        };
 | 
			
		||||
        const suggestion = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const suggestion = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(tokenSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.keywords;
 | 
			
		||||
@ -86,7 +86,7 @@ describe('MySQL Token Suggestion', () => {
 | 
			
		||||
            lineNumber: 5,
 | 
			
		||||
            column: 8,
 | 
			
		||||
        };
 | 
			
		||||
        const suggestion = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const suggestion = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(tokenSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.keywords;
 | 
			
		||||
@ -99,7 +99,7 @@ describe('MySQL Token Suggestion', () => {
 | 
			
		||||
            lineNumber: 7,
 | 
			
		||||
            column: 10,
 | 
			
		||||
        };
 | 
			
		||||
        const suggestion = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const suggestion = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(tokenSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.keywords;
 | 
			
		||||
@ -123,7 +123,7 @@ describe('MySQL Token Suggestion', () => {
 | 
			
		||||
            lineNumber: 9,
 | 
			
		||||
            column: 6,
 | 
			
		||||
        };
 | 
			
		||||
        const suggestion = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const suggestion = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(tokenSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.keywords;
 | 
			
		||||
@ -156,7 +156,7 @@ describe('MySQL Token Suggestion', () => {
 | 
			
		||||
            lineNumber: 11,
 | 
			
		||||
            column: 8,
 | 
			
		||||
        };
 | 
			
		||||
        const suggestion = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const suggestion = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(tokenSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.keywords;
 | 
			
		||||
@ -175,7 +175,7 @@ describe('MySQL Token Suggestion', () => {
 | 
			
		||||
            lineNumber: 13,
 | 
			
		||||
            column: 6,
 | 
			
		||||
        };
 | 
			
		||||
        const suggestion = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const suggestion = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(tokenSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.keywords;
 | 
			
		||||
@ -188,7 +188,7 @@ describe('MySQL Token Suggestion', () => {
 | 
			
		||||
            lineNumber: 15,
 | 
			
		||||
            column: 6,
 | 
			
		||||
        };
 | 
			
		||||
        const suggestion = parser.getSuggestionAtCaretPosition(
 | 
			
		||||
        const suggestion = mysql.getSuggestionAtCaretPosition(
 | 
			
		||||
            commentOtherLine(tokenSql, pos.lineNumber),
 | 
			
		||||
            pos
 | 
			
		||||
        )?.keywords;
 | 
			
		||||
 | 
			
		||||
@ -1,36 +1,36 @@
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
 | 
			
		||||
describe('MySQL Syntax Tests', () => {
 | 
			
		||||
    const parser = new MySQL();
 | 
			
		||||
    const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
    test('Select Statement', () => {
 | 
			
		||||
        const sql = 'select id,name from user1;';
 | 
			
		||||
        const result = parser.validate(sql);
 | 
			
		||||
        const result = mysql.validate(sql);
 | 
			
		||||
 | 
			
		||||
        expect(result.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Select 1+1', () => {
 | 
			
		||||
        const sql = 'SELECT 1+1;';
 | 
			
		||||
        const result = parser.validate(sql);
 | 
			
		||||
        const result = mysql.validate(sql);
 | 
			
		||||
        expect(result.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Test invalid Double Line Comment statement', () => {
 | 
			
		||||
        let sql = `-test comment\n`;
 | 
			
		||||
        let result = parser.validate(sql);
 | 
			
		||||
        let result = mysql.validate(sql);
 | 
			
		||||
        expect(result.length).toBe(1);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Test valid Double Line Comment statement', () => {
 | 
			
		||||
        const sql = `----test comment\n`;
 | 
			
		||||
        const result = parser.validate(sql);
 | 
			
		||||
        const result = mysql.validate(sql);
 | 
			
		||||
        expect(result.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Test valid Hash Sign Line Comment statement', () => {
 | 
			
		||||
        const sql = `#test comment\n`;
 | 
			
		||||
        const result = parser.validate(sql);
 | 
			
		||||
        const result = mysql.validate(sql);
 | 
			
		||||
        expect(result.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { readSQL } from 'test/helper';
 | 
			
		||||
 | 
			
		||||
const parser = new MySQL();
 | 
			
		||||
const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
const features = {
 | 
			
		||||
    alterUser: readSQL(__dirname, 'alterUser.sql'),
 | 
			
		||||
@ -40,7 +40,7 @@ describe('MySQL Database Administration Syntax Tests', () => {
 | 
			
		||||
    Object.keys(features).forEach((key) => {
 | 
			
		||||
        features[key].forEach((sql) => {
 | 
			
		||||
            it(sql, () => {
 | 
			
		||||
                const result = parser.validate(sql);
 | 
			
		||||
                const result = mysql.validate(sql);
 | 
			
		||||
                if (result.length) {
 | 
			
		||||
                    console.error(result, `\nPlease check sql: ${sql}`);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { readSQL } from 'test/helper';
 | 
			
		||||
 | 
			
		||||
const parser = new MySQL();
 | 
			
		||||
const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
const features = {
 | 
			
		||||
    alterDatabase: readSQL(__dirname, 'alterDatabase.sql'),
 | 
			
		||||
@ -47,7 +47,7 @@ describe('MySQL DDL Syntax Tests', () => {
 | 
			
		||||
    Object.keys(features).forEach((key) => {
 | 
			
		||||
        features[key].forEach((sql) => {
 | 
			
		||||
            it(sql, () => {
 | 
			
		||||
                const result = parser.validate(sql);
 | 
			
		||||
                const result = mysql.validate(sql);
 | 
			
		||||
                if (result.length) {
 | 
			
		||||
                    console.error(result, `\nPlease check sql: ${sql}`);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { readSQL } from 'test/helper';
 | 
			
		||||
 | 
			
		||||
const parser = new MySQL();
 | 
			
		||||
const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
const features = {
 | 
			
		||||
    call: readSQL(__dirname, 'call.sql'),
 | 
			
		||||
@ -31,7 +31,7 @@ describe('MySQL DML Syntax Tests', () => {
 | 
			
		||||
    Object.keys(features).forEach((key) => {
 | 
			
		||||
        features[key].forEach((sql) => {
 | 
			
		||||
            it(sql, () => {
 | 
			
		||||
                const result = parser.validate(sql);
 | 
			
		||||
                const result = mysql.validate(sql);
 | 
			
		||||
                if (result.length) {
 | 
			
		||||
                    console.error(result, `\nPlease check sql: ${sql}`);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { readSQL } from 'test/helper';
 | 
			
		||||
 | 
			
		||||
const parser = new MySQL();
 | 
			
		||||
const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
const features = {
 | 
			
		||||
    commit: readSQL(__dirname, 'commit.sql'),
 | 
			
		||||
@ -25,7 +25,7 @@ describe('MySQL Transactional and Locking, Replication, Prepared Compound and Ut
 | 
			
		||||
    Object.keys(features).forEach((key) => {
 | 
			
		||||
        features[key].forEach((sql) => {
 | 
			
		||||
            it(sql, () => {
 | 
			
		||||
                const result = parser.validate(sql);
 | 
			
		||||
                const result = mysql.validate(sql);
 | 
			
		||||
                if (result.length) {
 | 
			
		||||
                    console.error(result, `\nPlease check sql: ${sql}`);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -1,16 +1,16 @@
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
 | 
			
		||||
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
 | 
			
		||||
const unCompleteSQL = `CREATE TABLE`;
 | 
			
		||||
 | 
			
		||||
describe('MySQL validate invalid sql', () => {
 | 
			
		||||
    const parser = new MySQL();
 | 
			
		||||
    const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
    test('validate random text', () => {
 | 
			
		||||
        expect(parser.validate(randomText).length).not.toBe(0);
 | 
			
		||||
        expect(mysql.validate(randomText).length).not.toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('validate unComplete sql', () => {
 | 
			
		||||
        expect(parser.validate(unCompleteSQL).length).not.toBe(0);
 | 
			
		||||
        expect(mysql.validate(unCompleteSQL).length).not.toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -1,13 +1,13 @@
 | 
			
		||||
import MySQL from 'src/parser/mysql';
 | 
			
		||||
import { MySQL } from 'src/parser/mysql';
 | 
			
		||||
import { MySqlParserVisitor } from 'src/lib/mysql/MySqlParserVisitor';
 | 
			
		||||
import { AbstractParseTreeVisitor } from 'antlr4ng';
 | 
			
		||||
 | 
			
		||||
describe('MySQL Visitor Tests', () => {
 | 
			
		||||
    const expectTableName = 'user1';
 | 
			
		||||
    const sql = `select id,name,sex from ${expectTableName};`;
 | 
			
		||||
    const parser = new MySQL();
 | 
			
		||||
    const mysql = new MySQL();
 | 
			
		||||
 | 
			
		||||
    const parseTree = parser.parse(sql, (error) => {
 | 
			
		||||
    const parseTree = mysql.parse(sql, (error) => {
 | 
			
		||||
        console.error('Parse error:', error);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user