Skip to content

Commit

Permalink
Add spec for isRegex and isSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
Maurits Rijk committed May 23, 2017
1 parent dc185f5 commit 740a564
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions specs/isRegex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const _ = require('lodash');

const s = require('../lib/spec');
const isPred = require('./pred');

const {isNull} = s.utils;

module.exports = {
args: s.cat('x', isPred),
ret: s.or(':null?', isNull, ':other', () => true),
fn: ({args, ret}) => isNull(ret) || _.isEqual(ret, args.x)
};
12 changes: 12 additions & 0 deletions specs/isSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const _ = require('lodash');

const s = require('../lib/spec');
const isPred = require('./pred');

const {isNull} = s.utils;

module.exports = {
args: s.cat('x', isPred),
ret: s.or(':null?', isNull, ':other', () => true),
fn: ({args, ret}) => isNull(ret) || _.isEqual(ret, args.x)
};
2 changes: 1 addition & 1 deletion specs/pred.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const testcheck = require('testcheck');
const {isInteger, isString, isDate} = s.utils;

// Simple definition of a predicate
const genPred = () => testcheck.gen.oneOf([isInteger, isDate, isString, s.tuple(isInteger)]);
const genPred = () => testcheck.gen.oneOf([isInteger, isDate, isString, s.tuple(isInteger), s.alt(':s', isString)]);
const isPred = s.spec(x => _.isFunction(x) || s.isSpec(x), {gen: genPred});

module.exports = isPred;
6 changes: 6 additions & 0 deletions test/isRegex.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const {expect} = require('chai');

const s = require('../lib/spec');

const {check} = require('./utils');

const {isString} = s.utils;

describe('Test the isRegex function', () => {
Expand All @@ -15,4 +17,8 @@ describe('Test the isRegex function', () => {
const foo = s.and(isString);
expect(s.isRegex(foo)).to.be.null;
});

it('should use the spec to test', () => {
expect(check(s.isRegex, '../specs/isRegex')).to.have.property('result').to.equal(true);
});
});
6 changes: 6 additions & 0 deletions test/isSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const {expect} = require('chai');

const s = require('../lib/spec');

const {check} = require('./utils');

describe('Test the isSpec function', () => {

it('should return the spec object', () => {
Expand All @@ -17,4 +19,8 @@ describe('Test the isSpec function', () => {
it('should return null if the parameter is an integer', () => {
expect(s.isSpec(1)).to.be.null;
});

it('should use the spec to test', () => {
expect(check(s.isSpec, '../specs/isSpec')).to.have.property('result').to.equal(true);
});
});

0 comments on commit 740a564

Please sign in to comment.