Merge pull request #607 from gurjeet/improve_escape_tests

Improve unit tests of escape-literal/identifier, and remove them from integration tests.
This commit is contained in:
Brian C 2014-07-06 19:25:16 -04:00
commit c4f914166f
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() { var testLit = function(testName, input, expected) {
createClient(function(client) { test(testName, function(){
var expected = "'hello world'"; var client = new Client(helper.config);
var actual = client.escapeLiteral('hello world'); var actual = client.escapeLiteral(input);
assert.equal(expected, actual); assert.equal(expected, actual);
client.end();
}); });
}); };
test('escapeLiteral: contains double quotes only', function() { var testIdent = function(testName, input, expected) {
createClient(function(client) { test(testName, function(){
var expected = "'hello \" world'"; var client = new Client(helper.config);
var actual = client.escapeLiteral('hello " world'); var actual = client.escapeIdentifier(input);
assert.equal(expected, actual); assert.equal(expected, actual);
client.end();
}); });
}); };
test('escapeLiteral: contains single quotes only', function() { testLit('escapeLiteral: no special characters',
createClient(function(client) { 'hello world', "'hello world'");
var expected = "'hello \'\' world'";
var actual = client.escapeLiteral('hello \' world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeLiteral: contains backslashes only', function() { testLit('escapeLiteral: contains double quotes only',
createClient(function(client) { 'hello " world', "'hello \" world'");
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() { testLit('escapeLiteral: contains single quotes only',
createClient(function(client) { 'hello \' world', "'hello \'\' world'");
var expected = "'hello '' \" world'";
var actual = client.escapeLiteral('hello \' " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeLiteral: contains double quotes and backslashes', function() { testLit('escapeLiteral: contains backslashes only',
createClient(function(client) { 'hello \\ world', " E'hello \\\\ world'");
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() { testLit('escapeLiteral: contains single quotes and double quotes',
createClient(function(client) { 'hello \' " world', "'hello '' \" world'");
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() { testLit('escapeLiteral: contains double quotes and backslashes',
createClient(function(client) { 'hello \\ " world', " E'hello \\\\ \" world'");
var expected = " E'hello \\\\ '' \" world'";
var actual = client.escapeLiteral('hello \\ \' " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: no special characters', function() { testLit('escapeLiteral: contains single quotes and backslashes',
createClient(function(client) { 'hello \\ \' world', " E'hello \\\\ '' world'");
var expected = '"hello world"';
var actual = client.escapeIdentifier('hello world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains double quotes only', function() { testLit('escapeLiteral: contains single quotes, double quotes, and backslashes',
createClient(function(client) { 'hello \\ \' " world', " E'hello \\\\ '' \" world'");
var expected = '"hello "" world"';
var actual = client.escapeIdentifier('hello " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains single quotes only', function() { testIdent('escapeIdentifier: no special characters',
createClient(function(client) { 'hello world', '"hello world"');
var expected = '"hello \' world"';
var actual = client.escapeIdentifier('hello \' world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains backslashes only', function() { testIdent('escapeIdentifier: contains double quotes only',
createClient(function(client) { 'hello " world', '"hello "" world"');
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() { testIdent('escapeIdentifier: contains single quotes only',
createClient(function(client) { 'hello \' world', '"hello \' world"');
var expected = '"hello \' "" world"';
var actual = client.escapeIdentifier('hello \' " world');
assert.equal(expected, actual);
client.end();
});
});
test('escapeIdentifier: contains double quotes and backslashes', function() { testIdent('escapeIdentifier: contains backslashes only',
return createClient(function(client) { 'hello \\ world', '"hello \\ world"');
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() { testIdent('escapeIdentifier: contains single quotes and double quotes',
createClient(function(client) { 'hello \' " world', '"hello \' "" world"');
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() { testIdent('escapeIdentifier: contains double quotes and backslashes',
createClient(function(client) { 'hello \\ " world', '"hello \\ "" world"');
var expected = '"hello \\ \' "" world"';
var actual = client.escapeIdentifier('hello \\ \' " world'); testIdent('escapeIdentifier: contains single quotes and backslashes',
assert.equal(expected, actual); 'hello \\ \' world', '"hello \\ \' world"');
client.end();
}); testIdent('escapeIdentifier: contains single quotes, double quotes, and backslashes',
}); 'hello \\ \' " world', '"hello \\ \' "" world"');