Add fromIndex to _.contains.

Former-commit-id: 9f61db3ceda2d87ddfbfd4cffb2bd1f9732cc79a
This commit is contained in:
John-David Dalton
2012-11-04 11:24:29 -08:00
parent 1d3488fa8e
commit 218e3b66f2
5 changed files with 67 additions and 23 deletions

View File

@@ -636,6 +636,7 @@
equal(object.fn(), 2, '_.bind: ' + basename);
ok(lodash.clone(array, true)[0] === array[0], '_.clone should be shallow: ' + basename);
equal(lodash.contains([1, 2, 3], 1, 2), true, '_.contains should ignore `fromIndex`: ' + basename);
equal(lodash.every([true, false, true]), false, '_.every: ' + basename);
object = { 'length': 0, 'splice': Array.prototype.splice };

View File

@@ -262,6 +262,33 @@
QUnit.module('lodash.contains');
(function() {
_.each({
'an array': [1, 2, 3, 1, 2, 3],
'an object': { 'a': 1, 'b': 2, 'c': 3, 'd': 1, 'e': 2, 'f': 3 },
'a string': '123123'
},
function(collection, key) {
test('should work with ' + key + ' and a positive `fromIndex`', function() {
equal(_.contains(collection, 1, 2), true);
});
test('should work with ' + key + ' and a `fromIndex` >= collection\'s length', function() {
equal(_.contains(collection, 1, 6), false);
equal(_.contains(collection, undefined, 6), false);
equal(_.contains(collection, 1, 8), false);
equal(_.contains(collection, undefined, 8), false);
});
test('should work with ' + key + ' and a negative `fromIndex`', function() {
equal(_.contains(collection, 2, -3), true);
});
test('should work with ' + key + ' and a negative `fromIndex` <= negative collection\'s length', function() {
equal(_.contains(collection, 1, -6), true);
equal(_.contains(collection, 2, -8), true);
});
});
_.each({
'literal': 'abc',
'object': Object('abc')