From 44c697908b40bb03ad6e2279c3da3ed15eddb1e4 Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Wed, 16 Dec 2015 13:19:38 +0800 Subject: [PATCH] Ensure `curryN`, `curryRightN`, `curryRight`, and `sampleSize` are defined. --- lib/fp/mapping.js | 7 ++++--- test/test-fp.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/fp/mapping.js b/lib/fp/mapping.js index 15b0f2069..267c0ccca 100644 --- a/lib/fp/mapping.js +++ b/lib/fp/mapping.js @@ -73,11 +73,11 @@ module.exports = { /** Used to map ary to method names. */ 'aryMethodMap': { 1: ( - 'attempt,ceil,create,curry,floor,fromPairs,iteratee,invert,over,overEvery,' + + 'attempt,ceil,create,curry,curryRight,floor,fromPairs,iteratee,invert,over,overEvery,' + 'overSome,memoize,method,methodOf,mixin,rest,reverse,round,runInContext,template,' + 'trim,trimLeft,trimRight,uniqueId,words').split(','), 2: ( - 'add,ary,assign,at,bind,bindKey,cloneDeepWith,cloneWith,concat,countBy,curryN,' + + 'add,ary,assign,at,bind,bindKey,cloneDeepWith,cloneWith,concat,countBy,curryN,curryRightN,' + 'debounce,defaults,defaultsDeep,delay,difference,drop,dropRight,dropRightWhile,' + 'dropWhile,endsWith,every,extend,filter,find,find,findIndex,findKey,findLast,' + 'findLastIndex,findLastKey,flatMap,forEach,forEachRight,forIn,forInRight,' + @@ -120,7 +120,8 @@ module.exports = { 'keyMap': { 'curryN': 'curry', 'curryRightN': 'curryRight', - 'getOr': 'get' + 'getOr': 'get', + 'sampleSize': 'sample' }, /** Used to identify methods which mutate arrays or objects. */ diff --git a/test/test-fp.js b/test/test-fp.js index 75717e7dc..63277f128 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -321,6 +321,45 @@ var actual = fp.curryN(1, function(a, b) { return [a, b]; })('a'); assert.deepEqual(actual, ['a', undefined]); }); + + QUnit.test('should only pass in `arity` number of arguments', function(assert) { + assert.expect(1); + + var actual = fp.curryN(1, function(a, b) { return [a, b]; })('a', 'b'); + assert.deepEqual(actual, ['a', undefined]); + }); + }()); + + /*--------------------------------------------------------------------------*/ + + QUnit.module('fp.curryRight'); + + (function() { + QUnit.test('should accept only a `func` param', function(assert) { + assert.expect(1); + + assert.raises(function() { fp.curryRight(1, _.noop); }, TypeError); + }); + }()); + + /*--------------------------------------------------------------------------*/ + + QUnit.module('fp.curryRightN'); + + (function() { + QUnit.test('should accept an `arity` param', function(assert) { + assert.expect(1); + + var actual = fp.curryRightN(1, function(a, b) { return [a, b]; })('a'); + assert.deepEqual(actual, ['a', undefined]); + }); + + QUnit.test('should only pass in `arity` number of arguments', function(assert) { + assert.expect(1); + + var actual = fp.curryRightN(1, function(a, b) { return [a, b]; })('a', 'b'); + assert.deepEqual(actual, ['a', undefined]); + }); }()); /*--------------------------------------------------------------------------*/