Add _.pullAt tests.

This commit is contained in:
John-David Dalton
2014-11-06 20:46:03 -08:00
parent 3ffa6cd1ac
commit 9bd77d36f1

View File

@@ -9267,7 +9267,7 @@
deepEqual(actual, [1, 3, 1, 2, 1, 3]);
});
test('should return `undefined` for nonexistent keys', 2, function() {
test('should use `undefined` for nonexistent indexes', 2, function() {
var array = ['a', 'b', 'c'],
actual = _.pullAt(array, [2, 4, 0]);
@@ -9275,12 +9275,34 @@
deepEqual(actual, ['c', undefined, 'a']);
});
test('should return an empty array when no keys are provided', 2, function() {
test('should ignore non-index keys', 2, function() {
var array = ['a', 'b', 'c'],
clone = array.slice();
array['1.1'] = array['-1'] = 1;
var values = _.reject(empties, function(value) {
return value === 0 || _.isArray(value);
}).concat(-1, 1.1);
var expected = _.map(values, _.constant(undefined)),
actual = _.pullAt(array, values);
deepEqual(actual, expected);
deepEqual(array, clone);
});
test('should return an empty array when no indexes are provided', 4, function() {
var array = ['a', 'b', 'c'],
actual = _.pullAt(array);
deepEqual(array, ['a', 'b', 'c']);
deepEqual(actual, []);
actual = _.pullAt(array, [], []);
deepEqual(array, ['a', 'b', 'c']);
deepEqual(actual, []);
});
test('should accept multiple index arguments', 2, function() {
@@ -9291,6 +9313,14 @@
deepEqual(actual, ['d', 'a', 'c']);
});
test('should accept multiple arrays of indexes', 2, function() {
var array = ['a', 'b', 'c', 'd'],
actual = _.pullAt(array, [3], [0, 2]);
deepEqual(array, ['b']);
deepEqual(actual, ['d', 'a', 'c']);
});
test('should work with a falsey `array` argument when keys are provided', 1, function() {
var expected = _.map(falsey, _.constant([undefined, undefined]));
@@ -9302,21 +9332,6 @@
deepEqual(actual, expected);
});
test('should ignore non-index values', 2, function() {
var array = ['a', 'b', 'c'],
clone = array.slice();
var values = _.reject(empties, function(value) {
return value === 0 || _.isArray(value);
}).concat(-1, 1.1);
var expected = _.map(values, _.constant(undefined)),
actual = _.pullAt.apply(_, [array].concat(values));
deepEqual(actual, expected);
deepEqual(array, clone);
});
}());
/*--------------------------------------------------------------------------*/