mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Update vendor/underscore to v1.5.0.
Former-commit-id: 8f647bccfdd8fe81473ae7d1354056a928b6f28c
This commit is contained in:
39
vendor/underscore/test/arrays.js
vendored
39
vendor/underscore/test/arrays.js
vendored
@@ -65,6 +65,8 @@ $(document).ready(function() {
|
|||||||
deepEqual(_.flatten(list, true), [1,2,3,[[[4]]]], 'can shallowly flatten nested arrays');
|
deepEqual(_.flatten(list, true), [1,2,3,[[[4]]]], 'can shallowly flatten nested arrays');
|
||||||
var result = (function(){ return _.flatten(arguments); })(1, [2], [3, [[[4]]]]);
|
var result = (function(){ return _.flatten(arguments); })(1, [2], [3, [[[4]]]]);
|
||||||
deepEqual(result, [1,2,3,4], 'works on an arguments object');
|
deepEqual(result, [1,2,3,4], 'works on an arguments object');
|
||||||
|
list = [[1], [2], [3], [[4]]];
|
||||||
|
deepEqual(_.flatten(list, true), [1, 2, 3, [4]], 'can shallowly flatten arrays containing only other arrays');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("without", function() {
|
test("without", function() {
|
||||||
@@ -73,7 +75,7 @@ $(document).ready(function() {
|
|||||||
var result = (function(){ return _.without(arguments, 0, 1); })(1, 2, 1, 0, 3, 1, 4);
|
var result = (function(){ return _.without(arguments, 0, 1); })(1, 2, 1, 0, 3, 1, 4);
|
||||||
equal(result.join(', '), '2, 3, 4', 'works on an arguments object');
|
equal(result.join(', '), '2, 3, 4', 'works on an arguments object');
|
||||||
|
|
||||||
var list = [{one : 1}, {two : 2}];
|
list = [{one : 1}, {two : 2}];
|
||||||
ok(_.without(list, {one : 1}).length == 2, 'uses real object identity for comparisons.');
|
ok(_.without(list, {one : 1}).length == 2, 'uses real object identity for comparisons.');
|
||||||
ok(_.without(list, list[0]).length == 1, 'ditto.');
|
ok(_.without(list, list[0]).length == 1, 'ditto.');
|
||||||
});
|
});
|
||||||
@@ -82,17 +84,17 @@ $(document).ready(function() {
|
|||||||
var list = [1, 2, 1, 3, 1, 4];
|
var list = [1, 2, 1, 3, 1, 4];
|
||||||
equal(_.uniq(list).join(', '), '1, 2, 3, 4', 'can find the unique values of an unsorted array');
|
equal(_.uniq(list).join(', '), '1, 2, 3, 4', 'can find the unique values of an unsorted array');
|
||||||
|
|
||||||
var list = [1, 1, 1, 2, 2, 3];
|
list = [1, 1, 1, 2, 2, 3];
|
||||||
equal(_.uniq(list, true).join(', '), '1, 2, 3', 'can find the unique values of a sorted array faster');
|
equal(_.uniq(list, true).join(', '), '1, 2, 3', 'can find the unique values of a sorted array faster');
|
||||||
|
|
||||||
var 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 iterator = function(value) { return value.name; };
|
||||||
equal(_.map(_.uniq(list, false, iterator), iterator).join(', '), 'moe, curly, larry', 'can find the unique values of an array using a custom iterator');
|
equal(_.map(_.uniq(list, false, iterator), iterator).join(', '), 'moe, curly, larry', 'can find the unique values of an array using a custom iterator');
|
||||||
|
|
||||||
equal(_.map(_.uniq(list, iterator), iterator).join(', '), 'moe, curly, larry', 'can find the unique values of an array using a custom iterator without specifying whether array is sorted');
|
equal(_.map(_.uniq(list, iterator), iterator).join(', '), 'moe, curly, larry', 'can find the unique values of an array using a custom iterator without specifying whether array is sorted');
|
||||||
|
|
||||||
var iterator = function(value) { return value +1; };
|
iterator = function(value) { return value +1; };
|
||||||
var list = [1, 2, 2, 3, 4, 4];
|
list = [1, 2, 2, 3, 4, 4];
|
||||||
equal(_.uniq(list, true, iterator).join(', '), '1, 2, 3, 4', 'iterator works with sorted array');
|
equal(_.uniq(list, true, iterator).join(', '), '1, 2, 3, 4', 'iterator works with sorted array');
|
||||||
|
|
||||||
var result = (function(){ return _.uniq(arguments); })(1, 2, 1, 3, 1, 4);
|
var result = (function(){ return _.uniq(arguments); })(1, 2, 1, 3, 1, 4);
|
||||||
@@ -111,15 +113,20 @@ $(document).ready(function() {
|
|||||||
var result = _.union([1, 2, 3], [2, 30, 1], [1, 40]);
|
var result = _.union([1, 2, 3], [2, 30, 1], [1, 40]);
|
||||||
equal(result.join(' '), '1 2 3 30 40', 'takes the union of a list of arrays');
|
equal(result.join(' '), '1 2 3 30 40', 'takes the union of a list of arrays');
|
||||||
|
|
||||||
var result = _.union([1, 2, 3], [2, 30, 1], [1, 40, [1]]);
|
result = _.union([1, 2, 3], [2, 30, 1], [1, 40, [1]]);
|
||||||
equal(result.join(' '), '1 2 3 30 40 1', 'takes the union of a list of nested arrays');
|
equal(result.join(' '), '1 2 3 30 40 1', 'takes the union of a list of nested arrays');
|
||||||
|
|
||||||
|
var args = null;
|
||||||
|
(function(){ args = arguments; })(1, 2, 3);
|
||||||
|
result = _.union(args, [2, 30, 1], [1, 40]);
|
||||||
|
equal(result.join(' '), '1 2 3 30 40', 'takes the union of a list of arrays');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("difference", function() {
|
test("difference", function() {
|
||||||
var result = _.difference([1, 2, 3], [2, 30, 40]);
|
var result = _.difference([1, 2, 3], [2, 30, 40]);
|
||||||
equal(result.join(' '), '1 3', 'takes the difference of two arrays');
|
equal(result.join(' '), '1 3', 'takes the difference of two arrays');
|
||||||
|
|
||||||
var result = _.difference([1, 2, 3, 4], [2, 30, 40], [1, 11, 111]);
|
result = _.difference([1, 2, 3, 4], [2, 30, 40], [1, 11, 111]);
|
||||||
equal(result.join(' '), '3 4', 'takes the difference of three arrays');
|
equal(result.join(' '), '3 4', 'takes the difference of three arrays');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -129,6 +136,19 @@ $(document).ready(function() {
|
|||||||
equal(String(stooges), 'moe,30,true,larry,40,,curly,50,', 'zipped together arrays of different lengths');
|
equal(String(stooges), 'moe,30,true,larry,40,,curly,50,', 'zipped together arrays of different lengths');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('unzip', function() {
|
||||||
|
var stoogesUnzipped = _.unzip(['moe',30, 'stooge 1'],['larry',40, 'stooge 2'],['curly',50, 'stooge 3']);
|
||||||
|
deepEqual(stoogesUnzipped, [['moe','larry','curly'],[30,40,50], ['stooge 1', 'stooge 2', 'stooge 3']], 'unzipped pairs');
|
||||||
|
|
||||||
|
// In the case of difference lengths of the tuples undefineds
|
||||||
|
// should be used as placeholder
|
||||||
|
stoogesUnzipped = _.unzip(['moe',30],['larry',40],['curly',50, 'extra data']);
|
||||||
|
deepEqual(stoogesUnzipped, [['moe','larry','curly'],[30,40,50], [undefined, undefined, 'extra data']], 'unzipped pairs');
|
||||||
|
|
||||||
|
var emptyUnzipped = _.unzip([]);
|
||||||
|
deepEqual(emptyUnzipped, [], 'unzipped empty');
|
||||||
|
});
|
||||||
|
|
||||||
test('object', function() {
|
test('object', function() {
|
||||||
var result = _.object(['moe', 'larry', 'curly'], [30, 40, 50]);
|
var result = _.object(['moe', 'larry', 'curly'], [30, 40, 50]);
|
||||||
var shouldBe = {moe: 30, larry: 40, curly: 50};
|
var shouldBe = {moe: 30, larry: 40, curly: 50};
|
||||||
@@ -152,7 +172,8 @@ $(document).ready(function() {
|
|||||||
equal(result, 1, 'works on an arguments object');
|
equal(result, 1, 'works on an arguments object');
|
||||||
equal(_.indexOf(null, 2), -1, 'handles nulls properly');
|
equal(_.indexOf(null, 2), -1, 'handles nulls properly');
|
||||||
|
|
||||||
var numbers = [10, 20, 30, 40, 50], num = 35;
|
var num = 35;
|
||||||
|
numbers = [10, 20, 30, 40, 50];
|
||||||
var index = _.indexOf(numbers, num, true);
|
var index = _.indexOf(numbers, num, true);
|
||||||
equal(index, -1, '35 is not in the list');
|
equal(index, -1, '35 is not in the list');
|
||||||
|
|
||||||
@@ -179,7 +200,7 @@ $(document).ready(function() {
|
|||||||
equal(_.lastIndexOf(numbers, 0), 8, 'lastIndexOf the other element');
|
equal(_.lastIndexOf(numbers, 0), 8, 'lastIndexOf the other element');
|
||||||
var result = (function(){ return _.lastIndexOf(arguments, 1); })(1, 0, 1, 0, 0, 1, 0, 0, 0);
|
var result = (function(){ return _.lastIndexOf(arguments, 1); })(1, 0, 1, 0, 0, 1, 0, 0, 0);
|
||||||
equal(result, 5, 'works on an arguments object');
|
equal(result, 5, 'works on an arguments object');
|
||||||
equal(_.indexOf(null, 2), -1, 'handles nulls properly');
|
equal(_.lastIndexOf(null, 2), -1, 'handles nulls properly');
|
||||||
|
|
||||||
numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3];
|
numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3];
|
||||||
var index = _.lastIndexOf(numbers, 2, 2);
|
var index = _.lastIndexOf(numbers, 2, 2);
|
||||||
|
|||||||
16
vendor/underscore/test/chaining.js
vendored
16
vendor/underscore/test/chaining.js
vendored
@@ -17,15 +17,15 @@ $(document).ready(function() {
|
|||||||
hash[l]++;
|
hash[l]++;
|
||||||
return hash;
|
return hash;
|
||||||
}, {}).value();
|
}, {}).value();
|
||||||
ok(counts['a'] == 16 && counts['e'] == 10, 'counted all the letters in the song');
|
ok(counts.a == 16 && counts.e == 10, 'counted all the letters in the song');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("select/reject/sortBy", function() {
|
test("select/reject/sortBy", function() {
|
||||||
var numbers = [1,2,3,4,5,6,7,8,9,10];
|
var numbers = [1,2,3,4,5,6,7,8,9,10];
|
||||||
numbers = _(numbers).chain().select(function(n) {
|
numbers = _(numbers).chain().select(function(n) {
|
||||||
return n % 2 == 0;
|
return n % 2 === 0;
|
||||||
}).reject(function(n) {
|
}).reject(function(n) {
|
||||||
return n % 4 == 0;
|
return n % 4 === 0;
|
||||||
}).sortBy(function(n) {
|
}).sortBy(function(n) {
|
||||||
return -n;
|
return -n;
|
||||||
}).value();
|
}).value();
|
||||||
@@ -35,9 +35,9 @@ $(document).ready(function() {
|
|||||||
test("select/reject/sortBy in functional style", function() {
|
test("select/reject/sortBy in functional style", function() {
|
||||||
var numbers = [1,2,3,4,5,6,7,8,9,10];
|
var numbers = [1,2,3,4,5,6,7,8,9,10];
|
||||||
numbers = _.chain(numbers).select(function(n) {
|
numbers = _.chain(numbers).select(function(n) {
|
||||||
return n % 2 == 0;
|
return n % 2 === 0;
|
||||||
}).reject(function(n) {
|
}).reject(function(n) {
|
||||||
return n % 4 == 0;
|
return n % 4 === 0;
|
||||||
}).sortBy(function(n) {
|
}).sortBy(function(n) {
|
||||||
return -n;
|
return -n;
|
||||||
}).value();
|
}).value();
|
||||||
@@ -56,4 +56,10 @@ $(document).ready(function() {
|
|||||||
equal(numbers.join(', '), "34, 10, 8, 6, 4, 2, 10, 10", 'can chain together array functions.');
|
equal(numbers.join(', '), "34, 10, 8, 6, 4, 2, 10, 10", 'can chain together array functions.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("chaining works in small stages", function() {
|
||||||
|
var o = _([1, 2, 3, 4]).chain();
|
||||||
|
deepEqual(o.filter(function(i) { return i < 3; }).value(), [1, 2]);
|
||||||
|
deepEqual(o.filter(function(i) { return i > 2; }).value(), [3, 4]);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
24
vendor/underscore/test/collections.js
vendored
24
vendor/underscore/test/collections.js
vendored
@@ -76,13 +76,16 @@ $(document).ready(function() {
|
|||||||
var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; });
|
var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; });
|
||||||
equal(sum, 6, 'default initial value');
|
equal(sum, 6, 'default initial value');
|
||||||
|
|
||||||
|
var prod = _.reduce([1, 2, 3, 4], function(prod, num){ return prod * num; });
|
||||||
|
equal(prod, 24, 'can reduce via multiplication');
|
||||||
|
|
||||||
var ifnull;
|
var ifnull;
|
||||||
try {
|
try {
|
||||||
_.reduce(null, function(){});
|
_.reduce(null, function(){});
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
ifnull = ex;
|
ifnull = ex;
|
||||||
}
|
}
|
||||||
ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly');
|
ok(ifnull instanceof TypeError, 'handles a null (without initial value) properly');
|
||||||
|
|
||||||
ok(_.reduce(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
|
ok(_.reduce(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
|
||||||
equal(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
|
equal(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
|
||||||
@@ -105,7 +108,7 @@ $(document).ready(function() {
|
|||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
ifnull = ex;
|
ifnull = ex;
|
||||||
}
|
}
|
||||||
ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly');
|
ok(ifnull instanceof TypeError, 'handles a null (without initial value) properly');
|
||||||
|
|
||||||
var sum = _.reduceRight({a: 1, b: 2, c: 3}, function(sum, num){ return sum + num; });
|
var sum = _.reduceRight({a: 1, b: 2, c: 3}, function(sum, num){ return sum + num; });
|
||||||
equal(sum, 6, 'default initial value on object');
|
equal(sum, 6, 'default initial value on object');
|
||||||
@@ -258,6 +261,11 @@ $(document).ready(function() {
|
|||||||
result = _.where(list, {b: 2});
|
result = _.where(list, {b: 2});
|
||||||
equal(result.length, 2);
|
equal(result.length, 2);
|
||||||
equal(result[0].a, 1);
|
equal(result[0].a, 1);
|
||||||
|
|
||||||
|
result = _.where(list, {a: 1}, true);
|
||||||
|
equal(result.b, 2, "Only get the first object matched.")
|
||||||
|
result = _.where(list, {a: 1}, false);
|
||||||
|
equal(result.length, 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('findWhere', function() {
|
test('findWhere', function() {
|
||||||
@@ -361,6 +369,14 @@ $(document).ready(function() {
|
|||||||
var grouped = _.groupBy(array);
|
var grouped = _.groupBy(array);
|
||||||
equal(grouped['1'].length, 2);
|
equal(grouped['1'].length, 2);
|
||||||
equal(grouped['3'].length, 1);
|
equal(grouped['3'].length, 1);
|
||||||
|
|
||||||
|
var matrix = [
|
||||||
|
[1,2],
|
||||||
|
[1,3],
|
||||||
|
[2,3]
|
||||||
|
];
|
||||||
|
deepEqual(_.groupBy(matrix, 0), {1: [[1,2], [1,3]], 2: [[2,3]]})
|
||||||
|
deepEqual(_.groupBy(matrix, 1), {2: [[1,2]], 3: [[1,3], [2,3]]})
|
||||||
});
|
});
|
||||||
|
|
||||||
test('countBy', function() {
|
test('countBy', function() {
|
||||||
@@ -438,6 +454,7 @@ $(document).ready(function() {
|
|||||||
test('size', function() {
|
test('size', function() {
|
||||||
equal(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object');
|
equal(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object');
|
||||||
equal(_.size([1, 2, 3]), 3, 'can compute the size of an array');
|
equal(_.size([1, 2, 3]), 3, 'can compute the size of an array');
|
||||||
|
equal(_.size($('<div>').add('<span>').add('<span>')), 3, 'can compute the size of jQuery objects');
|
||||||
|
|
||||||
var func = function() {
|
var func = function() {
|
||||||
return _.size(arguments);
|
return _.size(arguments);
|
||||||
@@ -445,7 +462,8 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
equal(func(1, 2, 3, 4), 4, 'can test the size of the arguments object');
|
equal(func(1, 2, 3, 4), 4, 'can test the size of the arguments object');
|
||||||
|
|
||||||
equal(_.size('hello'), 5, 'can compute the size of a string');
|
equal(_.size('hello'), 5, 'can compute the size of a string literal');
|
||||||
|
equal(_.size(new String('hello')), 5, 'can compute the size of string object');
|
||||||
|
|
||||||
equal(_.size(null), 0, 'handles nulls');
|
equal(_.size(null), 0, 'handles nulls');
|
||||||
});
|
});
|
||||||
|
|||||||
62
vendor/underscore/test/functions.js
vendored
62
vendor/underscore/test/functions.js
vendored
@@ -34,7 +34,10 @@ $(document).ready(function() {
|
|||||||
// To test this with a modern browser, set underscore's nativeBind to undefined
|
// To test this with a modern browser, set underscore's nativeBind to undefined
|
||||||
var F = function () { return this; };
|
var F = function () { return this; };
|
||||||
var Boundf = _.bind(F, {hello: "moe curly"});
|
var Boundf = _.bind(F, {hello: "moe curly"});
|
||||||
|
var newBoundf = new Boundf();
|
||||||
|
equal(newBoundf.hello, undefined, "function should not be bound to the context, to comply with ECMAScript 5");
|
||||||
equal(Boundf().hello, "moe curly", "When called without the new operator, it's OK to be bound to the context");
|
equal(Boundf().hello, "moe curly", "When called without the new operator, it's OK to be bound to the context");
|
||||||
|
ok(newBoundf instanceof F, "a bound instance is an instance of the original function");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("partial", function() {
|
test("partial", function() {
|
||||||
@@ -63,18 +66,21 @@ $(document).ready(function() {
|
|||||||
getName : function() { return 'name: ' + this.name; },
|
getName : function() { return 'name: ' + this.name; },
|
||||||
sayHi : function() { return 'hi: ' + this.name; }
|
sayHi : function() { return 'hi: ' + this.name; }
|
||||||
};
|
};
|
||||||
_.bindAll(moe);
|
|
||||||
|
raises(function() { _.bindAll(moe); }, Error, 'throws an error for bindAll with no functions named');
|
||||||
|
|
||||||
|
_.bindAll(moe, 'sayHi');
|
||||||
curly.sayHi = moe.sayHi;
|
curly.sayHi = moe.sayHi;
|
||||||
equal(curly.sayHi(), 'hi: moe', 'calling bindAll with no arguments binds all functions to the object');
|
equal(curly.sayHi(), 'hi: moe');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("memoize", function() {
|
test("memoize", function() {
|
||||||
var fib = function(n) {
|
var fib = function(n) {
|
||||||
return n < 2 ? n : fib(n - 1) + fib(n - 2);
|
return n < 2 ? n : fib(n - 1) + fib(n - 2);
|
||||||
};
|
};
|
||||||
var fastFib = _.memoize(fib);
|
|
||||||
equal(fib(10), 55, 'a memoized version of fibonacci produces identical results');
|
equal(fib(10), 55, 'a memoized version of fibonacci produces identical results');
|
||||||
equal(fastFib(10), 55, 'a memoized version of fibonacci produces identical results');
|
fib = _.memoize(fib); // Redefine `fib` for memoization
|
||||||
|
equal(fib(10), 55, 'a memoized version of fibonacci produces identical results');
|
||||||
|
|
||||||
var o = function(str) {
|
var o = function(str) {
|
||||||
return str;
|
return str;
|
||||||
@@ -177,6 +183,41 @@ $(document).ready(function() {
|
|||||||
}, 96);
|
}, 96);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
asyncTest("throttle does not trigger leading call when leading is set to false", 2, function() {
|
||||||
|
var counter = 0;
|
||||||
|
var incr = function(){ counter++; };
|
||||||
|
var throttledIncr = _.throttle(incr, 60, {leading: false});
|
||||||
|
|
||||||
|
throttledIncr(); throttledIncr();
|
||||||
|
ok(counter === 0);
|
||||||
|
|
||||||
|
_.delay(function() {
|
||||||
|
ok(counter == 1);
|
||||||
|
start();
|
||||||
|
}, 96);
|
||||||
|
});
|
||||||
|
|
||||||
|
asyncTest("throttle does not trigger trailing call when trailing is set to false", 4, function() {
|
||||||
|
var counter = 0;
|
||||||
|
var incr = function(){ counter++; };
|
||||||
|
var throttledIncr = _.throttle(incr, 60, {trailing: false});
|
||||||
|
|
||||||
|
throttledIncr(); throttledIncr(); throttledIncr();
|
||||||
|
ok(counter === 1);
|
||||||
|
|
||||||
|
_.delay(function() {
|
||||||
|
ok(counter == 1);
|
||||||
|
|
||||||
|
throttledIncr(); throttledIncr();
|
||||||
|
ok(counter == 2);
|
||||||
|
|
||||||
|
_.delay(function() {
|
||||||
|
ok(counter == 2);
|
||||||
|
start();
|
||||||
|
}, 96);
|
||||||
|
}, 96);
|
||||||
|
});
|
||||||
|
|
||||||
asyncTest("debounce", 1, function() {
|
asyncTest("debounce", 1, function() {
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
var incr = function(){ counter++; };
|
var incr = function(){ counter++; };
|
||||||
@@ -221,10 +262,18 @@ $(document).ready(function() {
|
|||||||
equal(num, 1);
|
equal(num, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Recursive onced function.", 1, function() {
|
||||||
|
var f = _.once(function(){
|
||||||
|
ok(true);
|
||||||
|
f();
|
||||||
|
});
|
||||||
|
f();
|
||||||
|
});
|
||||||
|
|
||||||
test("wrap", function() {
|
test("wrap", function() {
|
||||||
var greet = function(name){ return "hi: " + name; };
|
var greet = function(name){ return "hi: " + name; };
|
||||||
var backwards = _.wrap(greet, function(func, name){ return func(name) + ' ' + name.split('').reverse().join(''); });
|
var backwards = _.wrap(greet, function(func, name){ return func(name) + ' ' + name.split('').reverse().join(''); });
|
||||||
equal(backwards('moe'), 'hi: moe eom', 'wrapped the saluation function');
|
equal(backwards('moe'), 'hi: moe eom', 'wrapped the salutation function');
|
||||||
|
|
||||||
var inner = function(){ return "Hello "; };
|
var inner = function(){ return "Hello "; };
|
||||||
var obj = {name : "Moe"};
|
var obj = {name : "Moe"};
|
||||||
@@ -259,7 +308,8 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
equal(testAfter(5, 5), 1, "after(N) should fire after being called N times");
|
equal(testAfter(5, 5), 1, "after(N) should fire after being called N times");
|
||||||
equal(testAfter(5, 4), 0, "after(N) should not fire unless called N times");
|
equal(testAfter(5, 4), 0, "after(N) should not fire unless called N times");
|
||||||
equal(testAfter(0, 0), 1, "after(0) should fire immediately");
|
equal(testAfter(0, 0), 0, "after(0) should not fire immediately");
|
||||||
|
equal(testAfter(0, 1), 1, "after(0) should fire when first invoked");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
13
vendor/underscore/test/objects.js
vendored
13
vendor/underscore/test/objects.js
vendored
@@ -46,7 +46,7 @@ $(document).ready(function() {
|
|||||||
var result;
|
var result;
|
||||||
equal(_.extend({}, {a:'b'}).a, 'b', 'can extend an object with the attributes of another');
|
equal(_.extend({}, {a:'b'}).a, 'b', 'can extend an object with the attributes of another');
|
||||||
equal(_.extend({a:'x'}, {a:'b'}).a, 'b', 'properties in source override destination');
|
equal(_.extend({a:'x'}, {a:'b'}).a, 'b', 'properties in source override destination');
|
||||||
equal(_.extend({x:'x'}, {a:'b'}).x, 'x', 'properties not in source dont get overriden');
|
equal(_.extend({x:'x'}, {a:'b'}).x, 'x', "properties not in source don't get overriden");
|
||||||
result = _.extend({x:'x'}, {a:'a'}, {b:'b'});
|
result = _.extend({x:'x'}, {a:'a'}, {b:'b'});
|
||||||
ok(_.isEqual(result, {x:'x', a:'a', b:'b'}), 'can extend from multiple source objects');
|
ok(_.isEqual(result, {x:'x', a:'a', b:'b'}), 'can extend from multiple source objects');
|
||||||
result = _.extend({x:'x'}, {a:'a', x:2}, {a:'b'});
|
result = _.extend({x:'x'}, {a:'a', x:2}, {a:'b'});
|
||||||
@@ -92,12 +92,13 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
test("defaults", function() {
|
test("defaults", function() {
|
||||||
var result;
|
var result;
|
||||||
var options = {zero: 0, one: 1, empty: "", nan: NaN, string: "string"};
|
var options = {zero: 0, one: 1, empty: "", nan: NaN, nothing: null};
|
||||||
|
|
||||||
_.defaults(options, {zero: 1, one: 10, twenty: 20});
|
_.defaults(options, {zero: 1, one: 10, twenty: 20, nothing: 'str'});
|
||||||
equal(options.zero, 0, 'value exists');
|
equal(options.zero, 0, 'value exists');
|
||||||
equal(options.one, 1, 'value exists');
|
equal(options.one, 1, 'value exists');
|
||||||
equal(options.twenty, 20, 'default applied');
|
equal(options.twenty, 20, 'default applied');
|
||||||
|
equal(options.nothing, null, "null isn't overridden");
|
||||||
|
|
||||||
_.defaults(options, {empty: "full"}, {nan: "nan"}, {word: "word"}, {word: "dog"});
|
_.defaults(options, {empty: "full"}, {nan: "nan"}, {word: "word"}, {word: "dog"});
|
||||||
equal(options.empty, "", 'value exists');
|
equal(options.empty, "", 'value exists');
|
||||||
@@ -431,15 +432,19 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("isArray", function() {
|
test("isArray", function() {
|
||||||
|
ok(!_.isArray(undefined), 'undefined vars are not arrays');
|
||||||
ok(!_.isArray(arguments), 'the arguments object is not an array');
|
ok(!_.isArray(arguments), 'the arguments object is not an array');
|
||||||
ok(_.isArray([1, 2, 3]), 'but arrays are');
|
ok(_.isArray([1, 2, 3]), 'but arrays are');
|
||||||
ok(_.isArray(iArray), 'even from another frame');
|
ok(_.isArray(iArray), 'even from another frame');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isString", function() {
|
test("isString", function() {
|
||||||
|
var obj = new String("I am a string object");
|
||||||
ok(!_.isString(document.body), 'the document body is not a string');
|
ok(!_.isString(document.body), 'the document body is not a string');
|
||||||
ok(_.isString([1, 2, 3].join(', ')), 'but strings are');
|
ok(_.isString([1, 2, 3].join(', ')), 'but strings are');
|
||||||
ok(_.isString(iString), 'even from another frame');
|
ok(_.isString(iString), 'even from another frame');
|
||||||
|
ok(_.isString("I am a string literal"), 'string literals are');
|
||||||
|
ok(_.isString(obj), 'so are String objects');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isNumber", function() {
|
test("isNumber", function() {
|
||||||
@@ -468,10 +473,12 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("isFunction", function() {
|
test("isFunction", function() {
|
||||||
|
ok(!_.isFunction(undefined), 'undefined vars are not functions');
|
||||||
ok(!_.isFunction([1, 2, 3]), 'arrays are not functions');
|
ok(!_.isFunction([1, 2, 3]), 'arrays are not functions');
|
||||||
ok(!_.isFunction('moe'), 'strings are not functions');
|
ok(!_.isFunction('moe'), 'strings are not functions');
|
||||||
ok(_.isFunction(_.isFunction), 'but functions are');
|
ok(_.isFunction(_.isFunction), 'but functions are');
|
||||||
ok(_.isFunction(iFunction), 'even from another frame');
|
ok(_.isFunction(iFunction), 'even from another frame');
|
||||||
|
ok(_.isFunction(function(){}), 'even anonymous ones');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isDate", function() {
|
test("isDate", function() {
|
||||||
|
|||||||
8
vendor/underscore/test/utility.js
vendored
8
vendor/underscore/test/utility.js
vendored
@@ -55,6 +55,10 @@ $(document).ready(function() {
|
|||||||
ok(_.isEqual(vals, [0,1,2]), "works as a wrapper");
|
ok(_.isEqual(vals, [0,1,2]), "works as a wrapper");
|
||||||
// collects return values
|
// collects return values
|
||||||
ok(_.isEqual([0, 1, 2], _.times(3, function(i) { return i; })), "collects return values");
|
ok(_.isEqual([0, 1, 2], _.times(3, function(i) { return i; })), "collects return values");
|
||||||
|
|
||||||
|
deepEqual(_.times(0, _.identity), []);
|
||||||
|
deepEqual(_.times(-1, _.identity), []);
|
||||||
|
deepEqual(_.times(parseFloat('-Infinity'), _.identity), []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("mixin", function() {
|
test("mixin", function() {
|
||||||
@@ -69,6 +73,7 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
test("_.escape", function() {
|
test("_.escape", function() {
|
||||||
equal(_.escape("Curly & Moe"), "Curly & Moe");
|
equal(_.escape("Curly & Moe"), "Curly & Moe");
|
||||||
|
equal(_.escape('<a href="http://moe.com">Curly & Moe\'s</a>'), '<a href="http://moe.com">Curly & Moe's</a>');
|
||||||
equal(_.escape("Curly & Moe"), "Curly &amp; Moe");
|
equal(_.escape("Curly & Moe"), "Curly &amp; Moe");
|
||||||
equal(_.escape(null), '');
|
equal(_.escape(null), '');
|
||||||
});
|
});
|
||||||
@@ -76,6 +81,7 @@ $(document).ready(function() {
|
|||||||
test("_.unescape", function() {
|
test("_.unescape", function() {
|
||||||
var string = "Curly & Moe";
|
var string = "Curly & Moe";
|
||||||
equal(_.unescape("Curly & Moe"), string);
|
equal(_.unescape("Curly & Moe"), string);
|
||||||
|
equal(_.unescape('<a href="http://moe.com">Curly & Moe's</a>'), '<a href="http://moe.com">Curly & Moe\'s</a>');
|
||||||
equal(_.unescape("Curly &amp; Moe"), "Curly & Moe");
|
equal(_.unescape("Curly &amp; Moe"), "Curly & Moe");
|
||||||
equal(_.unescape(null), '');
|
equal(_.unescape(null), '');
|
||||||
equal(_.unescape(_.escape(string)), string);
|
equal(_.unescape(_.escape(string)), string);
|
||||||
@@ -207,7 +213,7 @@ $(document).ready(function() {
|
|||||||
strictEqual(_.result(obj, 'x'), 'x');
|
strictEqual(_.result(obj, 'x'), 'x');
|
||||||
strictEqual(_.result(obj, 'y'), 'x');
|
strictEqual(_.result(obj, 'y'), 'x');
|
||||||
strictEqual(_.result(obj, 'z'), undefined);
|
strictEqual(_.result(obj, 'z'), undefined);
|
||||||
strictEqual(_.result(null, 'x'), null);
|
strictEqual(_.result(null, 'x'), undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('_.templateSettings.variable', function() {
|
test('_.templateSettings.variable', function() {
|
||||||
|
|||||||
5
vendor/underscore/underscore-min.js
vendored
5
vendor/underscore/underscore-min.js
vendored
File diff suppressed because one or more lines are too long
42
vendor/underscore/underscore.js
vendored
42
vendor/underscore/underscore.js
vendored
@@ -1,4 +1,4 @@
|
|||||||
// Underscore.js 1.4.4
|
// Underscore.js 1.5.0
|
||||||
// http://underscorejs.org
|
// http://underscorejs.org
|
||||||
// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
|
// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
|
||||||
// (c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
// (c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Current version.
|
// Current version.
|
||||||
_.VERSION = '1.4.4';
|
_.VERSION = '1.5.0';
|
||||||
|
|
||||||
// Collection Functions
|
// Collection Functions
|
||||||
// --------------------
|
// --------------------
|
||||||
@@ -424,6 +424,9 @@
|
|||||||
|
|
||||||
// Internal implementation of a recursive `flatten` function.
|
// Internal implementation of a recursive `flatten` function.
|
||||||
var flatten = function(input, shallow, output) {
|
var flatten = function(input, shallow, output) {
|
||||||
|
if (shallow && _.every(input, _.isArray)) {
|
||||||
|
return concat.apply(output, input);
|
||||||
|
}
|
||||||
each(input, function(value) {
|
each(input, function(value) {
|
||||||
if (_.isArray(value) || _.isArguments(value)) {
|
if (_.isArray(value) || _.isArguments(value)) {
|
||||||
shallow ? push.apply(output, value) : flatten(value, shallow, output);
|
shallow ? push.apply(output, value) : flatten(value, shallow, output);
|
||||||
@@ -492,7 +495,7 @@
|
|||||||
// Zip together multiple lists into a single array -- elements that share
|
// Zip together multiple lists into a single array -- elements that share
|
||||||
// an index go together.
|
// an index go together.
|
||||||
_.zip = function() {
|
_.zip = function() {
|
||||||
return _.unzip(slice.call(arguments));
|
return _.unzip.apply(_, slice.call(arguments));
|
||||||
};
|
};
|
||||||
|
|
||||||
// The inverse operation to `_.zip`. If given an array of pairs it
|
// The inverse operation to `_.zip`. If given an array of pairs it
|
||||||
@@ -501,11 +504,11 @@
|
|||||||
// three element array and so on. For example, `_.unzip` given
|
// three element array and so on. For example, `_.unzip` given
|
||||||
// `[['a',1],['b',2],['c',3]]` returns the array
|
// `[['a',1],['b',2],['c',3]]` returns the array
|
||||||
// [['a','b','c'],[1,2,3]].
|
// [['a','b','c'],[1,2,3]].
|
||||||
_.unzip = function(list) {
|
_.unzip = function() {
|
||||||
var length = _.max(_.pluck(list, "length").concat(0));
|
var length = _.max(_.pluck(arguments, "length").concat(0));
|
||||||
var results = new Array(length);
|
var results = new Array(length);
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
results[i] = _.pluck(list, '' + i);
|
results[i] = _.pluck(arguments, '' + i);
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
@@ -649,11 +652,15 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Returns a function, that, when invoked, will only be triggered at most once
|
// Returns a function, that, when invoked, will only be triggered at most once
|
||||||
// during a given window of time.
|
// during a given window of time. Normally, the throttled function will run
|
||||||
_.throttle = function(func, wait, immediate) {
|
// as much as it can, without ever going more than once per `wait` duration;
|
||||||
|
// but if you'd like to disable the execution on the leading edge, pass
|
||||||
|
// `{leading: false}`. To disable execution on the trailing edge, ditto.
|
||||||
|
_.throttle = function(func, wait, options) {
|
||||||
var context, args, result;
|
var context, args, result;
|
||||||
var timeout = null;
|
var timeout = null;
|
||||||
var previous = 0;
|
var previous = 0;
|
||||||
|
options || (options = {});
|
||||||
var later = function() {
|
var later = function() {
|
||||||
previous = new Date;
|
previous = new Date;
|
||||||
timeout = null;
|
timeout = null;
|
||||||
@@ -661,7 +668,7 @@
|
|||||||
};
|
};
|
||||||
return function() {
|
return function() {
|
||||||
var now = new Date;
|
var now = new Date;
|
||||||
if (!previous && immediate === false) previous = now;
|
if (!previous && options.leading === false) previous = now;
|
||||||
var remaining = wait - (now - previous);
|
var remaining = wait - (now - previous);
|
||||||
context = this;
|
context = this;
|
||||||
args = arguments;
|
args = arguments;
|
||||||
@@ -670,7 +677,7 @@
|
|||||||
timeout = null;
|
timeout = null;
|
||||||
previous = now;
|
previous = now;
|
||||||
result = func.apply(context, args);
|
result = func.apply(context, args);
|
||||||
} else if (!timeout) {
|
} else if (!timeout && options.trailing !== false) {
|
||||||
timeout = setTimeout(later, remaining);
|
timeout = setTimeout(later, remaining);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -737,7 +744,6 @@
|
|||||||
|
|
||||||
// Returns a function that will only be executed after being called N times.
|
// Returns a function that will only be executed after being called N times.
|
||||||
_.after = function(times, func) {
|
_.after = function(times, func) {
|
||||||
if (times <= 0) return func();
|
|
||||||
return function() {
|
return function() {
|
||||||
if (--times < 1) {
|
if (--times < 1) {
|
||||||
return func.apply(this, arguments);
|
return func.apply(this, arguments);
|
||||||
@@ -891,6 +897,13 @@
|
|||||||
// unique nested structures.
|
// unique nested structures.
|
||||||
if (aStack[length] == a) return bStack[length] == b;
|
if (aStack[length] == a) return bStack[length] == b;
|
||||||
}
|
}
|
||||||
|
// Objects with different constructors are not equivalent, but `Object`s
|
||||||
|
// from different frames are.
|
||||||
|
var aCtor = a.constructor, bCtor = b.constructor;
|
||||||
|
if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
|
||||||
|
_.isFunction(bCtor) && (bCtor instanceof bCtor))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Add the first object to the stack of traversed objects.
|
// Add the first object to the stack of traversed objects.
|
||||||
aStack.push(a);
|
aStack.push(a);
|
||||||
bStack.push(b);
|
bStack.push(b);
|
||||||
@@ -907,13 +920,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Objects with different constructors are not equivalent, but `Object`s
|
|
||||||
// from different frames are.
|
|
||||||
var aCtor = a.constructor, bCtor = b.constructor;
|
|
||||||
if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
|
|
||||||
_.isFunction(bCtor) && (bCtor instanceof bCtor))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Deep compare objects.
|
// Deep compare objects.
|
||||||
for (var key in a) {
|
for (var key in a) {
|
||||||
if (_.has(a, key)) {
|
if (_.has(a, key)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user