"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/underscore/test/arrays.js" between
lodash-4.0.0.tar.gz and lodash-4.17.21.tar.gz

About: lodash is a modern JavaScript utility library delivering modularity, performance, & extras. Tagged version.

arrays.js  (lodash-4.0.0):arrays.js  (lodash-4.17.21)
skipping to change at line 18 skipping to change at line 18
assert.equal(_([1, 2, 3]).first(), 1, 'can perform OO-style "first()"'); assert.equal(_([1, 2, 3]).first(), 1, 'can perform OO-style "first()"');
assert.deepEqual(_.first([1, 2, 3], 0), [], 'returns an empty array when n < = 0 (0 case)'); assert.deepEqual(_.first([1, 2, 3], 0), [], 'returns an empty array when n < = 0 (0 case)');
assert.deepEqual(_.first([1, 2, 3], -1), [], 'returns an empty array when n <= 0 (negative case)'); assert.deepEqual(_.first([1, 2, 3], -1), [], 'returns an empty array when n <= 0 (negative case)');
assert.deepEqual(_.first([1, 2, 3], 2), [1, 2], 'can fetch the first n eleme nts'); assert.deepEqual(_.first([1, 2, 3], 2), [1, 2], 'can fetch the first n eleme nts');
assert.deepEqual(_.first([1, 2, 3], 5), [1, 2, 3], 'returns the whole array if n > length'); assert.deepEqual(_.first([1, 2, 3], 5), [1, 2, 3], 'returns the whole array if n > length');
var result = (function(){ return _.first(arguments); }(4, 3, 2, 1)); var result = (function(){ return _.first(arguments); }(4, 3, 2, 1));
assert.equal(result, 4, 'works on an arguments object'); assert.equal(result, 4, 'works on an arguments object');
result = _.map([[1, 2, 3], [1, 2, 3]], _.first); result = _.map([[1, 2, 3], [1, 2, 3]], _.first);
assert.deepEqual(result, [1, 1], 'works well with _.map'); assert.deepEqual(result, [1, 1], 'works well with _.map');
assert.equal(_.first(null), void 0, 'returns undefined when called on null') ; assert.equal(_.first(null), void 0, 'returns undefined when called on null') ;
Array.prototype[0] = 'boo';
assert.equal(_.first([]), void 0, 'return undefined when called on a empty a
rray');
delete Array.prototype[0];
}); });
QUnit.test('head', function(assert) { QUnit.test('head', function(assert) {
assert.strictEqual(_.head, _.first, 'is an alias for first'); assert.strictEqual(_.head, _.first, 'is an alias for first');
}); });
QUnit.test('take', function(assert) { QUnit.test('take', function(assert) {
assert.strictEqual(_.take, _.first, 'is an alias for first'); assert.strictEqual(_.take, _.first, 'is an alias for first');
}); });
skipping to change at line 69 skipping to change at line 73
assert.equal(_([1, 2, 3]).last(), 3, 'can perform OO-style "last()"'); assert.equal(_([1, 2, 3]).last(), 3, 'can perform OO-style "last()"');
assert.deepEqual(_.last([1, 2, 3], 0), [], 'returns an empty array when n <= 0 (0 case)'); assert.deepEqual(_.last([1, 2, 3], 0), [], 'returns an empty array when n <= 0 (0 case)');
assert.deepEqual(_.last([1, 2, 3], -1), [], 'returns an empty array when n < = 0 (negative case)'); assert.deepEqual(_.last([1, 2, 3], -1), [], 'returns an empty array when n < = 0 (negative case)');
assert.deepEqual(_.last([1, 2, 3], 2), [2, 3], 'can fetch the last n element s'); assert.deepEqual(_.last([1, 2, 3], 2), [2, 3], 'can fetch the last n element s');
assert.deepEqual(_.last([1, 2, 3], 5), [1, 2, 3], 'returns the whole array i f n > length'); assert.deepEqual(_.last([1, 2, 3], 5), [1, 2, 3], 'returns the whole array i f n > length');
var result = (function(){ return _(arguments).last(); }(1, 2, 3, 4)); var result = (function(){ return _(arguments).last(); }(1, 2, 3, 4));
assert.equal(result, 4, 'works on an arguments object'); assert.equal(result, 4, 'works on an arguments object');
result = _.map([[1, 2, 3], [1, 2, 3]], _.last); result = _.map([[1, 2, 3], [1, 2, 3]], _.last);
assert.deepEqual(result, [3, 3], 'works well with _.map'); assert.deepEqual(result, [3, 3], 'works well with _.map');
assert.equal(_.last(null), void 0, 'returns undefined when called on null'); assert.equal(_.last(null), void 0, 'returns undefined when called on null');
var arr = [];
arr[-1] = 'boo';
assert.equal(_.last(arr), void 0, 'return undefined when called on a empty a
rray');
}); });
QUnit.test('compact', function(assert) { QUnit.test('compact', function(assert) {
assert.deepEqual(_.compact([1, false, null, 0, '', void 0, NaN, 2]), [1, 2], 'removes all falsy values'); assert.deepEqual(_.compact([1, false, null, 0, '', void 0, NaN, 2]), [1, 2], 'removes all falsy values');
var result = (function(){ return _.compact(arguments); }(0, 1, false, 2, fal se, 3)); var result = (function(){ return _.compact(arguments); }(0, 1, false, 2, fal se, 3));
assert.deepEqual(result, [1, 2, 3], 'works on an arguments object'); assert.deepEqual(result, [1, 2, 3], 'works on an arguments object');
result = _.map([[1, false, false], [false, false, 3]], _.compact); result = _.map([[1, false, false], [false, false, 3]], _.compact);
assert.deepEqual(result, [[1], [3]], 'works well with _.map'); assert.deepEqual(result, [[1], [3]], 'works well with _.map');
}); });
skipping to change at line 146 skipping to change at line 154
// Sparsely populate `array` // Sparsely populate `array`
while (length--) { while (length--) {
largeArray[values[length]] = values[length]; largeArray[values[length]] = values[length];
} }
assert.equal(_.sortedIndex(largeArray, 2147483648), 2147483648, 'works with large indexes'); assert.equal(_.sortedIndex(largeArray, 2147483648), 2147483648, 'works with large indexes');
}); });
QUnit.test('uniq', function(assert) { QUnit.test('uniq', function(assert) {
var list = [1, 2, 1, 3, 1, 4]; var list = [1, 2, 1, 3, 1, 4];
assert.deepEqual(_.uniq(list), [1, 2, 3, 4], 'can find the unique values of an unsorted array'); assert.deepEqual(_.uniq(list), [1, 2, 3, 4], 'can find the unique values of an unsorted array');
list = [1, 1, 1, 2, 2, 3]; list = [1, 1, 1, 2, 2, 3];
assert.deepEqual(_.uniq(list, true), [1, 2, 3], 'can find the unique values of a sorted array faster'); assert.deepEqual(_.uniq(list, true), [1, 2, 3], 'can find the unique values of a sorted array faster');
list = [{name: 'moe'}, {name: 'curly'}, {name: 'larry'}, {name: 'curly'}]; list = [{name: 'Moe'}, {name: 'Curly'}, {name: 'Larry'}, {name: 'Curly'}];
var iterator = function(value) { return value.name; }; var expected = [{name: 'Moe'}, {name: 'Curly'}, {name: 'Larry'}];
assert.deepEqual(_.map(_.uniq(list, false, iterator), iterator), ['moe', 'cu var iterator = function(stooge) { return stooge.name; };
rly', 'larry'], 'can find the unique values of an array using a custom iterator' assert.deepEqual(_.uniq(list, false, iterator), expected, 'uses the result o
); f `iterator` for uniqueness comparisons (unsorted case)');
assert.deepEqual(_.uniq(list, iterator), expected, '`sorted` argument defaul
assert.deepEqual(_.map(_.uniq(list, iterator), iterator), ['moe', 'curly', ' ts to false when omitted');
larry'], 'can find the unique values of an array using a custom iterator without assert.deepEqual(_.uniq(list, 'name'), expected, 'when `iterator` is a strin
specifying whether array is sorted'); g, uses that key for comparisons (unsorted case)');
iterator = function(value) { return value + 1; }; list = [{score: 8}, {score: 10}, {score: 10}];
list = [1, 2, 2, 3, 4, 4]; expected = [{score: 8}, {score: 10}];
assert.deepEqual(_.uniq(list, true, iterator), [1, 2, 3, 4], 'iterator works iterator = function(item) { return item.score; };
with sorted array'); assert.deepEqual(_.uniq(list, true, iterator), expected, 'uses the result of
`iterator` for uniqueness comparisons (sorted case)');
var kittens = [ assert.deepEqual(_.uniq(list, true, 'score'), expected, 'when `iterator` is
{kitten: 'Celery', cuteness: 8}, a string, uses that key for comparisons (sorted case)');
{kitten: 'Juniper', cuteness: 10},
{kitten: 'Spottis', cuteness: 10}
];
var expected = [
{kitten: 'Celery', cuteness: 8},
{kitten: 'Juniper', cuteness: 10}
];
assert.deepEqual(_.uniq(kittens, true, 'cuteness'), expected, 'string iterat or works with sorted array'); assert.deepEqual(_.uniq([{0: 1}, {0: 1}, {0: 1}, {0: 2}], 0), [{0: 1}, {0: 2 }], 'can use falsey pluck like iterator');
var result = (function(){ return _.uniq(arguments); }(1, 2, 1, 3, 1, 4)); var result = (function(){ return _.uniq(arguments); }(1, 2, 1, 3, 1, 4));
assert.deepEqual(result, [1, 2, 3, 4], 'works on an arguments object'); assert.deepEqual(result, [1, 2, 3, 4], 'works on an arguments object');
var a = {}, b = {}, c = {}; var a = {}, b = {}, c = {};
assert.deepEqual(_.uniq([a, b, a, b, c]), [a, b, c], 'works on values that c an be tested for equivalency but not ordered'); assert.deepEqual(_.uniq([a, b, a, b, c]), [a, b, c], 'works on values that c an be tested for equivalency but not ordered');
assert.deepEqual(_.uniq(null), []); assert.deepEqual(_.uniq(null), [], 'returns an empty array when `array` is n ot iterable');
var context = {}; var context = {};
list = [3]; list = [3];
_.uniq(list, function(value, index, array) { _.uniq(list, function(value, index, array) {
assert.strictEqual(this, context); assert.strictEqual(this, context, 'executes its iterator in the given cont
assert.strictEqual(value, 3); ext');
assert.strictEqual(index, 0); assert.strictEqual(value, 3, 'passes its iterator the value');
assert.strictEqual(array, list); assert.strictEqual(index, 0, 'passes its iterator the index');
assert.strictEqual(array, list, 'passes its iterator the entire array');
}, context); }, context);
assert.deepEqual(_.uniq([{a: 1, b: 1}, {a: 1, b: 2}, {a: 1, b: 3}, {a: 2, b:
1}], 'a'), [{a: 1, b: 1}, {a: 2, b: 1}], 'can use pluck like iterator');
assert.deepEqual(_.uniq([{0: 1, b: 1}, {0: 1, b: 2}, {0: 1, b: 3}, {0: 2, b:
1}], 0), [{0: 1, b: 1}, {0: 2, b: 1}], 'can use falsey pluck like iterator');
}); });
QUnit.test('unique', function(assert) { QUnit.test('unique', function(assert) {
assert.strictEqual(_.unique, _.uniq, 'is an alias for uniq'); assert.strictEqual(_.unique, _.uniq, 'is an alias for uniq');
}); });
QUnit.test('intersection', function(assert) { QUnit.test('intersection', function(assert) {
var stooges = ['moe', 'curly', 'larry'], leaders = ['moe', 'groucho']; var stooges = ['moe', 'curly', 'larry'], leaders = ['moe', 'groucho'];
assert.deepEqual(_.intersection(stooges, leaders), ['moe'], 'can take the se t intersection of two arrays'); assert.deepEqual(_.intersection(stooges, leaders), ['moe'], 'can find the se t intersection of two arrays');
assert.deepEqual(_(stooges).intersection(leaders), ['moe'], 'can perform an OO-style intersection'); assert.deepEqual(_(stooges).intersection(leaders), ['moe'], 'can perform an OO-style intersection');
var result = (function(){ return _.intersection(arguments, leaders); }('moe' , 'curly', 'larry')); var result = (function(){ return _.intersection(arguments, leaders); }('moe' , 'curly', 'larry'));
assert.deepEqual(result, ['moe'], 'works on an arguments object'); assert.deepEqual(result, ['moe'], 'works on an arguments object');
var theSixStooges = ['moe', 'moe', 'curly', 'curly', 'larry', 'larry']; var theSixStooges = ['moe', 'moe', 'curly', 'curly', 'larry', 'larry'];
assert.deepEqual(_.intersection(theSixStooges, leaders), ['moe'], 'returns a duplicate-free array'); assert.deepEqual(_.intersection(theSixStooges, leaders), ['moe'], 'returns a duplicate-free array');
result = _.intersection([2, 4, 3, 1], [1, 2, 3]); result = _.intersection([2, 4, 3, 1], [1, 2, 3]);
assert.deepEqual(result, [2, 3, 1], 'preserves order of first array'); assert.deepEqual(result, [2, 3, 1], 'preserves the order of the first array' );
result = _.intersection(null, [1, 2, 3]); result = _.intersection(null, [1, 2, 3]);
assert.equal(Object.prototype.toString.call(result), '[object Array]', 'retu assert.deepEqual(result, [], 'returns an empty array when passed null as the
rns an empty array when passed null as first argument'); first argument');
assert.equal(result.length, 0, 'returns an empty array when passed null as f
irst argument');
result = _.intersection([1, 2, 3], null); result = _.intersection([1, 2, 3], null);
assert.equal(Object.prototype.toString.call(result), '[object Array]', 'retu assert.deepEqual(result, [], 'returns an empty array when passed null as an
rns an empty array when passed null as argument beyond the first'); argument beyond the first');
assert.equal(result.length, 0, 'returns an empty array when passed null as a
rgument beyond the first');
}); });
QUnit.test('union', function(assert) { QUnit.test('union', function(assert) {
var result = _.union([1, 2, 3], [2, 30, 1], [1, 40]); var result = _.union([1, 2, 3], [2, 30, 1], [1, 40]);
assert.deepEqual(result, [1, 2, 3, 30, 40], 'takes the union of a list of ar assert.deepEqual(result, [1, 2, 3, 30, 40], 'can find the union of a list of
rays'); arrays');
result = _([1, 2, 3]).union([2, 30, 1], [1, 40]);
assert.deepEqual(result, [1, 2, 3, 30, 40], 'can perform an OO-style union')
;
result = _.union([1, 2, 3], [2, 30, 1], [1, 40, [1]]); result = _.union([1, 2, 3], [2, 30, 1], [1, 40, [1]]);
assert.deepEqual(result, [1, 2, 3, 30, 40, [1]], 'takes the union of a list of nested arrays'); assert.deepEqual(result, [1, 2, 3, 30, 40, [1]], 'can find the union of a li st of nested arrays');
var args = null; result = _.union([10, 20], [1, 30, 10], [0, 40]);
(function(){ args = arguments; }(1, 2, 3)); assert.deepEqual(result, [10, 20, 1, 30, 0, 40], 'orders values by their fir
result = _.union(args, [2, 30, 1], [1, 40]); st encounter');
assert.deepEqual(result, [1, 2, 3, 30, 40], 'takes the union of a list of ar
rays');
result = _.union([1, 2, 3], 4); result = (function(){ return _.union(arguments, [2, 30, 1], [1, 40]); }(1, 2
assert.deepEqual(result, [1, 2, 3], 'restrict the union to arrays only'); , 3));
assert.deepEqual(result, [1, 2, 3, 30, 40], 'works on an arguments object');
assert.deepEqual(_.union([1, 2, 3], 4), [1, 2, 3], 'restricts the union to a
rrays only');
}); });
QUnit.test('difference', function(assert) { QUnit.test('difference', function(assert) {
var result = _.difference([1, 2, 3], [2, 30, 40]); var result = _.difference([1, 2, 3], [2, 30, 40]);
assert.deepEqual(result, [1, 3], 'takes the difference of two arrays'); assert.deepEqual(result, [1, 3], 'can find the difference of two arrays');
result = _([1, 2, 3]).difference([2, 30, 40]);
assert.deepEqual(result, [1, 3], 'can perform an OO-style difference');
result = _.difference([1, 2, 3, 4], [2, 30, 40], [1, 11, 111]); result = _.difference([1, 2, 3, 4], [2, 30, 40], [1, 11, 111]);
assert.deepEqual(result, [3, 4], 'takes the difference of three arrays'); assert.deepEqual(result, [3, 4], 'can find the difference of three arrays');
result = _.difference([8, 9, 3, 1], [3, 8]);
assert.deepEqual(result, [9, 1], 'preserves the order of the first array');
result = (function(){ return _.difference(arguments, [2, 30, 40]); }(1, 2, 3
));
assert.deepEqual(result, [1, 3], 'works on an arguments object');
result = _.difference([1, 2, 3], 1); result = _.difference([1, 2, 3], 1);
assert.deepEqual(result, [1, 2, 3], 'restrict the difference to arrays only' ); assert.deepEqual(result, [1, 2, 3], 'restrict the difference to arrays only' );
}); });
QUnit.test('zip', function(assert) { QUnit.test('zip', function(assert) {
var names = ['moe', 'larry', 'curly'], ages = [30, 40, 50], leaders = [true] ; var names = ['moe', 'larry', 'curly'], ages = [30, 40, 50], leaders = [true] ;
assert.deepEqual(_.zip(names, ages, leaders), [ assert.deepEqual(_.zip(names, ages, leaders), [
['moe', 30, true], ['moe', 30, true],
['larry', 40, void 0], ['larry', 40, void 0],
 End of changes. 18 change blocks. 
58 lines changed or deleted 68 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)