Skip to content

Commit

Permalink
Update docs + minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mrijk committed Apr 13, 2017
1 parent d54739b commit b6a033b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 32 deletions.
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [explain](docs/api/explain.md)
* [fdef](docs/api/fdef.md)
* [gen](docs/api/gen.md)
* [getSpec](docs/api/getSpec.md)
* [intIn](docs/api/intIn.md)
* [isIntInRange](docs/api/isIntInRange.md)
* [isValid](docs/api/isValid.md)
Expand Down
11 changes: 6 additions & 5 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ Descriptions for the different functions where copied from the original

| clojure.spec | speculaas |
|:-------------:|:------------:|
| & | [amp](api/amp.md) |
| + | [plus](api/plus.md) |
| * | [star](api/star.md) |
| coll-of | [collOf](api/collOf.md) |
| double-in | [doubleIn](api/doubleIn.md) |
| & | [amp](api/amp.md) |
| + | [plus](api/plus.md) |
| * | [star](api/star.md) |
| coll-of | [collOf](api/collOf.md) |
| double-in | [doubleIn](api/doubleIn.md) |
| get-spec | [getSpec](api/getSpec.md) |
| int-in | [intIn](api/intIn.md) |
| int-in-range? | [isIntInRange](api/isIntInRange.md) |
| map-of | [mapOf](api/mapOf.md) |
Expand Down
16 changes: 16 additions & 0 deletions docs/api/cat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cat
=====

Usage: ```cat(...)```

Returns a regex op that matches (all) values in sequence, returning a map
containing the keys of each pred and the corresponding value.

[Source](https://github.com/mrijk/speculaas/blob/master/lib/cat.js)

Example:

```js
const s = require('speculaas');
const {isBoolean, isString} = s.utils;
```
19 changes: 19 additions & 0 deletions docs/api/getSpec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
getSpec
=====

Usage: ```getSpec(k)```

Returns spec registered for keyword/symbol/var k, or undefined.

[Source](https://github.com/mrijk/speculaas/blob/master/lib/def.js)

Example:

```js
const s = require('speculaas');
const {isOdd} = s.utils;

s.def('::odd?', isOdd);
s.getSpec('::odd?');

```
2 changes: 1 addition & 1 deletion lib/def.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function createFunctionSpec(predicate) {
}

function getSpec(p) {
if (_.isString(p)) {
if (_.isString(p) || _.isSymbol(p)) {
return defs[p];
} else if (_.isObject(p)) {
return p;
Expand Down
19 changes: 19 additions & 0 deletions test/def.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const {expect} = require('chai');

const s = require('../lib/spec');
const {isOdd} = s.utils;

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

it('should allow an array as predicate', () => {
const suit = [':club', ':diamond', ':heart', ':spade'];
s.def('::suit', suit);
expect(s.isValid('::suit', ':club')).to.be.true;
});

it('should accept a Symbol', () => {
const odd = Symbol();
s.def(odd, isOdd);
expect(s.isValid(odd, 13)).to.be.true;
});
});
16 changes: 16 additions & 0 deletions test/getSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const {expect} = require('chai');

const s = require('../lib/spec');
const {isOdd, isInteger} = s.utils;

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

it('should return an existing spec', () => {
s.def('::odd?', s.and(isInteger, isOdd));
expect(s.getSpec('::odd?')).to.exist;
});

it('should return null on an non-existing spec', () => {
expect(s.getSpec('::foobar?')).to.be.undefined;
});
});
26 changes: 0 additions & 26 deletions test/spec.js

This file was deleted.

0 comments on commit b6a033b

Please sign in to comment.