2013-07-13 01:08:00 +08:00
|
|
|
var helper = require(__dirname + '/test-helper');
|
|
|
|
|
|
|
|
function createClient(callback) {
|
|
|
|
var client = new Client(helper.config);
|
|
|
|
client.connect(function(err) {
|
|
|
|
return callback(client);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
var testLit = function(testName, input, expected) {
|
|
|
|
test(testName, function(){
|
|
|
|
var client = new Client(helper.config);
|
|
|
|
var actual = client.escapeLiteral(input);
|
2013-07-13 01:08:00 +08:00
|
|
|
assert.equal(expected, actual);
|
|
|
|
});
|
2014-06-16 05:09:34 +08:00
|
|
|
};
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
var testIdent = function(testName, input, expected) {
|
|
|
|
test(testName, function(){
|
|
|
|
var client = new Client(helper.config);
|
|
|
|
var actual = client.escapeIdentifier(input);
|
2013-07-13 01:08:00 +08:00
|
|
|
assert.equal(expected, actual);
|
|
|
|
});
|
2014-06-16 05:09:34 +08:00
|
|
|
};
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testLit('escapeLiteral: no special characters',
|
|
|
|
'hello world', "'hello world'");
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testLit('escapeLiteral: contains double quotes only',
|
|
|
|
'hello " world', "'hello \" world'");
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testLit('escapeLiteral: contains single quotes only',
|
|
|
|
'hello \' world', "'hello \'\' world'");
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testLit('escapeLiteral: contains backslashes only',
|
|
|
|
'hello \\ world', " E'hello \\\\ world'");
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testLit('escapeLiteral: contains single quotes and double quotes',
|
|
|
|
'hello \' " world', "'hello '' \" world'");
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testLit('escapeLiteral: contains double quotes and backslashes',
|
|
|
|
'hello \\ " world', " E'hello \\\\ \" world'");
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testLit('escapeLiteral: contains single quotes and backslashes',
|
|
|
|
'hello \\ \' world', " E'hello \\\\ '' world'");
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testLit('escapeLiteral: contains single quotes, double quotes, and backslashes',
|
|
|
|
'hello \\ \' " world', " E'hello \\\\ '' \" world'");
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testIdent('escapeIdentifier: no special characters',
|
|
|
|
'hello world', '"hello world"');
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testIdent('escapeIdentifier: contains double quotes only',
|
|
|
|
'hello " world', '"hello "" world"');
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testIdent('escapeIdentifier: contains single quotes only',
|
|
|
|
'hello \' world', '"hello \' world"');
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testIdent('escapeIdentifier: contains backslashes only',
|
|
|
|
'hello \\ world', '"hello \\ world"');
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testIdent('escapeIdentifier: contains single quotes and double quotes',
|
|
|
|
'hello \' " world', '"hello \' "" world"');
|
2013-07-13 01:08:00 +08:00
|
|
|
|
2014-06-16 05:09:34 +08:00
|
|
|
testIdent('escapeIdentifier: contains double quotes and backslashes',
|
|
|
|
'hello \\ " world', '"hello \\ "" world"');
|
|
|
|
|
|
|
|
testIdent('escapeIdentifier: contains single quotes and backslashes',
|
|
|
|
'hello \\ \' world', '"hello \\ \' world"');
|
|
|
|
|
|
|
|
testIdent('escapeIdentifier: contains single quotes, double quotes, and backslashes',
|
|
|
|
'hello \\ \' " world', '"hello \\ \' "" world"');
|