refactored test. added assertion macro

This commit is contained in:
brianc 2010-09-30 00:32:44 -05:00
parent 8c30521cf9
commit f541fea830
2 changed files with 31 additions and 17 deletions

View File

@ -13,35 +13,42 @@ test('Parser on single messages', function() {
test('parses AuthenticationOk message', function() { test('parses AuthenticationOk message', function() {
var result = new Parser(authenticationOkBuffer).parse(); var result = new Parser(authenticationOkBuffer).parse();
assert.equal(result.name, 'AuthenticationOk'); assert.same(result, {
assert.equal(result.id, 'R'); name: 'AuthenticationOk',
assert.equal(result.length, 8); id: 'R',
length: 8
});
}); });
test('parses ParameterStatus message', function() { test('parses ParameterStatus message', function() {
var result = new Parser(parameterStatusBuffer).parse(); var result = new Parser(parameterStatusBuffer).parse();
assert.equal(result.name, 'ParameterStatus'); assert.same(result, {
assert.equal(result.id, 'S'); name: 'ParameterStatus',
assert.equal(result.length, 25); id: 'S',
assert.equal(result.parameterName, "client_encoding"); length: 25,
assert.equal(result.parameterValue, "UTF8"); parameterName: 'client_encoding',
parameterValue: 'UTF8'
});
}); });
test('parses BackendKeyData message', function() { test('parses BackendKeyData message', function() {
var result = new Parser(backendKeyDataBuffer).parse(); var result = new Parser(backendKeyDataBuffer).parse();
assert.equal(result.name, 'BackendKeyData'); assert.same(result, {
assert.equal(result.id, 'K'); name: 'BackendKeyData',
assert.equal(result.length, 12); id: 'K',
assert.equal(result.processID, 1); processID: 1,
assert.equal(result.secretKey, 2); secretKey: 2
});
}); });
test('parses ReadyForQuery message', function() { test('parses ReadyForQuery message', function() {
var result = new Parser(readyForQueryBuffer).parse(); var result = new Parser(readyForQueryBuffer).parse();
assert.equal(result.name, 'ReadyForQuery'); assert.same(result, {
assert.equal(result.id, 'Z'); name: 'ReadyForQuery',
assert.equal(result.length, 5); id: 'Z',
assert.equal(result.status, 'I'); length: 5,
status: 'I'
});
}); });
test('parses normal CString', function() { test('parses normal CString', function() {

View File

@ -3,6 +3,13 @@ assert = require('assert');
Client = require(__dirname+"/../lib/").Client; Client = require(__dirname+"/../lib/").Client;
Parser = require(__dirname+"/../lib/").Parser; Parser = require(__dirname+"/../lib/").Parser;
assert.same = function(actual, expected) {
for(var key in expected) {
assert.equal(actual[key], expected[key]);
}
};
test = function(name, action) { test = function(name, action) {
for(var i = 0; i < test.tabout; i++) { for(var i = 0; i < test.tabout; i++) {
name = ' ' + name; name = ' ' + name;