Avoid modularized test fails for Rhino.

This commit is contained in:
John-David Dalton
2014-11-06 22:23:54 -08:00
parent 5ea6948127
commit 1871ed5441

View File

@@ -2433,24 +2433,35 @@
} }
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([]));
@@ -2460,9 +2471,14 @@
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() { 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];
@@ -2473,9 +2489,14 @@
deepEqual(c(3), expected); deepEqual(c(3), 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 = _.curry(fn), var curried = _.curry(fn),
ph = curried.placeholder; ph = curried.placeholder;
@@ -2483,41 +2504,61 @@
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 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() {
function Foo(value) { if (!(isRhino && isModularize)) {
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() {
function fn(a, b, c) { if (!(isRhino && isModularize)) {
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];
@@ -2534,6 +2575,10 @@
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);
}
}); });
}()); }());
@@ -2547,24 +2592,35 @@
} }
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];
@@ -2575,9 +2631,14 @@
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;
@@ -2586,41 +2647,61 @@
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() {
function Foo(value) { if (!(isRhino && isModularize)) {
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() {
function fn(a, b, c) { if (!(isRhino && isModularize)) {
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];
@@ -2637,6 +2718,10 @@
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);
}
}); });
}()); }());
@@ -8797,11 +8882,16 @@
}); });
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);
}
}); });
}); });
@@ -8959,20 +9049,6 @@
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);
@@ -8988,6 +9064,25 @@
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);
}
}); });
}()); }());