2010-12-11 19:07:05 +08:00
|
|
|
var helper = require(__dirname + '/test-helper');
|
2011-03-04 02:05:29 +08:00
|
|
|
var q = {};
|
2011-07-11 04:49:52 +08:00
|
|
|
q.dateParser = require(__dirname + "/../../../lib/types").getTypeParser(1114, 'text');
|
2011-11-19 04:12:28 +08:00
|
|
|
q.stringArrayParser = require(__dirname + "/../../../lib/types").getTypeParser(1009, 'text');
|
2010-12-11 19:07:05 +08:00
|
|
|
|
|
|
|
test("testing dateParser", function() {
|
2012-12-11 11:24:40 +08:00
|
|
|
assert.equal(q.dateParser("2010-12-11 09:09:04").toString(),new Date("2010-12-11 09:09:04").toString());
|
2010-12-11 19:07:05 +08:00
|
|
|
});
|
|
|
|
|
2011-01-24 13:58:03 +08:00
|
|
|
var testForMs = function(part, expected) {
|
|
|
|
var dateString = "2010-01-01 01:01:01" + part;
|
|
|
|
test('testing for correcting parsing of ' + dateString, function() {
|
|
|
|
var ms = q.dateParser(dateString).getMilliseconds();
|
|
|
|
assert.equal(ms, expected)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
testForMs('.1', 100);
|
|
|
|
testForMs('.01', 10);
|
|
|
|
testForMs('.74', 740);
|
|
|
|
|
2012-12-11 11:24:40 +08:00
|
|
|
test("testing 2dateParser on dates without timezones", function() {
|
2011-01-24 13:58:03 +08:00
|
|
|
var actual = "2010-12-11 09:09:04.1";
|
2012-12-11 11:24:40 +08:00
|
|
|
var expected = JSON.stringify(new Date(2010,11,11,9,9,4,100))
|
2011-01-24 12:19:55 +08:00
|
|
|
assert.equal(JSON.stringify(q.dateParser(actual)),expected);
|
|
|
|
});
|
|
|
|
|
2012-12-11 11:24:40 +08:00
|
|
|
test("testing 2dateParser on dates with timezones", function() {
|
2011-01-24 12:19:55 +08:00
|
|
|
var actual = "2011-01-23 22:15:51.28-06";
|
|
|
|
var expected = "\"2011-01-24T04:15:51.280Z\"";
|
|
|
|
assert.equal(JSON.stringify(q.dateParser(actual)),expected);
|
2011-01-08 23:34:47 +08:00
|
|
|
});
|
|
|
|
|
2012-12-11 11:24:40 +08:00
|
|
|
test("testing 2dateParser on dates with huge millisecond value", function() {
|
2011-01-24 13:58:03 +08:00
|
|
|
var actual = "2011-01-23 22:15:51.280843-06";
|
|
|
|
var expected = "\"2011-01-24T04:15:51.280Z\"";
|
|
|
|
assert.equal(JSON.stringify(q.dateParser(actual)),expected);
|
|
|
|
});
|
|
|
|
|
2011-10-24 21:08:05 +08:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2011-11-30 08:54:01 +08:00
|
|
|
test("testing stringy array containing escaped strings", function(){
|
|
|
|
var input = '{"\\"\\"\\"","\\\\\\\\\\\\"}';
|
|
|
|
var expected = ['"""','\\\\\\'];
|
|
|
|
assert.deepEqual(q.stringArrayParser(input), expected);
|
|
|
|
});
|
|
|
|
|
2011-10-24 21:08:05 +08:00
|
|
|
test("testing NULL array", function(){
|
|
|
|
var input = '{NULL,NULL}';
|
|
|
|
var expected = [null,null];
|
|
|
|
assert.deepEqual(q.stringArrayParser(input), expected);
|
|
|
|
});
|