Skip to content

stringArrayParser can parse empty arrays + stringArrayParser tests #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var parseIntegerArray = function(val) {

var parseStringArray = function(val) {
if (!val) return null;
if (val === '{}') return [];
if (val[0] !== '{' || val[val.length-1] !== '}')
throw "Not postgresql array! (" + arrStr + ")";

Expand Down
30 changes: 30 additions & 0 deletions test/unit/client/query-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var helper = require(__dirname + '/test-helper');
var q = {};
q.dateParser = require(__dirname + "/../../../lib/types").getStringTypeParser(1114);
q.stringArrayParser = require(__dirname + "/../../../lib/types").getStringTypeParser(1009);

test("testing dateParser", function() {
assert.equal(q.dateParser("2010-12-11 09:09:04").toUTCString(),new Date("2010-12-11 09:09:04 GMT").toUTCString());
Expand Down Expand Up @@ -36,3 +37,32 @@ test("testing 2dateParser", function() {
assert.equal(JSON.stringify(q.dateParser(actual)),expected);
});

test("testing empty array", function(){
var input = '{}';
var expected = [];
assert.deepEqual(q.stringArrayParser(input), expected);
});

test("testing empty string array", function(){
var input = '{""}';
var expected = [""];
assert.deepEqual(q.stringArrayParser(input), expected);
});

test("testing numeric array", function(){
var input = '{1,2,3,4}';
var expected = [1,2,3,4];
assert.deepEqual(q.stringArrayParser(input), expected);
});

test("testing stringy array", function(){
var input = '{a,b,c,d}';
var expected = ['a','b','c','d'];
assert.deepEqual(q.stringArrayParser(input), expected);
});

test("testing NULL array", function(){
var input = '{NULL,NULL}';
var expected = [null,null];
assert.deepEqual(q.stringArrayParser(input), expected);
});