Skip to content

Commit

Permalink
fix missing path argument in FuncType
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jun 6, 2016
1 parent e0d94d1 commit 893fca7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ function func(domain, codomain, name) {
var domainLength = domain.length;
var optionalArgumentsIndex = getOptionalArgumentsIndex(domain);

function FuncType(value, curried) {
function FuncType(value, path) {

if (!isInstrumented(value)) { // automatically instrument the function
return FuncType.of(value, curried);
return FuncType.of(value);
}

if (process.env.NODE_ENV !== 'production') {
assert(FuncType.is(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + displayName; });
path = path || [displayName];
assert(FuncType.is(value), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/'); });
}

return value;
Expand Down
13 changes: 11 additions & 2 deletions test/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ describe('t.func(domain, codomain, [name])', function () {
assert.ok(T.is(T(f)));
});

it('should throw if arguments are wrong', function () {
var T1 = t.func(t.Number, t.Number);
var T2 = t.func(t.Number, t.String);
var f = T2.of(function () { return 'hi'; });
util.throwsWithMessage(function () {
T1(f);
}, '[tcomb] Invalid value "<function0>" supplied to (Number) => Number');
});

describe('of', function () {

it('should check the arguments', function () {
Expand Down Expand Up @@ -118,7 +127,7 @@ describe('t.func(domain, codomain, [name])', function () {

it('should throw if no arguments are passed in', function () {
var Type = t.func([t.Number, t.Number, t.Number], t.Number);
var sum = Type(function (a, b, c) {
var sum = Type.of(function (a, b, c) {
return a + b + c;
}, true);
util.throwsWithMessage(function () {
Expand All @@ -128,7 +137,7 @@ describe('t.func(domain, codomain, [name])', function () {

it('should curry functions', function () {
var Type = t.func([t.Number, t.Number, t.Number], t.Number);
var sum = Type(function (a, b, c) {
var sum = Type.of(function (a, b, c) {
return a + b + c;
}, true);
assert.deepEqual(sum(1, 2, 3), 6);
Expand Down

0 comments on commit 893fca7

Please sign in to comment.