Skip to content

Commit

Permalink
Add more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Maurits Rijk committed Sep 15, 2017
1 parent 6c646ea commit 2c6f2b8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 4 deletions.
9 changes: 9 additions & 0 deletions specs/cat.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.isRegex
};
7 changes: 7 additions & 0 deletions specs/plus.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.cat(':pred', isPred),
ret: s.isRegex
};
2 changes: 1 addition & 1 deletion specs/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ const isPred = require('./pred');

module.exports = {
args: s.cat(':pred', isPred),
ret: s.isSpec
ret: s.isRegex
};
7 changes: 7 additions & 0 deletions specs/star.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.cat(':pred', isPred),
ret: s.isRegex
};
14 changes: 13 additions & 1 deletion test/cat.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, isNumber, isOdd, isString} = s.utils;

Expand Down Expand Up @@ -35,13 +35,21 @@ describe('Test the cat function', () => {
it('explainData should return null', () => {
expect(s.explainData('::ingredient', [2, ':teaspoon'])).to.be.null;
});

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

describe('should reject invalid input', () => {
it('should fail if concatenation doesn\'t match', () => {
expect(s.isValid('::ingredient', [2, 13])).to.be.false;
});

xit('should fail when no predicate supplied', () => {
expect(s.isValid(s.cat(), [1])).to.be.false;
});

it('explainData should report about insufficient input', () => {
expect(s.explainData('::ingredient', [2])).to.eql({
problems: [
Expand Down Expand Up @@ -90,5 +98,9 @@ describe('Test the cat function', () => {
it('should implement describe', () => {
expect(s.describe('::ingredient')).to.eql(['cat', ':quantity', 'isNumber', ':unit', 'isString']);
});

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

4 changes: 4 additions & 0 deletions test/intIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ describe('Test the IntIn function', () => {
});

describe('should reject invalid input', () => {
it('should return always false if upper bound less than lower bound', () => {
expect(s.isValid(s.intIn(256, 0), 0)).to.be.false;
});

it('should exclude the upper bound', () => {
expect(s.isValid('::oneByte', 256)).to.be.false;
});
Expand Down
6 changes: 5 additions & 1 deletion test/plus.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 {isInteger, isOdd, invalidString} = s.utils;

Expand Down Expand Up @@ -76,5 +76,9 @@ describe('Test the plus (+) function', () => {
it('should implement describe', () => {
expect(s.describe('::odds')).to.eql(['plus', '::odd?']);
});

it('should exercise the plus function', () => {
exerciseFunc(s.plus, '../specs/plus');
});
});

6 changes: 5 additions & 1 deletion test/star.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 {invalidString, isBoolean, isInteger, isOdd, isString} = s.utils;

Expand Down Expand Up @@ -74,4 +74,8 @@ describe('Test the star (*) function', () => {
s.def('::odds', s.star(isOdd))
expect(s.describe('::odds')).to.eql(['star', 'isOdd']);
});

it('should exercise the star function', () => {
exerciseFunc(s.star, '../specs/star');
});
});

0 comments on commit 2c6f2b8

Please sign in to comment.