Increase test coverage of symbols.

This commit is contained in:
John-David Dalton
2016-01-09 01:05:43 -08:00
parent 5d97cdbcfe
commit 4a0415a6bd
3 changed files with 33 additions and 5 deletions

View File

@@ -3669,7 +3669,7 @@
* @returns {Object} Returns the cloned symbol object. * @returns {Object} Returns the cloned symbol object.
*/ */
function cloneSymbol(symbol) { function cloneSymbol(symbol) {
return Object(symbolValueOf.call(symbol)); return _Symbol ? Object(symbolValueOf.call(symbol)) : {};
} }
/** /**
@@ -4557,7 +4557,7 @@
equalFunc(convert(object), convert(other), customizer, bitmask | UNORDERED_COMPARE_FLAG); equalFunc(convert(object), convert(other), customizer, bitmask | UNORDERED_COMPARE_FLAG);
case symbolTag: case symbolTag:
return symbolValueOf.call(object) == symbolValueOf.call(other); return !!_Symbol && (symbolValueOf.call(object) == symbolValueOf.call(other));
} }
return false; return false;
} }
@@ -10347,7 +10347,10 @@
if (value == null) { if (value == null) {
return ''; return '';
} }
var result = isSymbol(value) ? symbolToString.call(value) : (value + ''); if (isSymbol(value)) {
return _Symbol ? symbolToString.call(value) : '';
}
var result = (value + '');
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
} }

View File

@@ -112,6 +112,9 @@
setProperty(window, '_Set', window.Set); setProperty(window, '_Set', window.Set);
setProperty(window, 'Set', noop); setProperty(window, 'Set', noop);
setProperty(window, '_Symbol', window.Symbol);
setProperty(window, 'Symbol', undefined);
setProperty(window, '_WeakMap', window.WeakMap); setProperty(window, '_WeakMap', window.WeakMap);
setProperty(window, 'WeakMap', noop); setProperty(window, 'WeakMap', noop);
@@ -148,6 +151,9 @@
} else { } else {
setProperty(window, 'Set', undefined); setProperty(window, 'Set', undefined);
} }
if (_Symbol) {
Symbol = _Symbol;
}
if (_WeakMap) { if (_WeakMap) {
WeakMap = _WeakMap; WeakMap = _WeakMap;
} else { } else {
@@ -157,6 +163,7 @@
setProperty(window, '_Map', undefined); setProperty(window, '_Map', undefined);
setProperty(window, '_Set', undefined); setProperty(window, '_Set', undefined);
setProperty(window, '_Symbol', undefined);
setProperty(window, '_WeakMap', undefined); setProperty(window, '_WeakMap', undefined);
setProperty(window, 'WinRTError', undefined); setProperty(window, 'WinRTError', undefined);

View File

@@ -461,6 +461,7 @@
setProperty(Object, 'getOwnPropertySymbols', undefined); setProperty(Object, 'getOwnPropertySymbols', undefined);
setProperty(root, 'Set', noop); setProperty(root, 'Set', noop);
setProperty(root, 'Symbol', undefined);
setProperty(root, 'WeakMap', noop); setProperty(root, 'WeakMap', noop);
// Fake `WinRTError`. // Fake `WinRTError`.
@@ -489,6 +490,11 @@
} else { } else {
delete root.Set; delete root.Set;
} }
if (Symbol) {
setProperty(root, 'Symbol', Symbol);
} else {
delete root.Symbol;
}
if (WeakMap) { if (WeakMap) {
setProperty(root, 'WeakMap', WeakMap); setProperty(root, 'WeakMap', WeakMap);
} else { } else {
@@ -700,7 +706,7 @@
}); });
QUnit.test('should avoid overwritten native methods', function(assert) { QUnit.test('should avoid overwritten native methods', function(assert) {
assert.expect(5); assert.expect(6);
function message(lodashMethod, nativeMethod) { function message(lodashMethod, nativeMethod) {
return '`' + lodashMethod + '` should avoid overwritten native `' + nativeMethod + '`'; return '`' + lodashMethod + '` should avoid overwritten native `' + nativeMethod + '`';
@@ -747,6 +753,18 @@
} }
assert.deepEqual(actual, [object, object], 'Object.getOwnPropertySymbols'); assert.deepEqual(actual, [object, object], 'Object.getOwnPropertySymbols');
try {
var symObject = Object(symbol);
actual = [
Symbol ? lodashBizarro.clone(symObject) : {},
Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
Symbol ? lodashBizarro.toString(symObject) : ''
];
} catch (e) {
actual = null;
}
assert.deepEqual(actual, [{}, false, ''], 'Symbol');
try { try {
var map = new lodashBizarro.memoize.Cache; var map = new lodashBizarro.memoize.Cache;
actual = map.set('a', 1).get('a'); actual = map.set('a', 1).get('a');
@@ -769,7 +787,7 @@
assert.deepEqual(actual, [], label); assert.deepEqual(actual, [], label);
} }
else { else {
skipTest(assert, 5); skipTest(assert, 6);
} }
}); });
}()); }());