mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
merging ratbeard's numerous improvements
This commit is contained in:
@@ -164,5 +164,12 @@ $(document).ready(function() {
|
||||
test('collections: size', function() {
|
||||
equals(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object');
|
||||
});
|
||||
|
||||
test('collections: buildLookup', function() {
|
||||
same(_.buildLookup([1,'hi']), {1:true, 'hi':true}, 'defaults values to true');
|
||||
same(_.buildLookup([1,'hi'], 1), {1:1, 'hi':1}, 'can override value');
|
||||
same(_.buildLookup({5:'five'}), {five: true}, 'making a map from an object uses its values');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -11,13 +11,13 @@ $(document).ready(function() {
|
||||
});
|
||||
|
||||
test("objects: functions", function() {
|
||||
var expected = ["all", "any", "bind", "bindAll", "breakLoop", "clone", "compact",
|
||||
var expected = ["alias", "all", "any", "bind", "bindAll", "breakLoop", "buildLookup", "clone", "compact",
|
||||
"compose","defer", "delay", "detect", "each", "every", "extend", "filter", "first",
|
||||
"flatten", "foldl", "foldr", "forEach", "functions", "head", "identity", "include",
|
||||
"indexOf", "inject", "intersect", "invoke", "isArguments", "isArray", "isDate", "isElement", "isEmpty", "isEqual",
|
||||
"isFunction", "isNaN", "isNull", "isNumber", "isRegExp", "isString", "isUndefined", "keys", "last", "lastIndexOf", "map", "max",
|
||||
"methods", "min", "noConflict", "pluck", "range", "reduce", "reduceRight", "reject", "rest", "select",
|
||||
"size", "some", "sortBy", "sortedIndex", "tail", "tap", "template", "toArray", "uniq",
|
||||
"size", "some", "sortBy", "sortedIndex", "tail", "tap", "template", "times", "toArray", "uniq",
|
||||
"uniqueId", "values", "without", "wrap", "zip"];
|
||||
ok(_(expected).isEqual(_.methods(_)), 'provides a sorted list of functions');
|
||||
var obj = {a : 'dash', b : _.map, c : (/yo/), d : _.reduce};
|
||||
@@ -60,6 +60,8 @@ $(document).ready(function() {
|
||||
ok(_.isEmpty([]), '[] is empty');
|
||||
ok(!_.isEmpty({one : 1}), '{one : 1} is not empty');
|
||||
ok(_.isEmpty({}), '{} is empty');
|
||||
ok(_.isEmpty(null), 'null is empty');
|
||||
ok(_.isEmpty(), 'undefined is empty');
|
||||
|
||||
var obj = {one : 1};
|
||||
delete obj.one;
|
||||
@@ -183,4 +185,19 @@ $(document).ready(function() {
|
||||
value();
|
||||
ok(returned == 6 && intercepted == 6, 'can use tapped objects in a chain');
|
||||
});
|
||||
|
||||
|
||||
test("objects: alias", function() {
|
||||
_.alias('isEqual', 'isTheSame');
|
||||
ok(_.isTheSame(9, 9), 'by default aliases methods on underscore');
|
||||
delete _.isTheSame;
|
||||
//
|
||||
var o = { hi: function () {return 9;} };
|
||||
_.alias(o, 'hi', 'ho');
|
||||
equals(o.ho(), 9, 'can add an alias on another object');
|
||||
_.alias(o, 'hi', 'there', 'sir');
|
||||
ok(o.hi==o.sir, 'can add multiple aliases');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -29,6 +29,17 @@ $(document).ready(function() {
|
||||
while(i++ < 100) ids.push(_.uniqueId());
|
||||
equals(_.uniq(ids).length, ids.length, 'can generate a globally-unique stream of ids');
|
||||
});
|
||||
|
||||
test("utility: times", function() {
|
||||
var vals = [];
|
||||
_.times(3, function (i) { vals.push(i); });
|
||||
ok(_.isEqual(vals, [0,1,2]), "is 0 indexed");
|
||||
//
|
||||
vals = [];
|
||||
_(3).times(function (i) { vals.push(i); });
|
||||
ok(_.isEqual(vals, [0,1,2]), "works as a wrapper");
|
||||
});
|
||||
|
||||
|
||||
test("utility: template", function() {
|
||||
var basicTemplate = _.template("<%= thing %> is gettin' on my noives!");
|
||||
|
||||
Reference in New Issue
Block a user