"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/underscore/test/objects.js" between
lodash-4.0.0.tar.gz and lodash-4.17.21.tar.gz

About: lodash is a modern JavaScript utility library delivering modularity, performance, & extras. Tagged version.

objects.js  (lodash-4.0.0):objects.js  (lodash-4.17.21)
skipping to change at line 126 skipping to change at line 126
assert.deepEqual(result, {x: 2, a: 'b'}, 'extending from multiple source obj ects last property trumps'); assert.deepEqual(result, {x: 2, a: 'b'}, 'extending from multiple source obj ects last property trumps');
result = _.extend({}, {a: void 0, b: null}); result = _.extend({}, {a: void 0, b: null});
assert.deepEqual(_.keys(result), ['a', 'b'], 'extend copies undefined values '); assert.deepEqual(_.keys(result), ['a', 'b'], 'extend copies undefined values ');
var F = function() {}; var F = function() {};
F.prototype = {a: 'b'}; F.prototype = {a: 'b'};
var subObj = new F(); var subObj = new F();
subObj.c = 'd'; subObj.c = 'd';
assert.deepEqual(_.extend({}, subObj), {a: 'b', c: 'd'}, 'extend copies all properties from source'); assert.deepEqual(_.extend({}, subObj), {a: 'b', c: 'd'}, 'extend copies all properties from source');
_.extend(subObj, {}); _.extend(subObj, {});
assert.ok(!subObj.hasOwnProperty('a'), "extend does not convert destination object's 'in' properties to 'own' properties"); assert.notOk(subObj.hasOwnProperty('a'), "extend does not convert destinatio n object's 'in' properties to 'own' properties");
try { try {
result = {}; result = {};
_.extend(result, null, void 0, {a: 1}); _.extend(result, null, void 0, {a: 1});
} catch (e) { /* ignored */ } } catch (e) { /* ignored */ }
assert.equal(result.a, 1, 'should not error on `null` or `undefined` sources '); assert.equal(result.a, 1, 'should not error on `null` or `undefined` sources ');
assert.strictEqual(_.extend(null, {a: 1}), null, 'extending null results in null'); assert.strictEqual(_.extend(null, {a: 1}), null, 'extending null results in null');
assert.strictEqual(_.extend(void 0, {a: 1}), void 0, 'extending undefined re sults in undefined'); assert.strictEqual(_.extend(void 0, {a: 1}), void 0, 'extending undefined re sults in undefined');
skipping to change at line 208 skipping to change at line 208
var Obj = function(){}; var Obj = function(){};
Obj.prototype = {a: 1, b: 2, c: 3}; Obj.prototype = {a: 1, b: 2, c: 3};
var instance = new Obj(); var instance = new Obj();
assert.deepEqual(_.pick(instance, 'a', 'c'), {a: 1, c: 3}, 'include prototyp e props'); assert.deepEqual(_.pick(instance, 'a', 'c'), {a: 1, c: 3}, 'include prototyp e props');
assert.deepEqual(_.pick(data, function(val, key) { assert.deepEqual(_.pick(data, function(val, key) {
return this[key] === 3 && this === instance; return this[key] === 3 && this === instance;
}, instance), {c: 3}, 'function is given context'); }, instance), {c: 3}, 'function is given context');
assert.ok(!_.has(_.pick({}, 'foo'), 'foo'), 'does not set own property if pr operty not in object'); assert.notOk(_.has(_.pick({}, 'foo'), 'foo'), 'does not set own property if property not in object');
_.pick(data, function(value, key, obj) { _.pick(data, function(value, key, obj) {
assert.equal(obj, data, 'passes same object as third parameter of iteratee '); assert.equal(obj, data, 'passes same object as third parameter of iteratee ');
}); });
}); });
QUnit.test('omit', function(assert) { QUnit.test('omit', function(assert) {
var result; var result;
result = _.omit({a: 1, b: 2, c: 3}, 'b'); result = _.omit({a: 1, b: 2, c: 3}, 'b');
assert.deepEqual(result, {a: 1, c: 3}, 'can omit a single named property'); assert.deepEqual(result, {a: 1, c: 3}, 'can omit a single named property');
result = _.omit({a: 1, b: 2, c: 3}, 'a', 'c'); result = _.omit({a: 1, b: 2, c: 3}, 'a', 'c');
skipping to change at line 312 skipping to change at line 312
var func = function() {}; var func = function() {};
Child.prototype = _.create(Parent.prototype, {func: func}); Child.prototype = _.create(Parent.prototype, {func: func});
assert.strictEqual(Child.prototype.func, func, 'properties should be added t o object'); assert.strictEqual(Child.prototype.func, func, 'properties should be added t o object');
Child.prototype = _.create(Parent.prototype, {constructor: Child}); Child.prototype = _.create(Parent.prototype, {constructor: Child});
assert.strictEqual(Child.prototype.constructor, Child); assert.strictEqual(Child.prototype.constructor, Child);
Child.prototype.foo = 'foo'; Child.prototype.foo = 'foo';
var created = _.create(Child.prototype, new Child); var created = _.create(Child.prototype, new Child);
assert.ok(!created.hasOwnProperty('foo'), 'should only add own properties'); assert.notOk(created.hasOwnProperty('foo'), 'should only add own properties' );
}); });
QUnit.test('isEqual', function(assert) { QUnit.test('isEqual', function(assert) {
function First() { function First() {
this.value = 1; this.value = 1;
} }
First.prototype.value = 1; First.prototype.value = 1;
function Second() { function Second() {
this.value = 1; this.value = 1;
} }
Second.prototype.value = 2; Second.prototype.value = 2;
// Basic equality and identity comparisons. // Basic equality and identity comparisons.
assert.ok(_.isEqual(null, null), '`null` is equal to `null`'); assert.ok(_.isEqual(null, null), '`null` is equal to `null`');
assert.ok(_.isEqual(), '`undefined` is equal to `undefined`'); assert.ok(_.isEqual(), '`undefined` is equal to `undefined`');
assert.ok(!_.isEqual(0, -0), '`0` is not equal to `-0`'); assert.notOk(_.isEqual(0, -0), '`0` is not equal to `-0`');
assert.ok(!_.isEqual(-0, 0), 'Commutative equality is implemented for `0` an assert.notOk(_.isEqual(-0, 0), 'Commutative equality is implemented for `0`
d `-0`'); and `-0`');
assert.ok(!_.isEqual(null, void 0), '`null` is not equal to `undefined`'); assert.notOk(_.isEqual(null, void 0), '`null` is not equal to `undefined`');
assert.ok(!_.isEqual(void 0, null), 'Commutative equality is implemented for assert.notOk(_.isEqual(void 0, null), 'Commutative equality is implemented f
`null` and `undefined`'); or `null` and `undefined`');
// String object and primitive comparisons. // String object and primitive comparisons.
assert.ok(_.isEqual('Curly', 'Curly'), 'Identical string primitives are equa l'); assert.ok(_.isEqual('Curly', 'Curly'), 'Identical string primitives are equa l');
assert.ok(_.isEqual(new String('Curly'), new String('Curly')), 'String objec ts with identical primitive values are equal'); assert.ok(_.isEqual(new String('Curly'), new String('Curly')), 'String objec ts with identical primitive values are equal');
assert.ok(_.isEqual(new String('Curly'), 'Curly'), 'String primitives and th eir corresponding object wrappers are equal'); assert.ok(_.isEqual(new String('Curly'), 'Curly'), 'String primitives and th eir corresponding object wrappers are equal');
assert.ok(_.isEqual('Curly', new String('Curly')), 'Commutative equality is implemented for string objects and primitives'); assert.ok(_.isEqual('Curly', new String('Curly')), 'Commutative equality is implemented for string objects and primitives');
assert.ok(!_.isEqual('Curly', 'Larry'), 'String primitives with different va assert.notOk(_.isEqual('Curly', 'Larry'), 'String primitives with different
lues are not equal'); values are not equal');
assert.ok(!_.isEqual(new String('Curly'), new String('Larry')), 'String obje assert.notOk(_.isEqual(new String('Curly'), new String('Larry')), 'String ob
cts with different primitive values are not equal'); jects with different primitive values are not equal');
assert.ok(!_.isEqual(new String('Curly'), {toString: function(){ return 'Cur assert.notOk(_.isEqual(new String('Curly'), {toString: function(){ return 'C
ly'; }}), 'String objects and objects with a custom `toString` method are not eq urly'; }}), 'String objects and objects with a custom `toString` method are not
ual'); equal');
// Number object and primitive comparisons. // Number object and primitive comparisons.
assert.ok(_.isEqual(75, 75), 'Identical number primitives are equal'); assert.ok(_.isEqual(75, 75), 'Identical number primitives are equal');
assert.ok(_.isEqual(new Number(75), new Number(75)), 'Number objects with id entical primitive values are equal'); assert.ok(_.isEqual(new Number(75), new Number(75)), 'Number objects with id entical primitive values are equal');
assert.ok(_.isEqual(75, new Number(75)), 'Number primitives and their corres ponding object wrappers are equal'); assert.ok(_.isEqual(75, new Number(75)), 'Number primitives and their corres ponding object wrappers are equal');
assert.ok(_.isEqual(new Number(75), 75), 'Commutative equality is implemente d for number objects and primitives'); assert.ok(_.isEqual(new Number(75), 75), 'Commutative equality is implemente d for number objects and primitives');
assert.ok(!_.isEqual(new Number(0), -0), '`new Number(0)` and `-0` are not e assert.notOk(_.isEqual(new Number(0), -0), '`new Number(0)` and `-0` are not
qual'); equal');
assert.ok(!_.isEqual(0, new Number(-0)), 'Commutative equality is implemente assert.notOk(_.isEqual(0, new Number(-0)), 'Commutative equality is implemen
d for `new Number(0)` and `-0`'); ted for `new Number(0)` and `-0`');
assert.ok(!_.isEqual(new Number(75), new Number(63)), 'Number objects with d assert.notOk(_.isEqual(new Number(75), new Number(63)), 'Number objects with
ifferent primitive values are not equal'); different primitive values are not equal');
assert.ok(!_.isEqual(new Number(63), {valueOf: function(){ return 63; }}), ' assert.notOk(_.isEqual(new Number(63), {valueOf: function(){ return 63; }}),
Number objects and objects with a `valueOf` method are not equal'); 'Number objects and objects with a `valueOf` method are not equal');
// Comparisons involving `NaN`. // Comparisons involving `NaN`.
assert.ok(_.isEqual(NaN, NaN), '`NaN` is equal to `NaN`'); assert.ok(_.isEqual(NaN, NaN), '`NaN` is equal to `NaN`');
assert.ok(_.isEqual(new Number(NaN), NaN), 'Object(`NaN`) is equal to `NaN`' ); assert.ok(_.isEqual(new Number(NaN), NaN), 'Object(`NaN`) is equal to `NaN`' );
assert.ok(!_.isEqual(61, NaN), 'A number primitive is not equal to `NaN`'); assert.notOk(_.isEqual(61, NaN), 'A number primitive is not equal to `NaN`')
assert.ok(!_.isEqual(new Number(79), NaN), 'A number object is not equal to ;
`NaN`'); assert.notOk(_.isEqual(new Number(79), NaN), 'A number object is not equal t
assert.ok(!_.isEqual(Infinity, NaN), '`Infinity` is not equal to `NaN`'); o `NaN`');
assert.notOk(_.isEqual(Infinity, NaN), '`Infinity` is not equal to `NaN`');
// Boolean object and primitive comparisons. // Boolean object and primitive comparisons.
assert.ok(_.isEqual(true, true), 'Identical boolean primitives are equal'); assert.ok(_.isEqual(true, true), 'Identical boolean primitives are equal');
assert.ok(_.isEqual(new Boolean, new Boolean), 'Boolean objects with identic al primitive values are equal'); assert.ok(_.isEqual(new Boolean, new Boolean), 'Boolean objects with identic al primitive values are equal');
assert.ok(_.isEqual(true, new Boolean(true)), 'Boolean primitives and their corresponding object wrappers are equal'); assert.ok(_.isEqual(true, new Boolean(true)), 'Boolean primitives and their corresponding object wrappers are equal');
assert.ok(_.isEqual(new Boolean(true), true), 'Commutative equality is imple mented for booleans'); assert.ok(_.isEqual(new Boolean(true), true), 'Commutative equality is imple mented for booleans');
assert.ok(!_.isEqual(new Boolean(true), new Boolean), 'Boolean objects with different primitive values are not equal'); assert.notOk(_.isEqual(new Boolean(true), new Boolean), 'Boolean objects wit h different primitive values are not equal');
// Common type coercions. // Common type coercions.
assert.ok(!_.isEqual(new Boolean(false), true), '`new Boolean(false)` is not assert.notOk(_.isEqual(new Boolean(false), true), '`new Boolean(false)` is n
equal to `true`'); ot equal to `true`');
assert.ok(!_.isEqual('75', 75), 'String and number primitives with like valu assert.notOk(_.isEqual('75', 75), 'String and number primitives with like va
es are not equal'); lues are not equal');
assert.ok(!_.isEqual(new Number(63), new String(63)), 'String and number obj assert.notOk(_.isEqual(new Number(63), new String(63)), 'String and number o
ects with like values are not equal'); bjects with like values are not equal');
assert.ok(!_.isEqual(75, '75'), 'Commutative equality is implemented for lik assert.notOk(_.isEqual(75, '75'), 'Commutative equality is implemented for l
e string and number values'); ike string and number values');
assert.ok(!_.isEqual(0, ''), 'Number and string primitives with like values assert.notOk(_.isEqual(0, ''), 'Number and string primitives with like value
are not equal'); s are not equal');
assert.ok(!_.isEqual(1, true), 'Number and boolean primitives with like valu assert.notOk(_.isEqual(1, true), 'Number and boolean primitives with like va
es are not equal'); lues are not equal');
assert.ok(!_.isEqual(new Boolean(false), new Number(0)), 'Boolean and number assert.notOk(_.isEqual(new Boolean(false), new Number(0)), 'Boolean and numb
objects with like values are not equal'); er objects with like values are not equal');
assert.ok(!_.isEqual(false, new String('')), 'Boolean primitives and string assert.notOk(_.isEqual(false, new String('')), 'Boolean primitives and strin
objects with like values are not equal'); g objects with like values are not equal');
assert.ok(!_.isEqual(12564504e5, new Date(2009, 9, 25)), 'Dates and their co assert.notOk(_.isEqual(12564504e5, new Date(2009, 9, 25)), 'Dates and their
rresponding numeric primitive values are not equal'); corresponding numeric primitive values are not equal');
// Dates. // Dates.
assert.ok(_.isEqual(new Date(2009, 9, 25), new Date(2009, 9, 25)), 'Date obj ects referencing identical times are equal'); assert.ok(_.isEqual(new Date(2009, 9, 25), new Date(2009, 9, 25)), 'Date obj ects referencing identical times are equal');
assert.ok(!_.isEqual(new Date(2009, 9, 25), new Date(2009, 11, 13)), 'Date o assert.notOk(_.isEqual(new Date(2009, 9, 25), new Date(2009, 11, 13)), 'Date
bjects referencing different times are not equal'); objects referencing different times are not equal');
assert.ok(!_.isEqual(new Date(2009, 11, 13), { assert.notOk(_.isEqual(new Date(2009, 11, 13), {
getTime: function(){ getTime: function(){
return 12606876e5; return 12606876e5;
} }
}), 'Date objects and objects with a `getTime` method are not equal'); }), 'Date objects and objects with a `getTime` method are not equal');
assert.ok(!_.isEqual(new Date('Curly'), new Date('Curly')), 'Invalid dates a re not equal'); assert.notOk(_.isEqual(new Date('Curly'), new Date('Curly')), 'Invalid dates are not equal');
// Functions. // Functions.
assert.ok(!_.isEqual(First, Second), 'Different functions with identical bod ies and source code representations are not equal'); assert.notOk(_.isEqual(First, Second), 'Different functions with identical b odies and source code representations are not equal');
// RegExps. // RegExps.
assert.ok(_.isEqual(/(?:)/gim, /(?:)/gim), 'RegExps with equivalent patterns and flags are equal'); assert.ok(_.isEqual(/(?:)/gim, /(?:)/gim), 'RegExps with equivalent patterns and flags are equal');
assert.ok(_.isEqual(/(?:)/gi, /(?:)/ig), 'Flag order is not significant'); assert.ok(_.isEqual(/(?:)/gi, /(?:)/ig), 'Flag order is not significant');
assert.ok(!_.isEqual(/(?:)/g, /(?:)/gi), 'RegExps with equivalent patterns a assert.notOk(_.isEqual(/(?:)/g, /(?:)/gi), 'RegExps with equivalent patterns
nd different flags are not equal'); and different flags are not equal');
assert.ok(!_.isEqual(/Moe/gim, /Curly/gim), 'RegExps with different patterns assert.notOk(_.isEqual(/Moe/gim, /Curly/gim), 'RegExps with different patter
and equivalent flags are not equal'); ns and equivalent flags are not equal');
assert.ok(!_.isEqual(/(?:)/gi, /(?:)/g), 'Commutative equality is implemente assert.notOk(_.isEqual(/(?:)/gi, /(?:)/g), 'Commutative equality is implemen
d for RegExps'); ted for RegExps');
assert.ok(!_.isEqual(/Curly/g, {source: 'Larry', global: true, ignoreCase: f assert.notOk(_.isEqual(/Curly/g, {source: 'Larry', global: true, ignoreCase:
alse, multiline: false}), 'RegExps and RegExp-like objects are not equal'); false, multiline: false}), 'RegExps and RegExp-like objects are not equal');
// Empty arrays, array-like objects, and object literals. // Empty arrays, array-like objects, and object literals.
assert.ok(_.isEqual({}, {}), 'Empty object literals are equal'); assert.ok(_.isEqual({}, {}), 'Empty object literals are equal');
assert.ok(_.isEqual([], []), 'Empty array literals are equal'); assert.ok(_.isEqual([], []), 'Empty array literals are equal');
assert.ok(_.isEqual([{}], [{}]), 'Empty nested arrays and objects are equal' ); assert.ok(_.isEqual([{}], [{}]), 'Empty nested arrays and objects are equal' );
assert.ok(!_.isEqual({length: 0}, []), 'Array-like objects and arrays are no assert.notOk(_.isEqual({length: 0}, []), 'Array-like objects and arrays are
t equal.'); not equal.');
assert.ok(!_.isEqual([], {length: 0}), 'Commutative equality is implemented assert.notOk(_.isEqual([], {length: 0}), 'Commutative equality is implemente
for array-like objects'); d for array-like objects');
assert.ok(!_.isEqual({}, []), 'Object literals and array literals are not eq assert.notOk(_.isEqual({}, []), 'Object literals and array literals are not
ual'); equal');
assert.ok(!_.isEqual([], {}), 'Commutative equality is implemented for objec assert.notOk(_.isEqual([], {}), 'Commutative equality is implemented for obj
ts and arrays'); ects and arrays');
// Arrays with primitive and object values. // Arrays with primitive and object values.
assert.ok(_.isEqual([1, 'Larry', true], [1, 'Larry', true]), 'Arrays contain ing identical primitives are equal'); assert.ok(_.isEqual([1, 'Larry', true], [1, 'Larry', true]), 'Arrays contain ing identical primitives are equal');
assert.ok(_.isEqual([/Moe/g, new Date(2009, 9, 25)], [/Moe/g, new Date(2009, 9, 25)]), 'Arrays containing equivalent elements are equal'); assert.ok(_.isEqual([/Moe/g, new Date(2009, 9, 25)], [/Moe/g, new Date(2009, 9, 25)]), 'Arrays containing equivalent elements are equal');
// Multi-dimensional arrays. // Multi-dimensional arrays.
var a = [new Number(47), false, 'Larry', /Moe/, new Date(2009, 11, 13), ['ru nning', 'biking', new String('programming')], {a: 47}]; var a = [new Number(47), false, 'Larry', /Moe/, new Date(2009, 11, 13), ['ru nning', 'biking', new String('programming')], {a: 47}];
var b = [new Number(47), false, 'Larry', /Moe/, new Date(2009, 11, 13), ['ru nning', 'biking', new String('programming')], {a: 47}]; var b = [new Number(47), false, 'Larry', /Moe/, new Date(2009, 11, 13), ['ru nning', 'biking', new String('programming')], {a: 47}];
assert.ok(_.isEqual(a, b), 'Arrays containing nested arrays and objects are recursively compared'); assert.ok(_.isEqual(a, b), 'Arrays containing nested arrays and objects are recursively compared');
// Overwrite the methods defined in ES 5.1 section 15.4.4. // Overwrite the methods defined in ES 5.1 section 15.4.4.
a.forEach = a.map = a.filter = a.every = a.indexOf = a.lastIndexOf = a.some = a.reduce = a.reduceRight = null; a.forEach = a.map = a.filter = a.every = a.indexOf = a.lastIndexOf = a.some = a.reduce = a.reduceRight = null;
b.join = b.pop = b.reverse = b.shift = b.slice = b.splice = b.concat = b.sor t = b.unshift = null; b.join = b.pop = b.reverse = b.shift = b.slice = b.splice = b.concat = b.sor t = b.unshift = null;
// Array elements and properties. // Array elements and properties.
assert.ok(_.isEqual(a, b), 'Arrays containing equivalent elements and differ ent non-numeric properties are equal'); assert.ok(_.isEqual(a, b), 'Arrays containing equivalent elements and differ ent non-numeric properties are equal');
a.push('White Rocks'); a.push('White Rocks');
assert.ok(!_.isEqual(a, b), 'Arrays of different lengths are not equal'); assert.notOk(_.isEqual(a, b), 'Arrays of different lengths are not equal');
a.push('East Boulder'); a.push('East Boulder');
b.push('Gunbarrel Ranch', 'Teller Farm'); b.push('Gunbarrel Ranch', 'Teller Farm');
assert.ok(!_.isEqual(a, b), 'Arrays of identical lengths containing differen t elements are not equal'); assert.notOk(_.isEqual(a, b), 'Arrays of identical lengths containing differ ent elements are not equal');
// Sparse arrays. // Sparse arrays.
assert.ok(_.isEqual(Array(3), Array(3)), 'Sparse arrays of identical lengths are equal'); assert.ok(_.isEqual(Array(3), Array(3)), 'Sparse arrays of identical lengths are equal');
assert.ok(!_.isEqual(Array(3), Array(6)), 'Sparse arrays of different length s are not equal when both are empty'); assert.notOk(_.isEqual(Array(3), Array(6)), 'Sparse arrays of different leng ths are not equal when both are empty');
var sparse = []; var sparse = [];
sparse[1] = 5; sparse[1] = 5;
assert.ok(_.isEqual(sparse, [void 0, 5]), 'Handles sparse arrays as dense'); assert.ok(_.isEqual(sparse, [void 0, 5]), 'Handles sparse arrays as dense');
// Simple objects. // Simple objects.
assert.ok(_.isEqual({a: 'Curly', b: 1, c: true}, {a: 'Curly', b: 1, c: true} ), 'Objects containing identical primitives are equal'); assert.ok(_.isEqual({a: 'Curly', b: 1, c: true}, {a: 'Curly', b: 1, c: true} ), 'Objects containing identical primitives are equal');
assert.ok(_.isEqual({a: /Curly/g, b: new Date(2009, 11, 13)}, {a: /Curly/g, b: new Date(2009, 11, 13)}), 'Objects containing equivalent members are equal'); assert.ok(_.isEqual({a: /Curly/g, b: new Date(2009, 11, 13)}, {a: /Curly/g, b: new Date(2009, 11, 13)}), 'Objects containing equivalent members are equal');
assert.ok(!_.isEqual({a: 63, b: 75}, {a: 61, b: 55}), 'Objects of identical assert.notOk(_.isEqual({a: 63, b: 75}, {a: 61, b: 55}), 'Objects of identica
sizes with different values are not equal'); l sizes with different values are not equal');
assert.ok(!_.isEqual({a: 63, b: 75}, {a: 61, c: 55}), 'Objects of identical assert.notOk(_.isEqual({a: 63, b: 75}, {a: 61, c: 55}), 'Objects of identica
sizes with different property names are not equal'); l sizes with different property names are not equal');
assert.ok(!_.isEqual({a: 1, b: 2}, {a: 1}), 'Objects of different sizes are assert.notOk(_.isEqual({a: 1, b: 2}, {a: 1}), 'Objects of different sizes ar
not equal'); e not equal');
assert.ok(!_.isEqual({a: 1}, {a: 1, b: 2}), 'Commutative equality is impleme assert.notOk(_.isEqual({a: 1}, {a: 1, b: 2}), 'Commutative equality is imple
nted for objects'); mented for objects');
assert.ok(!_.isEqual({x: 1, y: void 0}, {x: 1, z: 2}), 'Objects with identic assert.notOk(_.isEqual({x: 1, y: void 0}, {x: 1, z: 2}), 'Objects with ident
al keys and different values are not equivalent'); ical keys and different values are not equivalent');
// `A` contains nested objects and arrays. // `A` contains nested objects and arrays.
a = { a = {
name: new String('Moe Howard'), name: new String('Moe Howard'),
age: new Number(77), age: new Number(77),
stooge: true, stooge: true,
hobbies: ['acting'], hobbies: ['acting'],
film: { film: {
name: 'Sing a Song of Six Pants', name: 'Sing a Song of Six Pants',
release: new Date(1947, 9, 30), release: new Date(1947, 9, 30),
skipping to change at line 482 skipping to change at line 482
release: new Date(1947, 9, 30), release: new Date(1947, 9, 30),
stars: [new String('Larry Fine'), 'Shemp Howard'], stars: [new String('Larry Fine'), 'Shemp Howard'],
minutes: new Number(16), minutes: new Number(16),
seconds: 54 seconds: 54
} }
}; };
assert.ok(_.isEqual(a, b), 'Objects with nested equivalent members are recur sively compared'); assert.ok(_.isEqual(a, b), 'Objects with nested equivalent members are recur sively compared');
// Instances. // Instances.
assert.ok(_.isEqual(new First, new First), 'Object instances are equal'); assert.ok(_.isEqual(new First, new First), 'Object instances are equal');
assert.ok(!_.isEqual(new First, new Second), 'Objects with different constru assert.notOk(_.isEqual(new First, new Second), 'Objects with different const
ctors and identical own properties are not equal'); ructors and identical own properties are not equal');
assert.ok(!_.isEqual({value: 1}, new First), 'Object instances and objects s assert.notOk(_.isEqual({value: 1}, new First), 'Object instances and objects
haring equivalent properties are not equal'); sharing equivalent properties are not equal');
assert.ok(!_.isEqual({value: 2}, new Second), 'The prototype chain of object assert.notOk(_.isEqual({value: 2}, new Second), 'The prototype chain of obje
s should not be examined'); cts should not be examined');
// Circular Arrays. // Circular Arrays.
(a = []).push(a); (a = []).push(a);
(b = []).push(b); (b = []).push(b);
assert.ok(_.isEqual(a, b), 'Arrays containing circular references are equal' ); assert.ok(_.isEqual(a, b), 'Arrays containing circular references are equal' );
a.push(new String('Larry')); a.push(new String('Larry'));
b.push(new String('Larry')); b.push(new String('Larry'));
assert.ok(_.isEqual(a, b), 'Arrays containing circular references and equiva lent properties are equal'); assert.ok(_.isEqual(a, b), 'Arrays containing circular references and equiva lent properties are equal');
a.push('Shemp'); a.push('Shemp');
b.push('Curly'); b.push('Curly');
assert.ok(!_.isEqual(a, b), 'Arrays containing circular references and diffe rent properties are not equal'); assert.notOk(_.isEqual(a, b), 'Arrays containing circular references and dif ferent properties are not equal');
// More circular arrays #767. // More circular arrays #767.
a = ['everything is checked but', 'this', 'is not']; a = ['everything is checked but', 'this', 'is not'];
a[1] = a; a[1] = a;
b = ['everything is checked but', ['this', 'array'], 'is not']; b = ['everything is checked but', ['this', 'array'], 'is not'];
assert.ok(!_.isEqual(a, b), 'Comparison of circular references with non-circ ular references are not equal'); assert.notOk(_.isEqual(a, b), 'Comparison of circular references with non-ci rcular references are not equal');
// Circular Objects. // Circular Objects.
a = {abc: null}; a = {abc: null};
b = {abc: null}; b = {abc: null};
a.abc = a; a.abc = a;
b.abc = b; b.abc = b;
assert.ok(_.isEqual(a, b), 'Objects containing circular references are equal '); assert.ok(_.isEqual(a, b), 'Objects containing circular references are equal ');
a.def = 75; a.def = 75;
b.def = 75; b.def = 75;
assert.ok(_.isEqual(a, b), 'Objects containing circular references and equiv alent properties are equal'); assert.ok(_.isEqual(a, b), 'Objects containing circular references and equiv alent properties are equal');
a.def = new Number(75); a.def = new Number(75);
b.def = new Number(63); b.def = new Number(63);
assert.ok(!_.isEqual(a, b), 'Objects containing circular references and diff erent properties are not equal'); assert.notOk(_.isEqual(a, b), 'Objects containing circular references and di fferent properties are not equal');
// More circular objects #767. // More circular objects #767.
a = {everything: 'is checked', but: 'this', is: 'not'}; a = {everything: 'is checked', but: 'this', is: 'not'};
a.but = a; a.but = a;
b = {everything: 'is checked', but: {that: 'object'}, is: 'not'}; b = {everything: 'is checked', but: {that: 'object'}, is: 'not'};
assert.ok(!_.isEqual(a, b), 'Comparison of circular references with non-circ ular object references are not equal'); assert.notOk(_.isEqual(a, b), 'Comparison of circular references with non-ci rcular object references are not equal');
// Cyclic Structures. // Cyclic Structures.
a = [{abc: null}]; a = [{abc: null}];
b = [{abc: null}]; b = [{abc: null}];
(a[0].abc = a).push(a); (a[0].abc = a).push(a);
(b[0].abc = b).push(b); (b[0].abc = b).push(b);
assert.ok(_.isEqual(a, b), 'Cyclic structures are equal'); assert.ok(_.isEqual(a, b), 'Cyclic structures are equal');
a[0].def = 'Larry'; a[0].def = 'Larry';
b[0].def = 'Larry'; b[0].def = 'Larry';
assert.ok(_.isEqual(a, b), 'Cyclic structures containing equivalent properti es are equal'); assert.ok(_.isEqual(a, b), 'Cyclic structures containing equivalent properti es are equal');
a[0].def = new String('Larry'); a[0].def = new String('Larry');
b[0].def = new String('Curly'); b[0].def = new String('Curly');
assert.ok(!_.isEqual(a, b), 'Cyclic structures containing different properti es are not equal'); assert.notOk(_.isEqual(a, b), 'Cyclic structures containing different proper ties are not equal');
// Complex Circular References. // Complex Circular References.
a = {foo: {b: {foo: {c: {foo: null}}}}}; a = {foo: {b: {foo: {c: {foo: null}}}}};
b = {foo: {b: {foo: {c: {foo: null}}}}}; b = {foo: {b: {foo: {c: {foo: null}}}}};
a.foo.b.foo.c.foo = a; a.foo.b.foo.c.foo = a;
b.foo.b.foo.c.foo = b; b.foo.b.foo.c.foo = b;
assert.ok(_.isEqual(a, b), 'Cyclic structures with nested and identically-na med properties are equal'); assert.ok(_.isEqual(a, b), 'Cyclic structures with nested and identically-na med properties are equal');
// Chaining. // Chaining.
assert.ok(!_.isEqual(_({x: 1, y: void 0}).chain(), _({x: 1, z: 2}).chain()), 'Chained objects containing different values are not equal'); assert.notOk(_.isEqual(_({x: 1, y: void 0}).chain(), _({x: 1, z: 2}).chain() ), 'Chained objects containing different values are not equal');
a = _({x: 1, y: 2}).chain(); a = _({x: 1, y: 2}).chain();
b = _({x: 1, y: 2}).chain(); b = _({x: 1, y: 2}).chain();
assert.equal(_.isEqual(a.isEqual(b), _(true)), true, '`isEqual` can be chain ed'); assert.equal(_.isEqual(a.isEqual(b), _(true)), true, '`isEqual` can be chain ed');
// Objects without a `constructor` property // Objects without a `constructor` property
if (Object.create) { if (Object.create) {
a = Object.create(null, {x: {value: 1, enumerable: true}}); a = Object.create(null, {x: {value: 1, enumerable: true}});
b = {x: 1}; b = {x: 1};
assert.ok(_.isEqual(a, b), 'Handles objects without a constructor (e.g. fr om Object.create'); assert.ok(_.isEqual(a, b), 'Handles objects without a constructor (e.g. fr om Object.create');
skipping to change at line 567 skipping to change at line 567
Foo.prototype.constructor = null; Foo.prototype.constructor = null;
var other = {a: 1}; var other = {a: 1};
assert.strictEqual(_.isEqual(new Foo, other), false, 'Objects from different constructors are not equal'); assert.strictEqual(_.isEqual(new Foo, other), false, 'Objects from different constructors are not equal');
// Tricky object cases val comparisions // Tricky object cases val comparisions
assert.equal(_.isEqual([0], [-0]), false); assert.equal(_.isEqual([0], [-0]), false);
assert.equal(_.isEqual({a: 0}, {a: -0}), false); assert.equal(_.isEqual({a: 0}, {a: -0}), false);
assert.equal(_.isEqual([NaN], [NaN]), true); assert.equal(_.isEqual([NaN], [NaN]), true);
assert.equal(_.isEqual({a: NaN}, {a: NaN}), true); assert.equal(_.isEqual({a: NaN}, {a: NaN}), true);
if (typeof Symbol !== 'undefined') {
var symbol = Symbol('x');
assert.strictEqual(_.isEqual(symbol, symbol), true, 'A symbol is equal to
itself');
assert.strictEqual(_.isEqual(symbol, Object(symbol)), true, 'Even when wra
pped in Object()');
assert.strictEqual(_.isEqual(symbol, null), false, 'Different types are no
t equal');
}
}); });
QUnit.test('isEmpty', function(assert) { QUnit.test('isEmpty', function(assert) {
assert.ok(!_([1]).isEmpty(), '[1] is not empty'); assert.notOk(_([1]).isEmpty(), '[1] is not empty');
assert.ok(_.isEmpty([]), '[] is empty'); assert.ok(_.isEmpty([]), '[] is empty');
assert.ok(!_.isEmpty({one: 1}), '{one: 1} is not empty'); assert.notOk(_.isEmpty({one: 1}), '{one: 1} is not empty');
assert.ok(_.isEmpty({}), '{} is empty'); assert.ok(_.isEmpty({}), '{} is empty');
assert.ok(_.isEmpty(new RegExp('')), 'objects with prototype properties are empty'); assert.ok(_.isEmpty(new RegExp('')), 'objects with prototype properties are empty');
assert.ok(_.isEmpty(null), 'null is empty'); assert.ok(_.isEmpty(null), 'null is empty');
assert.ok(_.isEmpty(), 'undefined is empty'); assert.ok(_.isEmpty(), 'undefined is empty');
assert.ok(_.isEmpty(''), 'the empty string is empty'); assert.ok(_.isEmpty(''), 'the empty string is empty');
assert.ok(!_.isEmpty('moe'), 'but other strings are not'); assert.notOk(_.isEmpty('moe'), 'but other strings are not');
var obj = {one: 1}; var obj = {one: 1};
delete obj.one; delete obj.one;
assert.ok(_.isEmpty(obj), 'deleting all the keys from an object empties it') ; assert.ok(_.isEmpty(obj), 'deleting all the keys from an object empties it') ;
var args = function(){ return arguments; }; var args = function(){ return arguments; };
assert.ok(_.isEmpty(args()), 'empty arguments object is empty'); assert.ok(_.isEmpty(args()), 'empty arguments object is empty');
assert.ok(!_.isEmpty(args('')), 'non-empty arguments object is not empty'); assert.notOk(_.isEmpty(args('')), 'non-empty arguments object is not empty') ;
// covers collecting non-enumerable properties in IE < 9 // covers collecting non-enumerable properties in IE < 9
var nonEnumProp = {toString: 5}; var nonEnumProp = {toString: 5};
assert.ok(!_.isEmpty(nonEnumProp), 'non-enumerable property is not empty'); assert.notOk(_.isEmpty(nonEnumProp), 'non-enumerable property is not empty') ;
}); });
if (typeof document === 'object') { if (typeof document === 'object') {
QUnit.test('isElement', function(assert) { QUnit.test('isElement', function(assert) {
assert.ok(!_.isElement('div'), 'strings are not dom elements'); assert.notOk(_.isElement('div'), 'strings are not dom elements');
assert.ok(_.isElement(testElement), 'an element is a DOM element'); assert.ok(_.isElement(testElement), 'an element is a DOM element');
}); });
} }
QUnit.test('isArguments', function(assert) { QUnit.test('isArguments', function(assert) {
var args = (function(){ return arguments; }(1, 2, 3)); var args = (function(){ return arguments; }(1, 2, 3));
assert.ok(!_.isArguments('string'), 'a string is not an arguments object'); assert.notOk(_.isArguments('string'), 'a string is not an arguments object')
assert.ok(!_.isArguments(_.isArguments), 'a function is not an arguments obj ;
ect'); assert.notOk(_.isArguments(_.isArguments), 'a function is not an arguments o
bject');
assert.ok(_.isArguments(args), 'but the arguments object is an arguments obj ect'); assert.ok(_.isArguments(args), 'but the arguments object is an arguments obj ect');
assert.ok(!_.isArguments(_.toArray(args)), 'but not when it\'s converted int assert.notOk(_.isArguments(_.toArray(args)), 'but not when it\'s converted i
o an array'); nto an array');
assert.ok(!_.isArguments([1, 2, 3]), 'and not vanilla arrays.'); assert.notOk(_.isArguments([1, 2, 3]), 'and not vanilla arrays.');
}); });
QUnit.test('isObject', function(assert) { QUnit.test('isObject', function(assert) {
assert.ok(_.isObject(arguments), 'the arguments object is object'); assert.ok(_.isObject(arguments), 'the arguments object is object');
assert.ok(_.isObject([1, 2, 3]), 'and arrays'); assert.ok(_.isObject([1, 2, 3]), 'and arrays');
if (testElement) { if (testElement) {
assert.ok(_.isObject(testElement), 'and DOM element'); assert.ok(_.isObject(testElement), 'and DOM element');
} }
assert.ok(_.isObject(function() {}), 'and functions'); assert.ok(_.isObject(function() {}), 'and functions');
assert.ok(!_.isObject(null), 'but not null'); assert.notOk(_.isObject(null), 'but not null');
assert.ok(!_.isObject(void 0), 'and not undefined'); assert.notOk(_.isObject(void 0), 'and not undefined');
assert.ok(!_.isObject('string'), 'and not string'); assert.notOk(_.isObject('string'), 'and not string');
assert.ok(!_.isObject(12), 'and not number'); assert.notOk(_.isObject(12), 'and not number');
assert.ok(!_.isObject(true), 'and not boolean'); assert.notOk(_.isObject(true), 'and not boolean');
assert.ok(_.isObject(new String('string')), 'but new String()'); assert.ok(_.isObject(new String('string')), 'but new String()');
}); });
QUnit.test('isArray', function(assert) { QUnit.test('isArray', function(assert) {
assert.ok(!_.isArray(void 0), 'undefined vars are not arrays'); assert.notOk(_.isArray(void 0), 'undefined vars are not arrays');
assert.ok(!_.isArray(arguments), 'the arguments object is not an array'); assert.notOk(_.isArray(arguments), 'the arguments object is not an array');
assert.ok(_.isArray([1, 2, 3]), 'but arrays are'); assert.ok(_.isArray([1, 2, 3]), 'but arrays are');
}); });
QUnit.test('isString', function(assert) { QUnit.test('isString', function(assert) {
var obj = new String('I am a string object'); var obj = new String('I am a string object');
if (testElement) { if (testElement) {
assert.ok(!_.isString(testElement), 'an element is not a string'); assert.notOk(_.isString(testElement), 'an element is not a string');
} }
assert.ok(_.isString([1, 2, 3].join(', ')), 'but strings are'); assert.ok(_.isString([1, 2, 3].join(', ')), 'but strings are');
assert.strictEqual(_.isString('I am a string literal'), true, 'string litera ls are'); assert.strictEqual(_.isString('I am a string literal'), true, 'string litera ls are');
assert.ok(_.isString(obj), 'so are String objects'); assert.ok(_.isString(obj), 'so are String objects');
assert.strictEqual(_.isString(1), false); assert.strictEqual(_.isString(1), false);
}); });
QUnit.test('isSymbol', function(assert) {
assert.notOk(_.isSymbol(0), 'numbers are not symbols');
assert.notOk(_.isSymbol(''), 'strings are not symbols');
assert.notOk(_.isSymbol(_.isSymbol), 'functions are not symbols');
if (typeof Symbol === 'function') {
assert.ok(_.isSymbol(Symbol()), 'symbols are symbols');
assert.ok(_.isSymbol(Symbol('description')), 'described symbols are symbol
s');
assert.ok(_.isSymbol(Object(Symbol())), 'boxed symbols are symbols');
}
});
QUnit.test('isNumber', function(assert) { QUnit.test('isNumber', function(assert) {
assert.ok(!_.isNumber('string'), 'a string is not a number'); assert.notOk(_.isNumber('string'), 'a string is not a number');
assert.ok(!_.isNumber(arguments), 'the arguments object is not a number'); assert.notOk(_.isNumber(arguments), 'the arguments object is not a number');
assert.ok(!_.isNumber(void 0), 'undefined is not a number'); assert.notOk(_.isNumber(void 0), 'undefined is not a number');
assert.ok(_.isNumber(3 * 4 - 7 / 10), 'but numbers are'); assert.ok(_.isNumber(3 * 4 - 7 / 10), 'but numbers are');
assert.ok(_.isNumber(NaN), 'NaN *is* a number'); assert.ok(_.isNumber(NaN), 'NaN *is* a number');
assert.ok(_.isNumber(Infinity), 'Infinity is a number'); assert.ok(_.isNumber(Infinity), 'Infinity is a number');
assert.ok(!_.isNumber('1'), 'numeric strings are not numbers'); assert.notOk(_.isNumber('1'), 'numeric strings are not numbers');
}); });
QUnit.test('isBoolean', function(assert) { QUnit.test('isBoolean', function(assert) {
assert.ok(!_.isBoolean(2), 'a number is not a boolean'); assert.notOk(_.isBoolean(2), 'a number is not a boolean');
assert.ok(!_.isBoolean('string'), 'a string is not a boolean'); assert.notOk(_.isBoolean('string'), 'a string is not a boolean');
assert.ok(!_.isBoolean('false'), 'the string "false" is not a boolean'); assert.notOk(_.isBoolean('false'), 'the string "false" is not a boolean');
assert.ok(!_.isBoolean('true'), 'the string "true" is not a boolean'); assert.notOk(_.isBoolean('true'), 'the string "true" is not a boolean');
assert.ok(!_.isBoolean(arguments), 'the arguments object is not a boolean'); assert.notOk(_.isBoolean(arguments), 'the arguments object is not a boolean'
assert.ok(!_.isBoolean(void 0), 'undefined is not a boolean'); );
assert.ok(!_.isBoolean(NaN), 'NaN is not a boolean'); assert.notOk(_.isBoolean(void 0), 'undefined is not a boolean');
assert.ok(!_.isBoolean(null), 'null is not a boolean'); assert.notOk(_.isBoolean(NaN), 'NaN is not a boolean');
assert.notOk(_.isBoolean(null), 'null is not a boolean');
assert.ok(_.isBoolean(true), 'but true is'); assert.ok(_.isBoolean(true), 'but true is');
assert.ok(_.isBoolean(false), 'and so is false'); assert.ok(_.isBoolean(false), 'and so is false');
}); });
QUnit.test('isMap', function(assert) {
assert.notOk(_.isMap('string'), 'a string is not a map');
assert.notOk(_.isMap(2), 'a number is not a map');
assert.notOk(_.isMap({}), 'an object is not a map');
assert.notOk(_.isMap(false), 'a boolean is not a map');
assert.notOk(_.isMap(void 0), 'undefined is not a map');
assert.notOk(_.isMap([1, 2, 3]), 'an array is not a map');
if (typeof Set === 'function') {
assert.notOk(_.isMap(new Set()), 'a set is not a map');
}
if (typeof WeakSet === 'function') {
assert.notOk(_.isMap(new WeakSet()), 'a weakset is not a map');
}
if (typeof WeakMap === 'function') {
assert.notOk(_.isMap(new WeakMap()), 'a weakmap is not a map');
}
if (typeof Map === 'function') {
var keyString = 'a string';
var obj = new Map();
obj.set(keyString, 'value');
assert.ok(_.isMap(obj), 'but a map is');
}
});
QUnit.test('isWeakMap', function(assert) {
assert.notOk(_.isWeakMap('string'), 'a string is not a weakmap');
assert.notOk(_.isWeakMap(2), 'a number is not a weakmap');
assert.notOk(_.isWeakMap({}), 'an object is not a weakmap');
assert.notOk(_.isWeakMap(false), 'a boolean is not a weakmap');
assert.notOk(_.isWeakMap(void 0), 'undefined is not a weakmap');
assert.notOk(_.isWeakMap([1, 2, 3]), 'an array is not a weakmap');
if (typeof Set === 'function') {
assert.notOk(_.isWeakMap(new Set()), 'a set is not a weakmap');
}
if (typeof WeakSet === 'function') {
assert.notOk(_.isWeakMap(new WeakSet()), 'a weakset is not a weakmap');
}
if (typeof Map === 'function') {
assert.notOk(_.isWeakMap(new Map()), 'a map is not a weakmap');
}
if (typeof WeakMap === 'function') {
var keyObj = {}, obj = new WeakMap();
obj.set(keyObj, 'value');
assert.ok(_.isWeakMap(obj), 'but a weakmap is');
}
});
QUnit.test('isSet', function(assert) {
assert.notOk(_.isSet('string'), 'a string is not a set');
assert.notOk(_.isSet(2), 'a number is not a set');
assert.notOk(_.isSet({}), 'an object is not a set');
assert.notOk(_.isSet(false), 'a boolean is not a set');
assert.notOk(_.isSet(void 0), 'undefined is not a set');
assert.notOk(_.isSet([1, 2, 3]), 'an array is not a set');
if (typeof Map === 'function') {
assert.notOk(_.isSet(new Map()), 'a map is not a set');
}
if (typeof WeakMap === 'function') {
assert.notOk(_.isSet(new WeakMap()), 'a weakmap is not a set');
}
if (typeof WeakSet === 'function') {
assert.notOk(_.isSet(new WeakSet()), 'a weakset is not a set');
}
if (typeof Set === 'function') {
var obj = new Set();
obj.add(1).add('string').add(false).add({});
assert.ok(_.isSet(obj), 'but a set is');
}
});
QUnit.test('isWeakSet', function(assert) {
assert.notOk(_.isWeakSet('string'), 'a string is not a weakset');
assert.notOk(_.isWeakSet(2), 'a number is not a weakset');
assert.notOk(_.isWeakSet({}), 'an object is not a weakset');
assert.notOk(_.isWeakSet(false), 'a boolean is not a weakset');
assert.notOk(_.isWeakSet(void 0), 'undefined is not a weakset');
assert.notOk(_.isWeakSet([1, 2, 3]), 'an array is not a weakset');
if (typeof Map === 'function') {
assert.notOk(_.isWeakSet(new Map()), 'a map is not a weakset');
}
if (typeof WeakMap === 'function') {
assert.notOk(_.isWeakSet(new WeakMap()), 'a weakmap is not a weakset');
}
if (typeof Set === 'function') {
assert.notOk(_.isWeakSet(new Set()), 'a set is not a weakset');
}
if (typeof WeakSet === 'function') {
var obj = new WeakSet();
obj.add({x: 1}, {y: 'string'}).add({y: 'string'}).add({z: [1, 2, 3]});
assert.ok(_.isWeakSet(obj), 'but a weakset is');
}
});
QUnit.test('isFunction', function(assert) { QUnit.test('isFunction', function(assert) {
assert.ok(!_.isFunction(void 0), 'undefined vars are not functions'); assert.notOk(_.isFunction(void 0), 'undefined vars are not functions');
assert.ok(!_.isFunction([1, 2, 3]), 'arrays are not functions'); assert.notOk(_.isFunction([1, 2, 3]), 'arrays are not functions');
assert.ok(!_.isFunction('moe'), 'strings are not functions'); assert.notOk(_.isFunction('moe'), 'strings are not functions');
assert.ok(_.isFunction(_.isFunction), 'but functions are'); assert.ok(_.isFunction(_.isFunction), 'but functions are');
assert.ok(_.isFunction(function(){}), 'even anonymous ones'); assert.ok(_.isFunction(function(){}), 'even anonymous ones');
if (testElement) { if (testElement) {
assert.ok(!_.isFunction(testElement), 'elements are not functions'); assert.notOk(_.isFunction(testElement), 'elements are not functions');
} }
var nodelist = typeof document != 'undefined' && document.childNodes; var nodelist = typeof document != 'undefined' && document.childNodes;
if (nodelist) { if (nodelist) {
assert.ok(!_.isFunction(nodelist)); assert.notOk(_.isFunction(nodelist));
} }
}); });
if (typeof Int8Array !== 'undefined') { if (typeof Int8Array !== 'undefined') {
QUnit.test('#1929 Typed Array constructors are functions', function(assert) { QUnit.test('#1929 Typed Array constructors are functions', function(assert) {
_.chain(['Float32Array', 'Float64Array', 'Int8Array', 'Int16Array', 'Int32 Array', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array']) _.chain(['Float32Array', 'Float64Array', 'Int8Array', 'Int16Array', 'Int32 Array', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array'])
.map(_.propertyOf(typeof GLOBAL != 'undefined' ? GLOBAL : window)) .map(_.propertyOf(typeof GLOBAL != 'undefined' ? GLOBAL : window))
.compact() .compact()
.each(function(TypedArray) { .each(function(TypedArray) {
// PhantomJS reports `typeof UInt8Array == 'object'` and doesn't report toString TypeArray // PhantomJS reports `typeof UInt8Array == 'object'` and doesn't report toString TypeArray
// as a function // as a function
assert.strictEqual(_.isFunction(TypedArray), Object.prototype.toString.c all(TypedArray) === '[object Function]'); assert.strictEqual(_.isFunction(TypedArray), Object.prototype.toString.c all(TypedArray) === '[object Function]');
}); });
}); });
} }
QUnit.test('isDate', function(assert) { QUnit.test('isDate', function(assert) {
assert.ok(!_.isDate(100), 'numbers are not dates'); assert.notOk(_.isDate(100), 'numbers are not dates');
assert.ok(!_.isDate({}), 'objects are not dates'); assert.notOk(_.isDate({}), 'objects are not dates');
assert.ok(_.isDate(new Date()), 'but dates are'); assert.ok(_.isDate(new Date()), 'but dates are');
}); });
QUnit.test('isRegExp', function(assert) { QUnit.test('isRegExp', function(assert) {
assert.ok(!_.isRegExp(_.identity), 'functions are not RegExps'); assert.notOk(_.isRegExp(_.identity), 'functions are not RegExps');
assert.ok(_.isRegExp(/identity/), 'but RegExps are'); assert.ok(_.isRegExp(/identity/), 'but RegExps are');
}); });
QUnit.test('isFinite', function(assert) { QUnit.test('isFinite', function(assert) {
assert.ok(!_.isFinite(void 0), 'undefined is not finite'); assert.notOk(_.isFinite(void 0), 'undefined is not finite');
assert.ok(!_.isFinite(null), 'null is not finite'); assert.notOk(_.isFinite(null), 'null is not finite');
assert.ok(!_.isFinite(NaN), 'NaN is not finite'); assert.notOk(_.isFinite(NaN), 'NaN is not finite');
assert.ok(!_.isFinite(Infinity), 'Infinity is not finite'); assert.notOk(_.isFinite(Infinity), 'Infinity is not finite');
assert.ok(!_.isFinite(-Infinity), '-Infinity is not finite'); assert.notOk(_.isFinite(-Infinity), '-Infinity is not finite');
assert.ok(_.isFinite('12'), 'Numeric strings are numbers'); assert.ok(_.isFinite('12'), 'Numeric strings are numbers');
assert.ok(!_.isFinite('1a'), 'Non numeric strings are not numbers'); assert.notOk(_.isFinite('1a'), 'Non numeric strings are not numbers');
assert.ok(!_.isFinite(''), 'Empty strings are not numbers'); assert.notOk(_.isFinite(''), 'Empty strings are not numbers');
var obj = new Number(5); var obj = new Number(5);
assert.ok(_.isFinite(obj), 'Number instances can be finite'); assert.ok(_.isFinite(obj), 'Number instances can be finite');
assert.ok(_.isFinite(0), '0 is finite'); assert.ok(_.isFinite(0), '0 is finite');
assert.ok(_.isFinite(123), 'Ints are finite'); assert.ok(_.isFinite(123), 'Ints are finite');
assert.ok(_.isFinite(-12.44), 'Floats are finite'); assert.ok(_.isFinite(-12.44), 'Floats are finite');
if (typeof Symbol === 'function') {
assert.notOk(_.isFinite(Symbol()), 'symbols are not numbers');
assert.notOk(_.isFinite(Symbol('description')), 'described symbols are not
numbers');
assert.notOk(_.isFinite(Object(Symbol())), 'boxed symbols are not numbers'
);
}
}); });
QUnit.test('isNaN', function(assert) { QUnit.test('isNaN', function(assert) {
assert.ok(!_.isNaN(void 0), 'undefined is not NaN'); assert.notOk(_.isNaN(void 0), 'undefined is not NaN');
assert.ok(!_.isNaN(null), 'null is not NaN'); assert.notOk(_.isNaN(null), 'null is not NaN');
assert.ok(!_.isNaN(0), '0 is not NaN'); assert.notOk(_.isNaN(0), '0 is not NaN');
assert.ok(!_.isNaN(new Number(0)), 'wrapped 0 is not NaN'); assert.notOk(_.isNaN(new Number(0)), 'wrapped 0 is not NaN');
assert.ok(_.isNaN(NaN), 'but NaN is'); assert.ok(_.isNaN(NaN), 'but NaN is');
assert.ok(_.isNaN(new Number(NaN)), 'wrapped NaN is still NaN'); assert.ok(_.isNaN(new Number(NaN)), 'wrapped NaN is still NaN');
if (typeof Symbol !== 'undefined'){
assert.notOk(_.isNaN(Symbol()), 'symbol is not NaN');
}
}); });
QUnit.test('isNull', function(assert) { QUnit.test('isNull', function(assert) {
assert.ok(!_.isNull(void 0), 'undefined is not null'); assert.notOk(_.isNull(void 0), 'undefined is not null');
assert.ok(!_.isNull(NaN), 'NaN is not null'); assert.notOk(_.isNull(NaN), 'NaN is not null');
assert.ok(_.isNull(null), 'but null is'); assert.ok(_.isNull(null), 'but null is');
}); });
QUnit.test('isUndefined', function(assert) { QUnit.test('isUndefined', function(assert) {
assert.ok(!_.isUndefined(1), 'numbers are defined'); assert.notOk(_.isUndefined(1), 'numbers are defined');
assert.ok(!_.isUndefined(null), 'null is defined'); assert.notOk(_.isUndefined(null), 'null is defined');
assert.ok(!_.isUndefined(false), 'false is defined'); assert.notOk(_.isUndefined(false), 'false is defined');
assert.ok(!_.isUndefined(NaN), 'NaN is defined'); assert.notOk(_.isUndefined(NaN), 'NaN is defined');
assert.ok(_.isUndefined(), 'nothing is undefined'); assert.ok(_.isUndefined(), 'nothing is undefined');
assert.ok(_.isUndefined(void 0), 'undefined is undefined'); assert.ok(_.isUndefined(void 0), 'undefined is undefined');
}); });
QUnit.test('isError', function(assert) { QUnit.test('isError', function(assert) {
assert.ok(!_.isError(1), 'numbers are not Errors'); assert.notOk(_.isError(1), 'numbers are not Errors');
assert.ok(!_.isError(null), 'null is not an Error'); assert.notOk(_.isError(null), 'null is not an Error');
assert.ok(!_.isError(Error), 'functions are not Errors'); assert.notOk(_.isError(Error), 'functions are not Errors');
assert.ok(_.isError(new Error()), 'Errors are Errors'); assert.ok(_.isError(new Error()), 'Errors are Errors');
assert.ok(_.isError(new EvalError()), 'EvalErrors are Errors'); assert.ok(_.isError(new EvalError()), 'EvalErrors are Errors');
assert.ok(_.isError(new RangeError()), 'RangeErrors are Errors'); assert.ok(_.isError(new RangeError()), 'RangeErrors are Errors');
assert.ok(_.isError(new ReferenceError()), 'ReferenceErrors are Errors'); assert.ok(_.isError(new ReferenceError()), 'ReferenceErrors are Errors');
assert.ok(_.isError(new SyntaxError()), 'SyntaxErrors are Errors'); assert.ok(_.isError(new SyntaxError()), 'SyntaxErrors are Errors');
assert.ok(_.isError(new TypeError()), 'TypeErrors are Errors'); assert.ok(_.isError(new TypeError()), 'TypeErrors are Errors');
assert.ok(_.isError(new URIError()), 'URIErrors are Errors'); assert.ok(_.isError(new URIError()), 'URIErrors are Errors');
}); });
QUnit.test('tap', function(assert) { QUnit.test('tap', function(assert) {
skipping to change at line 777 skipping to change at line 898
max(). max().
tap(interceptor). tap(interceptor).
value(); value();
assert.equal(returned, 6, 'can use tapped objects in a chain'); assert.equal(returned, 6, 'can use tapped objects in a chain');
assert.equal(intercepted, returned, 'can use tapped objects in a chain'); assert.equal(intercepted, returned, 'can use tapped objects in a chain');
}); });
QUnit.test('has', function(assert) { QUnit.test('has', function(assert) {
var obj = {foo: 'bar', func: function(){}}; var obj = {foo: 'bar', func: function(){}};
assert.ok(_.has(obj, 'foo'), 'has() checks that the object has a property.') ; assert.ok(_.has(obj, 'foo'), 'has() checks that the object has a property.') ;
assert.ok(!_.has(obj, 'baz'), "has() returns false if the object doesn't hav e the property."); assert.notOk(_.has(obj, 'baz'), "has() returns false if the object doesn't h ave the property.");
assert.ok(_.has(obj, 'func'), 'has() works for functions too.'); assert.ok(_.has(obj, 'func'), 'has() works for functions too.');
obj.hasOwnProperty = null; obj.hasOwnProperty = null;
assert.ok(_.has(obj, 'foo'), 'has() works even when the hasOwnProperty metho d is deleted.'); assert.ok(_.has(obj, 'foo'), 'has() works even when the hasOwnProperty metho d is deleted.');
var child = {}; var child = {};
child.prototype = obj; child.prototype = obj;
assert.ok(!_.has(child, 'foo'), 'has() does not check the prototype chain fo r a property.'); assert.notOk(_.has(child, 'foo'), 'has() does not check the prototype chain for a property.');
assert.strictEqual(_.has(null, 'foo'), false, 'has() returns false for null' ); assert.strictEqual(_.has(null, 'foo'), false, 'has() returns false for null' );
assert.strictEqual(_.has(void 0, 'foo'), false, 'has() returns false for und efined'); assert.strictEqual(_.has(void 0, 'foo'), false, 'has() returns false for und efined');
}); });
QUnit.test('isMatch', function(assert) { QUnit.test('isMatch', function(assert) {
var moe = {name: 'Moe Howard', hair: true}; var moe = {name: 'Moe Howard', hair: true};
var curly = {name: 'Curly Howard', hair: false}; var curly = {name: 'Curly Howard', hair: false};
assert.equal(_.isMatch(moe, {hair: true}), true, 'Returns a boolean'); assert.equal(_.isMatch(moe, {hair: true}), true, 'Returns a boolean');
assert.equal(_.isMatch(curly, {hair: true}), false, 'Returns a boolean'); assert.equal(_.isMatch(curly, {hair: true}), false, 'Returns a boolean');
skipping to change at line 842 skipping to change at line 963
assert.equal(_.matcher({hair: true})(moe), true, 'Returns a boolean'); assert.equal(_.matcher({hair: true})(moe), true, 'Returns a boolean');
assert.equal(_.matcher({hair: true})(curly), false, 'Returns a boolean'); assert.equal(_.matcher({hair: true})(curly), false, 'Returns a boolean');
assert.equal(_.matcher({__x__: void 0})(5), false, 'can match undefined prop s on primitives'); assert.equal(_.matcher({__x__: void 0})(5), false, 'can match undefined prop s on primitives');
assert.equal(_.matcher({__x__: void 0})({__x__: void 0}), true, 'can match u ndefined props'); assert.equal(_.matcher({__x__: void 0})({__x__: void 0}), true, 'can match u ndefined props');
assert.equal(_.matcher({})(null), true, 'Empty spec called with null object returns true'); assert.equal(_.matcher({})(null), true, 'Empty spec called with null object returns true');
assert.equal(_.matcher({a: 1})(null), false, 'Non-empty spec called with nul l object returns false'); assert.equal(_.matcher({a: 1})(null), false, 'Non-empty spec called with nul l object returns false');
assert.ok(_.find(stooges, _.matcher({hair: false})) === curly, 'returns a pr assert.strictEqual(_.find(stooges, _.matcher({hair: false})), curly, 'return
edicate that can be used by finding functions.'); s a predicate that can be used by finding functions.');
assert.ok(_.find(stooges, _.matcher(moe)) === moe, 'can be used to locate an assert.strictEqual(_.find(stooges, _.matcher(moe)), moe, 'can be used to loc
object exists in a collection.'); ate an object exists in a collection.');
assert.deepEqual(_.filter([null, void 0], _.matcher({a: 1})), [], 'Do not th row on null values.'); assert.deepEqual(_.filter([null, void 0], _.matcher({a: 1})), [], 'Do not th row on null values.');
assert.deepEqual(_.filter([null, void 0], _.matcher(null)), [null, void 0], 'null matches null'); assert.deepEqual(_.filter([null, void 0], _.matcher(null)), [null, void 0], 'null matches null');
assert.deepEqual(_.filter([null, void 0], _.matcher({})), [null, void 0], 'n ull matches {}'); assert.deepEqual(_.filter([null, void 0], _.matcher({})), [null, void 0], 'n ull matches {}');
assert.deepEqual(_.filter([{b: 1}], _.matcher({a: void 0})), [], 'handles un defined values (1683)'); assert.deepEqual(_.filter([{b: 1}], _.matcher({a: void 0})), [], 'handles un defined values (1683)');
_.each([true, 5, NaN, null, void 0], function(item) { _.each([true, 5, NaN, null, void 0], function(item) {
assert.equal(_.matcher(item)({a: 1}), true, 'treats primitives as empty'); assert.equal(_.matcher(item)({a: 1}), true, 'treats primitives as empty');
}); });
 End of changes. 60 change blocks. 
159 lines changed or deleted 289 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)