Update vendor/underscore.

Former-commit-id: 8bb0b59d367ab2600a85a4442789eb41d9d97cb6
This commit is contained in:
John-David Dalton
2012-12-02 21:18:46 -08:00
parent f58f255fc8
commit 8b0f033a78
3 changed files with 17 additions and 24 deletions

View File

@@ -55,18 +55,16 @@ $(document).ready(function() {
test("compact", function() {
equal(_.compact([0, 1, false, 2, false, 3]).length, 3, 'can trim out all falsy values');
var result = (function(){ return _(arguments).compact().length; })(0, 1, false, 2, false, 3);
var result = (function(){ return _.compact(arguments).length; })(0, 1, false, 2, false, 3);
equal(result, 3, 'works on an arguments object');
});
test("flatten", function() {
if (window.JSON) {
var list = [1, [2], [3, [[[4]]]]];
equal(JSON.stringify(_.flatten(list)), '[1,2,3,4]', 'can flatten nested arrays');
equal(JSON.stringify(_.flatten(list, true)), '[1,2,3,[[[4]]]]', 'can shallowly flatten nested arrays');
var result = (function(){ return _.flatten(arguments); })(1, [2], [3, [[[4]]]]);
equal(JSON.stringify(result), '[1,2,3,4]', 'works on an arguments object');
}
var list = [1, [2], [3, [[[4]]]]];
equal(JSON.stringify(_.flatten(list)), '[1,2,3,4]', 'can flatten nested arrays');
equal(JSON.stringify(_.flatten(list, true)), '[1,2,3,[[[4]]]]', 'can shallowly flatten nested arrays');
var result = (function(){ return _.flatten(arguments); })(1, [2], [3, [[[4]]]]);
equal(JSON.stringify(result), '[1,2,3,4]', 'works on an arguments object');
});
test("without", function() {

View File

@@ -56,8 +56,8 @@ $(document).ready(function() {
try {
result = {};
_.extend(result, null, undefined, { 'a': 1 });
} catch(ex) { }
_.extend(result, null, undefined, {a:1});
} catch(ex) {}
equal(result.a, 1, 'should not error on `null` or `undefined` sources');
});
@@ -106,8 +106,8 @@ $(document).ready(function() {
try {
options = {};
_.defaults(options, null, undefined, { 'a': 1 });
} catch(ex) { }
_.defaults(options, null, undefined, {a:1});
} catch(ex) {}
equal(options.a, 1, 'should not error on `null` or `undefined` sources');
});
@@ -351,16 +351,10 @@ $(document).ready(function() {
// Chaining.
ok(!_.isEqual(_({x: 1, y: undefined}).chain(), _({x: 1, z: 2}).chain()), 'Chained objects containing different values are not equal');
equal(_({x: 1, y: 2}).chain().isEqual(_({x: 1, y: 2}).chain()).value(), true, '`isEqual` can be chained');
// Custom `isEqual` methods.
var isEqualObj = {isEqual: function (o) { return o.isEqual == this.isEqual; }, unique: {}};
var isEqualObjClone = {isEqual: isEqualObj.isEqual, unique: {}};
ok(_.isEqual(isEqualObj, isEqualObjClone), 'Both objects implement identical `isEqual` methods');
ok(_.isEqual(isEqualObjClone, isEqualObj), 'Commutative equality is implemented for objects with custom `isEqual` methods');
ok(!_.isEqual(isEqualObj, {}), 'Objects that do not implement equivalent `isEqual` methods are not equal');
ok(!_.isEqual({}, isEqualObj), 'Commutative equality is implemented for objects with different `isEqual` methods');
a = _({x: 1, y: 2}).chain();
b = _({x: 1, y: 2}).chain();
equal(_.isEqual(a.isEqual(b), _(true)), true, '`isEqual` can be chained');
// Objects from another frame.
ok(_.isEqual({}, iObject));

View File

@@ -175,10 +175,11 @@ $(document).ready(function() {
test('_.template provides the generated function source, when a SyntaxError occurs', function() {
try {
_.template('<b><%= if %></b>');
} catch (e) {
ok(e.source.indexOf('( if )') > 0);
_.template('<b><%= if x %></b>');
} catch (ex) {
var source = ex.source;
}
ok(/__p/.test(source));
});
test('_.template handles \\u2028 & \\u2029', function() {