Cleanup fp mapping and tests.

This commit is contained in:
John-David Dalton
2015-12-15 22:23:38 -08:00
parent a4b86f8368
commit db731e0c91
2 changed files with 30 additions and 65 deletions

View File

@@ -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. */

View File

@@ -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]);
});
}());
});
/*--------------------------------------------------------------------------*/