Remove Rhino guards from curry tests and add a partial test.

This commit is contained in:
John-David Dalton
2014-11-07 22:57:16 -08:00
parent 4896810258
commit f5682397c2

View File

@@ -2464,152 +2464,107 @@
} }
test('should curry based on the number of arguments provided', 3, function() { test('should curry based on the number of arguments provided', 3, function() {
if (!(isRhino && isModularize)) { var curried = _.curry(fn),
var curried = _.curry(fn), expected = [1, 2, 3, 4];
expected = [1, 2, 3, 4];
deepEqual(curried(1)(2)(3)(4), expected); deepEqual(curried(1)(2)(3)(4), expected);
deepEqual(curried(1, 2)(3, 4), expected); deepEqual(curried(1, 2)(3, 4), expected);
deepEqual(curried(1, 2, 3, 4), expected); deepEqual(curried(1, 2, 3, 4), expected);
}
else {
skipTest(3);
}
}); });
test('should allow specifying `arity`', 3, function() { test('should allow specifying `arity`', 3, function() {
if (!(isRhino && isModularize)) { var curried = _.curry(fn, 3),
var curried = _.curry(fn, 3), expected = [1, 2, 3];
expected = [1, 2, 3];
deepEqual(curried(1)(2, 3), expected); deepEqual(curried(1)(2, 3), expected);
deepEqual(curried(1, 2)(3), expected); deepEqual(curried(1, 2)(3), expected);
deepEqual(curried(1, 2, 3), expected); deepEqual(curried(1, 2, 3), expected);
}
else {
skipTest(3);
}
}); });
test('should coerce `arity` to a number', 2, function() { test('should coerce `arity` to a number', 2, function() {
if (!(isRhino && isModularize)) { var values = ['0', 'xyz'],
var values = ['0', 'xyz'], expected = _.map(values, _.constant([]));
expected = _.map(values, _.constant([]));
var actual = _.map(values, function(arity) { var actual = _.map(values, function(arity) {
return _.curry(fn, arity)(); return _.curry(fn, arity)();
}); });
deepEqual(actual, expected); deepEqual(actual, expected);
deepEqual(_.curry(fn, '2')(1)(2), [1, 2]); deepEqual(_.curry(fn, '2')(1)(2), [1, 2]);
}
else {
skipTest(2);
}
});
test('should work with partialed methods', 2, function() {
if (!(isRhino && isModularize)) {
var curried = _.curry(fn),
expected = [1, 2, 3, 4];
var a = _.partial(curried, 1),
b = _.bind(a, null, 2),
c = _.partialRight(b, 4),
d = _.partialRight(b(3), 4);
deepEqual(c(3), expected);
deepEqual(d(), expected);
}
else {
skipTest(2);
}
}); });
test('should support placeholders', 4, function() { test('should support placeholders', 4, function() {
if (!(isRhino && isModularize)) { var curried = _.curry(fn),
var curried = _.curry(fn), ph = curried.placeholder;
ph = curried.placeholder;
deepEqual(curried(1)(ph, 3)(ph, 4)(2), [1, 2, 3, 4]); deepEqual(curried(1)(ph, 3)(ph, 4)(2), [1, 2, 3, 4]);
deepEqual(curried(ph, 2)(1)(ph, 4)(3), [1, 2, 3, 4]); deepEqual(curried(ph, 2)(1)(ph, 4)(3), [1, 2, 3, 4]);
deepEqual(curried(ph, ph, 3)(ph, 2)(ph, 4)(1), [1, 2, 3, 4]); deepEqual(curried(ph, ph, 3)(ph, 2)(ph, 4)(1), [1, 2, 3, 4]);
deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), [1, 2, 3, 4]); deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), [1, 2, 3, 4]);
} });
else {
skipTest(4); test('should work with partialed methods', 2, function() {
} var curried = _.curry(fn),
expected = [1, 2, 3, 4];
var a = _.partial(curried, 1),
b = _.bind(a, null, 2),
c = _.partialRight(b, 4),
d = _.partialRight(b(3), 4);
deepEqual(c(3), expected);
deepEqual(d(), expected);
}); });
test('should provide additional arguments after reaching the target arity', 3, function() { test('should provide additional arguments after reaching the target arity', 3, function() {
if (!(isRhino && isModularize)) { var curried = _.curry(fn, 3);
var curried = _.curry(fn, 3); deepEqual(curried(1)(2, 3, 4), [1, 2, 3, 4]);
deepEqual(curried(1)(2, 3, 4), [1, 2, 3, 4]); deepEqual(curried(1, 2)(3, 4, 5), [1, 2, 3, 4, 5]);
deepEqual(curried(1, 2)(3, 4, 5), [1, 2, 3, 4, 5]); deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
}
else {
skipTest(3);
}
}); });
test('should return a function with a `length` of `0`', 6, function() { test('should return a function with a `length` of `0`', 6, function() {
if (!(isRhino && isModularize)) { _.times(2, function(index) {
_.times(2, function(index) { var curried = index ? _.curry(fn, 4) : _.curry(fn);
var curried = index ? _.curry(fn, 4) : _.curry(fn); strictEqual(curried.length, 0);
strictEqual(curried.length, 0); strictEqual(curried(1).length, 0);
strictEqual(curried(1).length, 0); strictEqual(curried(1, 2).length, 0);
strictEqual(curried(1, 2).length, 0); });
});
}
else {
skipTest(6);
}
}); });
test('ensure `new curried` is an instance of `func`', 2, function() { test('ensure `new curried` is an instance of `func`', 2, function() {
if (!(isRhino && isModularize)) { var Foo = function(value) {
var Foo = function(value) { return value && object;
return value && object; };
};
var curried = _.curry(Foo), var curried = _.curry(Foo),
object = {}; object = {};
ok(new curried(false) instanceof Foo); ok(new curried(false) instanceof Foo);
strictEqual(new curried(true), object); strictEqual(new curried(true), object);
}
else {
skipTest(2);
}
}); });
test('should not set a `this` binding', 9, function() { test('should not set a `this` binding', 9, function() {
if (!(isRhino && isModularize)) { var fn = function(a, b, c) {
var fn = function(a, b, c) { var value = this || {};
var value = this || {}; return [value[a], value[b], value[c]];
return [value[a], value[b], value[c]]; };
};
var object = { 'a': 1, 'b': 2, 'c': 3 }, var object = { 'a': 1, 'b': 2, 'c': 3 },
expected = [1, 2, 3]; expected = [1, 2, 3];
deepEqual(_.curry(_.bind(fn, object), 3)('a')('b')('c'), expected); deepEqual(_.curry(_.bind(fn, object), 3)('a')('b')('c'), expected);
deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b')('c'), expected); deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b')('c'), expected);
deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b', 'c'), expected); deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
deepEqual(_.bind(_.curry(fn), object)('a')('b')('c'), Array(3)); deepEqual(_.bind(_.curry(fn), object)('a')('b')('c'), Array(3));
deepEqual(_.bind(_.curry(fn), object)('a', 'b')('c'), Array(3)); deepEqual(_.bind(_.curry(fn), object)('a', 'b')('c'), Array(3));
deepEqual(_.bind(_.curry(fn), object)('a', 'b', 'c'), expected); deepEqual(_.bind(_.curry(fn), object)('a', 'b', 'c'), expected);
object.curried = _.curry(fn); object.curried = _.curry(fn);
deepEqual(object.curried('a')('b')('c'), Array(3)); deepEqual(object.curried('a')('b')('c'), Array(3));
deepEqual(object.curried('a', 'b')('c'), Array(3)); deepEqual(object.curried('a', 'b')('c'), Array(3));
deepEqual(object.curried('a', 'b', 'c'), expected); deepEqual(object.curried('a', 'b', 'c'), expected);
}
else {
skipTest(9);
}
}); });
}()); }());
@@ -2623,136 +2578,96 @@
} }
test('should curry based on the number of arguments provided', 3, function() { test('should curry based on the number of arguments provided', 3, function() {
if (!(isRhino && isModularize)) { var curried = _.curryRight(fn),
var curried = _.curryRight(fn), expected = [1, 2, 3, 4];
expected = [1, 2, 3, 4];
deepEqual(curried(4)(3)(2)(1), expected); deepEqual(curried(4)(3)(2)(1), expected);
deepEqual(curried(3, 4)(1, 2), expected); deepEqual(curried(3, 4)(1, 2), expected);
deepEqual(curried(1, 2, 3, 4), expected); deepEqual(curried(1, 2, 3, 4), expected);
}
else {
skipTest(3);
}
}); });
test('should allow specifying `arity`', 3, function() { test('should allow specifying `arity`', 3, function() {
if (!(isRhino && isModularize)) { var curried = _.curryRight(fn, 3),
var curried = _.curryRight(fn, 3), expected = [1, 2, 3];
expected = [1, 2, 3];
deepEqual(curried(3)(1, 2), expected); deepEqual(curried(3)(1, 2), expected);
deepEqual(curried(2, 3)(1), expected); deepEqual(curried(2, 3)(1), expected);
deepEqual(curried(1, 2, 3), expected); deepEqual(curried(1, 2, 3), expected);
}
else {
skipTest(3);
}
}); });
test('should work with partialed methods', 2, function() { test('should work with partialed methods', 2, function() {
if (!(isRhino && isModularize)) { var curried = _.curryRight(fn),
var curried = _.curryRight(fn), expected = [1, 2, 3, 4];
expected = [1, 2, 3, 4];
var a = _.partialRight(curried, 4), var a = _.partialRight(curried, 4),
b = _.partialRight(a, 3), b = _.partialRight(a, 3),
c = _.bind(b, null, 1), c = _.bind(b, null, 1),
d = _.partial(b(2), 1); d = _.partial(b(2), 1);
deepEqual(c(2), expected); deepEqual(c(2), expected);
deepEqual(d(), expected); deepEqual(d(), expected);
}
else {
skipTest(2);
}
}); });
test('should support placeholders', 4, function() { test('should support placeholders', 4, function() {
if (!(isRhino && isModularize)) { var curried = _.curryRight(fn),
var curried = _.curryRight(fn), expected = [1, 2, 3, 4],
expected = [1, 2, 3, 4], ph = curried.placeholder;
ph = curried.placeholder;
deepEqual(curried(4)(2, ph)(1, ph)(3), expected); deepEqual(curried(4)(2, ph)(1, ph)(3), expected);
deepEqual(curried(3, ph)(4)(1, ph)(2), expected); deepEqual(curried(3, ph)(4)(1, ph)(2), expected);
deepEqual(curried(ph, ph, 4)(ph, 3)(ph, 2)(1), expected); deepEqual(curried(ph, ph, 4)(ph, 3)(ph, 2)(1), expected);
deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), expected); deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), expected);
}
else {
skipTest(4);
}
}); });
test('should provide additional arguments after reaching the target arity', 3, function() { test('should provide additional arguments after reaching the target arity', 3, function() {
if (!(isRhino && isModularize)) { var curried = _.curryRight(fn, 3);
var curried = _.curryRight(fn, 3); deepEqual(curried(4)(1, 2, 3), [1, 2, 3, 4]);
deepEqual(curried(4)(1, 2, 3), [1, 2, 3, 4]); deepEqual(curried(4, 5)(1, 2, 3), [1, 2, 3, 4, 5]);
deepEqual(curried(4, 5)(1, 2, 3), [1, 2, 3, 4, 5]); deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
}
else {
skipTest(3);
}
}); });
test('should return a function with a `length` of `0`', 6, function() { test('should return a function with a `length` of `0`', 6, function() {
if (!(isRhino && isModularize)) { _.times(2, function(index) {
_.times(2, function(index) { var curried = index ? _.curryRight(fn, 4) : _.curryRight(fn);
var curried = index ? _.curryRight(fn, 4) : _.curryRight(fn); strictEqual(curried.length, 0);
strictEqual(curried.length, 0); strictEqual(curried(4).length, 0);
strictEqual(curried(4).length, 0); strictEqual(curried(3, 4).length, 0);
strictEqual(curried(3, 4).length, 0); });
});
}
else {
skipTest(6);
}
}); });
test('ensure `new curried` is an instance of `func`', 2, function() { test('ensure `new curried` is an instance of `func`', 2, function() {
if (!(isRhino && isModularize)) { var Foo = function(value) {
var Foo = function(value) { return value && object;
return value && object; };
};
var curried = _.curryRight(Foo), var curried = _.curryRight(Foo),
object = {}; object = {};
ok(new curried(false) instanceof Foo); ok(new curried(false) instanceof Foo);
strictEqual(new curried(true), object); strictEqual(new curried(true), object);
}
else {
skipTest(2);
}
}); });
test('should not set a `this` binding', 9, function() { test('should not set a `this` binding', 9, function() {
if (!(isRhino && isModularize)) { var fn = function(a, b, c) {
var fn = function(a, b, c) { var value = this || {};
var value = this || {}; return [value[a], value[b], value[c]];
return [value[a], value[b], value[c]]; };
};
var object = { 'a': 1, 'b': 2, 'c': 3 }, var object = { 'a': 1, 'b': 2, 'c': 3 },
expected = [1, 2, 3]; expected = [1, 2, 3];
deepEqual(_.curryRight(_.bind(fn, object), 3)('c')('b')('a'), expected); deepEqual(_.curryRight(_.bind(fn, object), 3)('c')('b')('a'), expected);
deepEqual(_.curryRight(_.bind(fn, object), 3)('b', 'c')('a'), expected); deepEqual(_.curryRight(_.bind(fn, object), 3)('b', 'c')('a'), expected);
deepEqual(_.curryRight(_.bind(fn, object), 3)('a', 'b', 'c'), expected); deepEqual(_.curryRight(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
deepEqual(_.bind(_.curryRight(fn), object)('c')('b')('a'), Array(3)); deepEqual(_.bind(_.curryRight(fn), object)('c')('b')('a'), Array(3));
deepEqual(_.bind(_.curryRight(fn), object)('b', 'c')('a'), Array(3)); deepEqual(_.bind(_.curryRight(fn), object)('b', 'c')('a'), Array(3));
deepEqual(_.bind(_.curryRight(fn), object)('a', 'b', 'c'), expected); deepEqual(_.bind(_.curryRight(fn), object)('a', 'b', 'c'), expected);
object.curried = _.curryRight(fn); object.curried = _.curryRight(fn);
deepEqual(object.curried('c')('b')('a'), Array(3)); deepEqual(object.curried('c')('b')('a'), Array(3));
deepEqual(object.curried('b', 'c')('a'), Array(3)); deepEqual(object.curried('b', 'c')('a'), Array(3));
deepEqual(object.curried('a', 'b', 'c'), expected); deepEqual(object.curried('a', 'b', 'c'), expected);
}
else {
skipTest(9);
}
}); });
}()); }());
@@ -8846,7 +8761,8 @@
_.each(['partial', 'partialRight'], function(methodName) { _.each(['partial', 'partialRight'], function(methodName) {
var func = _[methodName], var func = _[methodName],
isPartial = methodName == 'partial'; isPartial = methodName == 'partial',
ph = func.placeholder;
test('`_.' + methodName + '` partially applies arguments', 1, function() { test('`_.' + methodName + '` partially applies arguments', 1, function() {
var par = func(_.identity, 'a'); var par = func(_.identity, 'a');
@@ -8875,7 +8791,6 @@
test('`_.' + methodName + '` should support placeholders', 4, function() { test('`_.' + methodName + '` should support placeholders', 4, function() {
var fn = function() { return slice.call(arguments); }, var fn = function() { return slice.call(arguments); },
ph = func.placeholder,
par = func(fn, ph, 'b', ph); par = func(fn, ph, 'b', ph);
deepEqual(par('a', 'c'), ['a', 'b', 'c']); deepEqual(par('a', 'c'), ['a', 'b', 'c']);
@@ -8938,16 +8853,19 @@
}); });
test('`_.' + methodName + '` should work with curried methods', 2, function() { test('`_.' + methodName + '` should work with curried methods', 2, function() {
if (!(isRhino && isModularize)) { var fn = function(a, b, c) { return a + b + c; },
var fn = function(a, b, c) { return a + b + c; }, curried = _.curry(func(fn, 1), 2);
curried = _.curry(func(fn, 1), 2);
strictEqual(curried(2, 3), 6); strictEqual(curried(2, 3), 6);
strictEqual(curried(2)(3), 6); strictEqual(curried(2)(3), 6);
} });
else {
skipTest(2); test('should work with placeholders and curried methods', 1, function() {
} var fn = function() { return slice.call(arguments); },
curried = _.curry(fn),
par = func(curried, ph, 'b', ph, 'd');
deepEqual(par('a', 'c'), ['a', 'b', 'c', 'd']);
}); });
}); });
@@ -9105,6 +9023,20 @@
deepEqual(actual, [object, 1, 2, 3]); deepEqual(actual, [object, 1, 2, 3]);
}); });
_.each(['curry', 'curryRight'], function(methodName) {
function fn(a, b, c) {
return [a, b, c];
}
var curried = _[methodName](fn);
var actual = _.last(_.times(HOT_COUNT, function() {
return curried(1)(2)(3);
}));
deepEqual(actual, methodName == 'curry' ? [1, 2, 3] : [3, 2, 1]);
});
_.each(['partial', 'partialRight'], function(methodName) { _.each(['partial', 'partialRight'], function(methodName) {
function fn() { function fn() {
return slice.call(arguments); return slice.call(arguments);
@@ -9120,25 +9052,6 @@
deepEqual(actual, methodName == 'partial' ? [1, 2, 3] : [3, 2, 1]); deepEqual(actual, methodName == 'partial' ? [1, 2, 3] : [3, 2, 1]);
}); });
if (!(isRhino && isModularize)) {
_.each(['curry', 'curryRight'], function(methodName) {
function fn(a, b, c) {
return [a, b, c];
}
var curried = _[methodName](fn);
var actual = _.last(_.times(HOT_COUNT, function() {
return curried(1)(2)(3);
}));
deepEqual(actual, methodName == 'curry' ? [1, 2, 3] : [3, 2, 1]);
});
}
else {
skipTest(2);
}
}); });
}()); }());