Ensure _.isEqual matches values with circular references correctly.

Former-commit-id: 07968aeb430f56c32aab22dfda919706da840680
This commit is contained in:
John-David Dalton
2012-09-09 11:54:32 -07:00
parent ac78c5f4e5
commit c30bcdd515
3 changed files with 63 additions and 47 deletions

View File

@@ -770,15 +770,23 @@
equal(_.isEqual(shadowed, {}), false);
});
test('should return `true` for like-objects from different documents', function() {
// ensure `_._object` is assigned (unassigned in Opera 10.00)
if (_._object) {
var object = { 'a': 1, 'b': 2, 'c': 3 };
equal(_.isEqual(object, _._object), true);
}
else {
skipTest();
}
test('should use custom `isEqual` methods on primitives', function() {
Boolean.prototype.isEqual = function() { return true; };
equal(_.isEqual(true, false), true);
delete Boolean.prototype.isEqual;
});
test('should return `false` when comparing values with circular references to unlike values', function() {
var array1 = ['a', null, 'c'],
array2 = ['a', [], 'c'],
object1 = { 'a': 1, 'b': null, 'c': 3 },
object2 = { 'a': 1, 'b': {}, 'c': 3 };
array1[1] = array1;
equal(_.isEqual(array1, array2), false);
object1.b = object1;
equal(_.isEqual(object1, object2), false);
});
}());