From db731e0c91a833d6c15cb7b8249186327b20b689 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 15 Dec 2015 22:23:38 -0800 Subject: [PATCH] Cleanup fp mapping and tests. --- lib/fp/mapping.js | 32 ++++++++++++------------ test/test-fp.js | 63 +++++++++++------------------------------------ 2 files changed, 30 insertions(+), 65 deletions(-) diff --git a/lib/fp/mapping.js b/lib/fp/mapping.js index 2d79ec4a2..bedc9315e 100644 --- a/lib/fp/mapping.js +++ b/lib/fp/mapping.js @@ -73,21 +73,22 @@ module.exports = { /** Used to map ary to method names. */ 'aryMethodMap': { 1: ( - 'attempt,ceil,create,curry,curryRight,floor,fromPairs,iteratee,invert,over,overEvery,' + - 'overSome,memoize,method,methodOf,mixin,rest,reverse,round,runInContext,sample,template,' + - 'trim,trimLeft,trimRight,uniqueId,words').split(','), + '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,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,' + - 'forOwn,forOwnRight,get,groupBy,includes,indexBy,indexOf,intersection,invoke,' + - 'invokeMap,isMatch,lastIndexOf,map,mapKeys,mapValues,matchesProperty,maxBy,' + - 'mean,minBy,merge,omit,overArgs,pad,padLeft,padRight,parseInt,partition,' + - 'pick,pull,pullAll,pullAt,random,range,rangeRight,rearg,reject,remove,repeat,' + - 'result,sampleSize,some,sortBy,sortByOrder,sortedIndexBy,sortedLastIndexBy,' + - 'sortedUniqBy,startsWith,subtract,sumBy,take,takeRight,takeRightWhile,takeWhile,' + - 'throttle,times,truncate,union,uniqBy,without,wrap,xor,zip,zipObject').split(','), + '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,forOwn,forOwnRight,get,groupBy,includes,indexBy,indexOf,' + + 'intersection,invoke,invokeMap,isMatch,lastIndexOf,map,mapKeys,mapValues,' + + 'matchesProperty,maxBy,mean,minBy,merge,omit,overArgs,pad,padLeft,padRight,' + + 'parseInt,partition,pick,pull,pullAll,pullAt,random,range,rangeRight,rearg,' + + 'reject,remove,repeat,result,sampleSize,some,sortBy,sortByOrder,sortedIndexBy,' + + 'sortedLastIndexBy,sortedUniqBy,startsWith,subtract,sumBy,take,takeRight,' + + 'takeRightWhile,takeWhile,throttle,times,truncate,union,uniqBy,without,wrap,' + + 'xor,zip,zipObject').split(','), 3: ( 'assignWith,clamp,differenceBy,extendWith,getOr,inRange,intersectionBy,' + 'isEqualWith,isMatchWith,mergeWith,omitBy,pickBy,pullAllBy,reduce,' + @@ -120,8 +121,7 @@ module.exports = { 'keyMap': { 'curryN': 'curry', 'curryRightN': 'curryRight', - 'getOr': 'get', - 'sampleSize': 'sample' + 'getOr': 'get' }, /** Used to identify methods which mutate arrays or objects. */ diff --git a/test/test-fp.js b/test/test-fp.js index 63277f128..065713916 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -300,67 +300,32 @@ /*--------------------------------------------------------------------------*/ - QUnit.module('fp.curry'); + QUnit.module('curry methods'); - (function() { - QUnit.test('should accept only a `func` param', function(assert) { + _.each(['curry', 'curryRight'], function(methodName) { + var func = fp[methodName]; + + QUnit.test('`_.' + methodName + '` should only accept a `func` param', function(assert) { assert.expect(1); - assert.raises(function() { fp.curry(1, _.noop); }, TypeError); + assert.raises(function() { func(1, _.noop); }, TypeError); }); - }()); + }); /*--------------------------------------------------------------------------*/ - QUnit.module('fp.curryN'); + QUnit.module('curryN methods'); - (function() { - QUnit.test('should accept an `arity` param', function(assert) { + _.each(['curryN', 'curryRightN'], function(methodName) { + var func = fp[methodName]; + + QUnit.test('`_.' + methodName + '` accept an `arity` param', function(assert) { assert.expect(1); - var actual = fp.curryN(1, function(a, b) { return [a, b]; })('a'); + var actual = func(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]); - }); - }()); + }); /*--------------------------------------------------------------------------*/