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,35 +2464,24 @@
} }
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([]));
@@ -2502,14 +2491,19 @@
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 support placeholders', 4, function() {
} var curried = _.curry(fn),
ph = curried.placeholder;
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, 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]);
}); });
test('should work with partialed methods', 2, function() { test('should work with partialed methods', 2, function() {
if (!(isRhino && isModularize)) {
var curried = _.curry(fn), var curried = _.curry(fn),
expected = [1, 2, 3, 4]; expected = [1, 2, 3, 4];
@@ -2520,55 +2514,25 @@
deepEqual(c(3), expected); deepEqual(c(3), expected);
deepEqual(d(), expected); deepEqual(d(), expected);
}
else {
skipTest(2);
}
});
test('should support placeholders', 4, function() {
if (!(isRhino && isModularize)) {
var curried = _.curry(fn),
ph = curried.placeholder;
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, 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]);
}
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 = _.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;
}; };
@@ -2578,14 +2542,9 @@
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]];
@@ -2606,10 +2565,6 @@
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,35 +2578,24 @@
} }
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];
@@ -2662,14 +2606,9 @@
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;
@@ -2678,40 +2617,25 @@
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;
}; };
@@ -2721,14 +2645,9 @@
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]];
@@ -2749,10 +2668,6 @@
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);
}
}); });
}()); }());