2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 17:29:07 +08:00
|
|
|
require('../support/test-helper');
|
2016-02-04 17:26:31 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var assert = require('assert');
|
|
|
|
var TableNameParser = require('../../lib/utils/table-name-parser');
|
|
|
|
|
|
|
|
describe('TableNameParser', function () {
|
|
|
|
it('parses table names with scheme and quotes', function (done) {
|
|
|
|
var test_cases = [
|
|
|
|
['xyz', { schema: null, table: 'xyz' }],
|
|
|
|
['"xyz"', { schema: null, table: 'xyz' }],
|
|
|
|
['"xy z"', { schema: null, table: 'xy z' }],
|
|
|
|
['"xy.z"', { schema: null, table: 'xy.z' }],
|
|
|
|
['"x.y.z"', { schema: null, table: 'x.y.z' }],
|
|
|
|
['abc.xyz', { schema: 'abc', table: 'xyz' }],
|
|
|
|
['"abc".xyz', { schema: 'abc', table: 'xyz' }],
|
|
|
|
['abc."xyz"', { schema: 'abc', table: 'xyz' }],
|
|
|
|
['"abc"."xyz"', { schema: 'abc', table: 'xyz' }],
|
|
|
|
['"a bc"."x yz"', { schema: 'a bc', table: 'x yz' }],
|
|
|
|
['"a bc".xyz', { schema: 'a bc', table: 'xyz' }],
|
|
|
|
['"a.bc".xyz', { schema: 'a.bc', table: 'xyz' }],
|
|
|
|
['"a.b.c".xyz', { schema: 'a.b.c', table: 'xyz' }],
|
|
|
|
['"a.b.c.".xyz', { schema: 'a.b.c.', table: 'xyz' }],
|
|
|
|
['"a""bc".xyz', { schema: 'a"bc', table: 'xyz' }],
|
|
|
|
['"a""bc"."x""yz"', { schema: 'a"bc', table: 'x"yz' }]
|
|
|
|
];
|
|
|
|
|
|
|
|
test_cases.forEach(function (test_case) {
|
|
|
|
var table_name = test_case[0];
|
|
|
|
var expected_result = test_case[1];
|
|
|
|
var result = TableNameParser.parse(table_name);
|
|
|
|
assert.deepEqual(result, expected_result);
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('quotes identifiers that need quoting', function (done) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(TableNameParser.quote('x yz'), '"x yz"');
|
|
|
|
assert.strictEqual(TableNameParser.quote('x-yz'), '"x-yz"');
|
|
|
|
assert.strictEqual(TableNameParser.quote('x.yz'), '"x.yz"');
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('doubles quotes', function (done) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(TableNameParser.quote('x"yz'), '"x""yz"');
|
|
|
|
assert.strictEqual(TableNameParser.quote('x"y"z'), '"x""y""z"');
|
|
|
|
assert.strictEqual(TableNameParser.quote('x""y"z'), '"x""""y""z"');
|
|
|
|
assert.strictEqual(TableNameParser.quote('x "yz'), '"x ""yz"');
|
|
|
|
assert.strictEqual(TableNameParser.quote('x"y-y"z'), '"x""y-y""z"');
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not quote identifiers that don\'t need to be quoted', function (done) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(TableNameParser.quote('xyz'), 'xyz');
|
|
|
|
assert.strictEqual(TableNameParser.quote('x_z123'), 'x_z123');
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
});
|
2016-02-04 17:26:31 +08:00
|
|
|
});
|