Improve unit tests of escape-literal/identifier, and remove them from integration tests.

Improve the code and clarity of unit tests in escape-tests.js. And
removed the related integration tests since it has been demonstrated in
the unit tests that a connection is not needed for escaping the literals
and identifiers.
This commit is contained in:
Gurjeet Singh 2014-06-15 17:09:34 -04:00
parent 3eccf5c4a8
commit 75760c4aa2
2 changed files with 44 additions and 278 deletions

View File

@ -1,153 +0,0 @@
var helper = require(__dirname + '/test-helper');
function createClient(callback) {
var client = new Client(helper.config);
client.connect(function(err) {
return callback(client);
});
}
test('escapeLiteral: no special characters', function() {
createClient(function(client) {
var expected = "'hello world'";
var actual = client.escapeLiteral('hello world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeLiteral: contains double quotes only', function() {
createClient(function(client) {
var expected = "'hello \" world'";
var actual = client.escapeLiteral('hello " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeLiteral: contains single quotes only', function() {
createClient(function(client) {
var expected = "'hello \'\' world'";
var actual = client.escapeLiteral('hello \' world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeLiteral: contains backslashes only', function() {
createClient(function(client) {
var expected = " E'hello \\\\ world'";
var actual = client.escapeLiteral('hello \\ world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeLiteral: contains single quotes and double quotes', function() {
createClient(function(client) {
var expected = "'hello '' \" world'";
var actual = client.escapeLiteral('hello \' " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeLiteral: contains double quotes and backslashes', function() {
createClient(function(client) {
var expected = " E'hello \\\\ \" world'";
var actual = client.escapeLiteral('hello \\ " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeLiteral: contains single quotes and backslashes', function() {
createClient(function(client) {
var expected = " E'hello \\\\ '' world'";
var actual = client.escapeLiteral('hello \\ \' world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeLiteral: contains single quotes, double quotes, and backslashes', function() {
createClient(function(client) {
var expected = " E'hello \\\\ '' \" world'";
var actual = client.escapeLiteral('hello \\ \' " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: no special characters', function() {
createClient(function(client) {
var expected = '"hello world"';
var actual = client.escapeIdentifier('hello world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains double quotes only', function() {
createClient(function(client) {
var expected = '"hello "" world"';
var actual = client.escapeIdentifier('hello " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains single quotes only', function() {
createClient(function(client) {
var expected = '"hello \' world"';
var actual = client.escapeIdentifier('hello \' world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains backslashes only', function() {
createClient(function(client) {
var expected = '"hello \\ world"';
var actual = client.escapeIdentifier('hello \\ world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains single quotes and double quotes', function() {
createClient(function(client) {
var expected = '"hello \' "" world"';
var actual = client.escapeIdentifier('hello \' " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains double quotes and backslashes', function() {
return createClient(function(client) {
var expected = '"hello \\ "" world"';
var actual = client.escapeIdentifier('hello \\ " world');
assert.equal(expected, actual);
client.end();
return;
});
});
test('escapeIdentifier: contains single quotes and backslashes', function() {
createClient(function(client) {
var expected = '"hello \\ \' world"';
var actual = client.escapeIdentifier('hello \\ \' world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains single quotes, double quotes, and backslashes', function() {
createClient(function(client) {
var expected = '"hello \\ \' "" world"';
var actual = client.escapeIdentifier('hello \\ \' " world');
assert.equal(expected, actual);
client.end();
});
});

View File

@ -7,147 +7,66 @@ function createClient(callback) {
});
}
test('escapeLiteral: no special characters', function() {
createClient(function(client) {
var expected = "'hello world'";
var actual = client.escapeLiteral('hello world');
var testLit = function(testName, input, expected) {
test(testName, function(){
var client = new Client(helper.config);
var actual = client.escapeLiteral(input);
assert.equal(expected, actual);
client.end();
});
});
};
test('escapeLiteral: contains double quotes only', function() {
createClient(function(client) {
var expected = "'hello \" world'";
var actual = client.escapeLiteral('hello " world');
var testIdent = function(testName, input, expected) {
test(testName, function(){
var client = new Client(helper.config);
var actual = client.escapeIdentifier(input);
assert.equal(expected, actual);
client.end();
});
});
};
test('escapeLiteral: contains single quotes only', function() {
createClient(function(client) {
var expected = "'hello \'\' world'";
var actual = client.escapeLiteral('hello \' world');
assert.equal(expected, actual);
client.end();
});
});
testLit('escapeLiteral: no special characters',
'hello world', "'hello world'");
test('escapeLiteral: contains backslashes only', function() {
createClient(function(client) {
var expected = " E'hello \\\\ world'";
var actual = client.escapeLiteral('hello \\ world');
assert.equal(expected, actual);
client.end();
});
});
testLit('escapeLiteral: contains double quotes only',
'hello " world', "'hello \" world'");
test('escapeLiteral: contains single quotes and double quotes', function() {
createClient(function(client) {
var expected = "'hello '' \" world'";
var actual = client.escapeLiteral('hello \' " world');
assert.equal(expected, actual);
client.end();
});
});
testLit('escapeLiteral: contains single quotes only',
'hello \' world', "'hello \'\' world'");
test('escapeLiteral: contains double quotes and backslashes', function() {
createClient(function(client) {
var expected = " E'hello \\\\ \" world'";
var actual = client.escapeLiteral('hello \\ " world');
assert.equal(expected, actual);
client.end();
});
});
testLit('escapeLiteral: contains backslashes only',
'hello \\ world', " E'hello \\\\ world'");
test('escapeLiteral: contains single quotes and backslashes', function() {
createClient(function(client) {
var expected = " E'hello \\\\ '' world'";
var actual = client.escapeLiteral('hello \\ \' world');
assert.equal(expected, actual);
client.end();
});
});
testLit('escapeLiteral: contains single quotes and double quotes',
'hello \' " world', "'hello '' \" world'");
test('escapeLiteral: contains single quotes, double quotes, and backslashes', function() {
createClient(function(client) {
var expected = " E'hello \\\\ '' \" world'";
var actual = client.escapeLiteral('hello \\ \' " world');
assert.equal(expected, actual);
client.end();
});
});
testLit('escapeLiteral: contains double quotes and backslashes',
'hello \\ " world', " E'hello \\\\ \" world'");
test('escapeIdentifier: no special characters', function() {
createClient(function(client) {
var expected = '"hello world"';
var actual = client.escapeIdentifier('hello world');
assert.equal(expected, actual);
client.end();
});
});
testLit('escapeLiteral: contains single quotes and backslashes',
'hello \\ \' world', " E'hello \\\\ '' world'");
test('escapeIdentifier: contains double quotes only', function() {
createClient(function(client) {
var expected = '"hello "" world"';
var actual = client.escapeIdentifier('hello " world');
assert.equal(expected, actual);
client.end();
});
});
testLit('escapeLiteral: contains single quotes, double quotes, and backslashes',
'hello \\ \' " world', " E'hello \\\\ '' \" world'");
test('escapeIdentifier: contains single quotes only', function() {
createClient(function(client) {
var expected = '"hello \' world"';
var actual = client.escapeIdentifier('hello \' world');
assert.equal(expected, actual);
client.end();
});
});
testIdent('escapeIdentifier: no special characters',
'hello world', '"hello world"');
test('escapeIdentifier: contains backslashes only', function() {
createClient(function(client) {
var expected = '"hello \\ world"';
var actual = client.escapeIdentifier('hello \\ world');
assert.equal(expected, actual);
client.end();
});
});
testIdent('escapeIdentifier: contains double quotes only',
'hello " world', '"hello "" world"');
test('escapeIdentifier: contains single quotes and double quotes', function() {
createClient(function(client) {
var expected = '"hello \' "" world"';
var actual = client.escapeIdentifier('hello \' " world');
assert.equal(expected, actual);
client.end();
});
});
testIdent('escapeIdentifier: contains single quotes only',
'hello \' world', '"hello \' world"');
test('escapeIdentifier: contains double quotes and backslashes', function() {
return createClient(function(client) {
var expected = '"hello \\ "" world"';
var actual = client.escapeIdentifier('hello \\ " world');
assert.equal(expected, actual);
client.end();
return;
});
});
testIdent('escapeIdentifier: contains backslashes only',
'hello \\ world', '"hello \\ world"');
test('escapeIdentifier: contains single quotes and backslashes', function() {
createClient(function(client) {
var expected = '"hello \\ \' world"';
var actual = client.escapeIdentifier('hello \\ \' world');
assert.equal(expected, actual);
client.end();
});
});
testIdent('escapeIdentifier: contains single quotes and double quotes',
'hello \' " world', '"hello \' "" world"');
test('escapeIdentifier: contains single quotes, double quotes, and backslashes', function() {
createClient(function(client) {
var expected = '"hello \\ \' "" world"';
var actual = client.escapeIdentifier('hello \\ \' " world');
assert.equal(expected, actual);
client.end();
});
});
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"');