Skip to content

Commit

Permalink
New specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Maurits Rijk committed Sep 15, 2017
1 parent 2c6f2b8 commit c380ec8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions specs/and.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const s = require('../lib/spec');
const isPred = require('./pred');

module.exports = {
args: s.star(isPred),
ret: s.isSpec
};
9 changes: 9 additions & 0 deletions specs/or.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const s = require('../lib/spec');
const isPred = require('./pred');

const {isString} = s.utils;

module.exports = {
args: s.star(s.tuple(isString, isPred)),
ret: s.isSpec
};
10 changes: 9 additions & 1 deletion test/and.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {expect} = require('chai');

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

const {idemPotent} = require('./utils');
const {exerciseFunc, idemPotent} = require('./utils');

const {isEven, isInteger, invalidString, unknownString} = s.utils;

Expand All @@ -29,6 +29,10 @@ describe('Test the and function', () => {
expect(s.conform(s.and(s.cat('n1', isInteger), '::one-bigger'), [13])).to.eql({n1: 13});
});

it('should allow zero predicates on any input', () => {
expect(s.isValid(s.and(), [])).to.be.true;
});

it('should unform a conformed value', () => {
expect(idemPotent('::even?', 42)).to.be.true;
});
Expand Down Expand Up @@ -56,5 +60,9 @@ describe('Test the and function', () => {
it('should implement describe', () => {
expect(s.describe('::even?')).to.eql(['and', 'isInteger', 'isEven']);
});

xit('should exercise the and spec', () => {
exerciseFunc(s.and, '../specs/and');
});
});

10 changes: 9 additions & 1 deletion test/or.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {expect} = require('chai');;

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

const {idemPotent} = require('./utils');
const {exerciseFunc, idemPotent} = require('./utils');

const {isInt, isInteger, isString, unknownString} = s.utils;

Expand All @@ -31,6 +31,10 @@ describe('Test the or function', () => {
expect(s.conform('::name-or-id', 13)).to.eql([':id', 13]);
});

it('should not allow zero predicates on any input', () => {
expect(s.isValid(s.or(), [])).to.be.false;
});

it('should unform a conformed value', () => {
expect(idemPotent('::name-or-id', 'abc')).to.be.true;
});
Expand Down Expand Up @@ -69,4 +73,8 @@ describe('Test the or function', () => {
it('should implement describe', () => {
expect(s.describe('::name-or-id')).to.eql(['or', ':name', 'isString', ':id', 'isInt']);
});

xit('should exercise the or spec', () => {
exerciseFunc(s.or, '../specs/or');
});
});

0 comments on commit c380ec8

Please sign in to comment.