Add placeholder support tests for _.bind.

This commit is contained in:
John-David Dalton
2014-02-22 20:59:02 -08:00
parent 80289bd452
commit 28b83a486e

View File

@@ -799,11 +799,29 @@
deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']); deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']);
}); });
test('should create a function with a `length` of `0`', 1, function() { test('should support placeholders', 4, function() {
if (_._iteratorTemplate) {
var object = {},
bound = _.bind(fn, object, _, 'b', _);
deepEqual(bound('a', 'c'), [object, 'a', 'b', 'c']);
deepEqual(bound('a'), [object, 'a', 'b', undefined]);
deepEqual(bound('a', 'c', 'd'), [object, 'a', 'b', 'c', 'd']);
deepEqual(bound(), [object, undefined, 'b', undefined]);
}
else {
skipTest(4);
}
});
test('should create a function with a `length` of `0`', 2, function() {
var func = function(a, b, c) {}, var func = function(a, b, c) {},
bound = _.bind(fn, {}); bound = _.bind(fn, {});
strictEqual(bound.length, 0); strictEqual(bound.length, 0);
bound = _.bind(fn, {}, 1);
strictEqual(bound.length, 0);
}); });
test('should ignore binding when called with the `new` operator', 3, function() { test('should ignore binding when called with the `new` operator', 3, function() {
@@ -6018,24 +6036,20 @@
test('`_.' + methodName + '` should support placeholders', 4, function() { test('`_.' + methodName + '` should support placeholders', 4, function() {
if (_._iteratorTemplate) { if (_._iteratorTemplate) {
var fn = function() { var fn = function() {
return _.reduce(arguments, function(string, chr) { return slice.call(arguments);
return string + (chr || '');
}, '');
}; };
var par = func(fn, _, 'b', _); var par = func(fn, _, 'b', _);
equal(par('a', 'c'), 'abc'); deepEqual(par('a', 'c'), ['a', 'b', 'c']);
equal(par('a'), 'ab'); deepEqual(par('a'), ['a', 'b', undefined]);
deepEqual(par(), [undefined, 'b', undefined]);
if (isPartial) { if (isPartial) {
equal(par('a', 'c', 'd'), 'abcd'); deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
} else { } else {
par = func(fn, _, 'c', _); par = func(fn, _, 'c', _);
equal(par('a', 'b', 'd'), 'abcd'); deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
} }
fn = function() { return slice.call(arguments); };
par = func(fn, _, 'b', _);
deepEqual(par(), [undefined, 'b', undefined]);
} }
else { else {
skipTest(4); skipTest(4);