Permalink
Browse files

Add tests for non-integer funcs.

  • Loading branch information...
1 parent 8d24dc5 commit f0f2ea7d62085321e6d671edcef3f4dd8e652fde @cliffano committed Jun 28, 2012
Showing with 129 additions and 2 deletions.
  1. +129 −2 test/functions.js
View
@@ -38,7 +38,7 @@ describe('functions', function () {
});
(_.isNaN(checks.data)).should.equal(false);
checks.data.should.not.match(/.+\..+/);
- parseInt(checks.data, 10).should.be.within(100, 200);
+ checks.data.should.be.within(100, 200);
});
it('should evaluate identical integer function when it has identical min max arguments', function (done) {
@@ -48,26 +48,153 @@ describe('functions', function () {
});
(_.isNaN(checks.data)).should.equal(false);
checks.data.should.not.match(/.+\..+/);
- parseInt(checks.data, 10).should.equal(100);
+ checks.data.should.equal(100);
});
});
describe('float', function () {
+
+ it('should evaluate float function when it has no argument', function (done) {
+ functions.float(function (data) {
+ checks.data = data;
+ done();
+ });
+ (_.isNaN(checks.data)).should.equal(false);
+ checks.data.should.match(/.+\..+/);
+ });
+
+ it('should evaluate ranged float function when it has min max arguments', function (done) {
+ functions.float(100.0, 200.0, function (data) {
+ checks.data = data;
+ done();
+ });
+ (_.isNaN(checks.data)).should.equal(false);
+ checks.data.should.match(/.+\..+/);
+ checks.data.should.be.within(100.0, 200.0);
+ });
+
+ it('should evaluate identical float function when it has identical min max arguments', function (done) {
+ functions.float(567.89, 567.89, function (data) {
+ checks.data = data;
+ done();
+ });
+ checks.data.should.match(/.+\..+/);
+ checks.data.should.equal(567.89);
+ });
});
describe('date', function () {
+
+ it('should evaluate date function with ISO format when it has no argument', function (done) {
+ functions.date(function (data) {
+ checks.data = data;
+ done();
+ });
+ checks.data.should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
+ });
+
+ it('should evaluate date function with custom format when it has format argument', function (done) {
+ functions.date('yyyy/mm/dd', function (data) {
+ checks.data = data;
+ done();
+ });
+ checks.data.should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
+ });
+
+ it('should evaluate date function with default format and ranged date when it has min max arguments and no format argument', function (done) {
+ functions.date(1998, 2000, function (data) {
+ checks.data = data;
+ done();
+ });
+ checks.data.should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
+ parseInt(checks.data.match(/^[0-9]{4}/), 10).should.be.within(1998, 1999);
+ });
+
+ it('should evaluate date function with custom format and ranged date when it has min max format arguments', function (done) {
+ functions.date('yyyy/mm/dd', 1998, 2000, function (data) {
+ checks.data = data;
+ done();
+ });
+ checks.data.should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
+ parseInt(checks.data.match(/^[0-9]{4}/), 10).should.be.within(1998, 1999);
+ });
});
describe('select', function () {
+
+ it('should evaluate select function when it has arguments', function (done) {
+ functions.select('aaa', 'bbb', 'ccc', function (data) {
+ checks.data = data;
+ done();
+ });
+ ['aaa','bbb','ccc'].indexOf(checks.data).should.be.within(0, 2);
+ });
+
+ it('should evaluate identical select function when it has only 1 argument', function (done) {
+ functions.select('aaa', function (data) {
+ checks.data = data;
+ done();
+ });
+ ['aaa'].indexOf(checks.data).should.equal(0);
+ });
+
+ it('should evaluate to empty when select function has no argument', function (done) {
+ functions.select(function (data) {
+ checks.data = data;
+ done();
+ });
+ ['aaa','bbb','ccc'].indexOf(checks.data).should.equal(-1);
+ });
});
describe('word', function () {
+
+ it('should evaluate a single word when word function has no argument', function (done) {
+ functions.word(function (data) {
+ checks.data = data;
+ done();
+ });
+ (_.isString(checks.data)).should.equal(true);
+ (checks.data.match(/[a-zA-Z]+/) !== null).should.equal(true);
+ });
+
+ it('should evaluate multiple words when word function has an argument', function (done) {
+ functions.word(5, function (data) {
+ checks.data = data;
+ done();
+ });
+ function _check(word) {
+ (_.isString(word)).should.equal(true);
+ (word.match(/[a-zA-Z]+/) !== null).should.equal(true);
+ }
+ var words = checks.data.split(' ');
+ words.length.should.equal(5);
+ words.forEach(_check);
+ });
});
describe('firstName', function () {
+
+ it('should evaluate first name function', function (done) {
+ functions.first_name(function (data) {
+ checks.data = data;
+ done();
+ });
+ (_.isString(checks.data)).should.equal(true);
+ (checks.data.match(/[a-zA-Z]+/) !== null).should.equal(true);
+ });
});
describe('lastName', function () {
+
+ it('should evaluate last name function', function (done) {
+ functions.last_name(function (data) {
+ checks.data = data;
+ done();
+ });
+ (_.isString(checks.data)).should.equal(true);
+ (checks.data.match(/[a-zA-Z]+/) !== null).should.equal(true);
+ });
});
});

0 comments on commit f0f2ea7

Please sign in to comment.