lava-oushudb-dt-sql-parser/test/utils/index.test.ts

49 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-09-25 15:43:36 +08:00
import * as utils from '../../src/utils';
describe('utils', () => {
describe('split sql', () => {
test('single', () => {
let sql = 'select id,name from user';
let result = utils.splitSql(sql);
2020-08-28 13:29:47 +08:00
expect(result).toEqual([sql.length - 1]);
2019-09-25 15:43:36 +08:00
sql += ';';
result = utils.splitSql(sql);
2020-08-28 13:29:47 +08:00
expect(result).toEqual([sql.length - 1]);
2019-09-25 15:43:36 +08:00
});
test('multiple', () => {
const sql = `-- a ;
select * from a;
select user from b`;
const result = utils.splitSql(sql);
2020-08-28 13:29:47 +08:00
expect(result).toEqual([34, 65]);
2019-09-25 15:43:36 +08:00
});
2019-09-29 17:38:52 +08:00
test('error sql', () => {
const sql = `CREATE TABLE MyResult(
a double,
b timestamp,
c timestamp
)WITH(
type ='mysql,
url ='jdbc:mysql://1.1.1.1:3306/hi?charset=utf8',
userName ='name',
password ='123',
tableName ='user'
);`;
const result = utils.splitSql(sql);
2020-08-28 13:29:47 +08:00
expect(result).toEqual([337]);
2019-09-29 17:38:52 +08:00
const sql2 = `CREATE TABLE MyResult(
a double,
b timestamp,
c timestamp
)WITH(
type ='mysql,
url ='jdbc:mysql://1.1.1.1:3306/hi?charset=utf8',
userName ='name',
password ='123',
tableName ='user'
)`;
const result2 = utils.splitSql(sql2);
2020-08-28 13:29:47 +08:00
expect(result2).toEqual([336]);
2019-09-29 17:38:52 +08:00
});
2020-08-28 13:29:47 +08:00
});
});