From a64b6293335cd7e26eb49e87697d2532a7013db5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 29 Jun 2016 11:01:25 -0700 Subject: [PATCH] Combine `_.isMatch` and `_.matches` tests. --- test/test.js | 595 ++++++++++++--------------------------------------- 1 file changed, 133 insertions(+), 462 deletions(-) diff --git a/test/test.js b/test/test.js index bfeacbbe2..90ab4fef0 100644 --- a/test/test.js +++ b/test/test.js @@ -10645,346 +10645,6 @@ /*--------------------------------------------------------------------------*/ - QUnit.module('lodash.isMatch'); - - (function() { - QUnit.test('should perform a deep comparison between `object` and `source`', function(assert) { - assert.expect(5); - - var object = { 'a': 1, 'b': 2, 'c': 3 }; - assert.strictEqual(_.isMatch(object, { 'a': 1 }), true); - assert.strictEqual(_.isMatch(object, { 'b': 1 }), false); - assert.strictEqual(_.isMatch(object, { 'a': 1, 'c': 3 }), true); - assert.strictEqual(_.isMatch(object, { 'c': 3, 'd': 4 }), false); - - object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 }; - assert.strictEqual(_.isMatch(object, { 'a': { 'b': { 'c': 1 } } }), true); - }); - - QUnit.test('should match inherited string keyed `object` properties', function(assert) { - assert.expect(1); - - function Foo() { - this.a = 1; - } - Foo.prototype.b = 2; - - assert.strictEqual(_.isMatch({ 'a': new Foo }, { 'a': { 'b': 2 } }), true); - }); - - QUnit.test('should not match by inherited `source` properties', function(assert) { - assert.expect(1); - - function Foo() { - this.a = 1; - } - Foo.prototype.b = 2; - - var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }], - source = new Foo, - expected = lodashStable.map(objects, stubTrue); - - var actual = lodashStable.map(objects, function(object) { - return _.isMatch(object, source); - }); - - assert.deepEqual(actual, expected); - }); - - QUnit.test('should compare a variety of `source` property values', function(assert) { - assert.expect(2); - - var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } }, - object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } }; - - assert.strictEqual(_.isMatch(object1, object1), true); - assert.strictEqual(_.isMatch(object1, object2), false); - }); - - QUnit.test('should match `-0` as `0`', function(assert) { - assert.expect(2); - - var object1 = { 'a': -0 }, - object2 = { 'a': 0 }; - - assert.strictEqual(_.isMatch(object1, object2), true); - assert.strictEqual(_.isMatch(object2, object1), true); - }); - - QUnit.test('should compare functions by reference', function(assert) { - assert.expect(3); - - var object1 = { 'a': lodashStable.noop }, - object2 = { 'a': noop }, - object3 = { 'a': {} }; - - assert.strictEqual(_.isMatch(object1, object1), true); - assert.strictEqual(_.isMatch(object2, object1), false); - assert.strictEqual(_.isMatch(object3, object1), false); - }); - - QUnit.test('should work with a function for `object`', function(assert) { - assert.expect(1); - - function Foo() {} - Foo.a = { 'b': 2, 'c': 3 }; - - assert.strictEqual(_.isMatch(Foo, { 'a': { 'b': 2 } }), true); - }); - - QUnit.test('should work with a function for `source`', function(assert) { - assert.expect(1); - - function Foo() {} - Foo.a = 1; - Foo.b = function() {}; - Foo.c = 3; - - var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }]; - - var actual = lodashStable.map(objects, function(object) { - return _.isMatch(object, Foo); - }); - - assert.deepEqual(actual, [false, true]); - }); - - QUnit.test('should work with a non-plain `object`', function(assert) { - assert.expect(1); - - function Foo(object) { lodashStable.assign(this, object); } - - var object = new Foo({ 'a': new Foo({ 'b': 2, 'c': 3 }) }); - assert.strictEqual(_.isMatch(object, { 'a': { 'b': 2 } }), true); - }); - - QUnit.test('should partial match arrays', function(assert) { - assert.expect(3); - - var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }], - source = { 'a': ['d'] }, - predicate = function(object) { return _.isMatch(object, source); }, - actual = lodashStable.filter(objects, predicate); - - assert.deepEqual(actual, [objects[1]]); - - source = { 'a': ['b', 'd'] }; - actual = lodashStable.filter(objects, predicate); - - assert.deepEqual(actual, []); - - source = { 'a': ['d', 'b'] }; - actual = lodashStable.filter(objects, predicate); - - assert.deepEqual(actual, []); - }); - - QUnit.test('should partial match arrays with duplicate values', function(assert) { - assert.expect(1); - - var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }], - source = { 'a': [2, 2] }; - - var actual = lodashStable.filter(objects, function(object) { - return _.isMatch(object, source); - }); - - assert.deepEqual(actual, [objects[1]]); - }); - - QUnit.test('should partial match arrays of objects', function(assert) { - assert.expect(1); - - var source = { 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] }; - - var objects = [ - { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] }, - { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] } - ]; - - var actual = lodashStable.filter(objects, function(object) { - return _.isMatch(object, source); - }); - - assert.deepEqual(actual, [objects[0]]); - }); - - QUnit.test('should partial match maps', function(assert) { - assert.expect(3); - - if (Map) { - var objects = [{ 'a': new Map }, { 'a': new Map }]; - objects[0].a.set('a', 1); - objects[1].a.set('a', 1); - objects[1].a.set('b', 2); - - var map = new Map; - map.set('b', 2); - - var source = { 'a': map }, - predicate = function(object) { return _.isMatch(object, source); }, - actual = lodashStable.filter(objects, predicate); - - assert.deepEqual(actual, [objects[1]]); - - map['delete']('b'); - actual = lodashStable.filter(objects, predicate); - - assert.deepEqual(actual, objects); - - map.set('c', 3); - actual = lodashStable.filter(objects, predicate); - - assert.deepEqual(actual, []); - } - else { - skipAssert(assert, 3); - } - }); - - QUnit.test('should partial match sets', function(assert) { - assert.expect(3); - - if (Set) { - var objects = [{ 'a': new Set }, { 'a': new Set }]; - objects[0].a.add(1); - objects[1].a.add(1); - objects[1].a.add(2); - - var set = new Set; - set.add(2); - - var source = { 'a': set }, - predicate = function(object) { return _.isMatch(object, source); }, - actual = lodashStable.filter(objects, predicate); - - assert.deepEqual(actual, [objects[1]]); - - set['delete'](2); - actual = lodashStable.filter(objects, predicate); - - assert.deepEqual(actual, objects); - - set.add(3); - actual = lodashStable.filter(objects, predicate); - - assert.deepEqual(actual, []); - } - else { - skipAssert(assert, 3); - } - }); - - QUnit.test('should match `undefined` values', function(assert) { - assert.expect(3); - - var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }], - source = { 'b': undefined }, - predicate = function(object) { return _.isMatch(object, source); }, - actual = lodashStable.map(objects, predicate), - expected = [false, false, true]; - - assert.deepEqual(actual, expected); - - source = { 'a': 1, 'b': undefined }; - actual = lodashStable.map(objects, predicate); - - assert.deepEqual(actual, expected); - - objects = [{ 'a': { 'b': 2 } }, { 'a': { 'b': 2, 'c': 3 } }, { 'a': { 'b': 2, 'c': undefined } }]; - source = { 'a': { 'c': undefined } }; - actual = lodashStable.map(objects, predicate); - - assert.deepEqual(actual, expected); - }); - - QUnit.test('should match `undefined` values on primitives', function(assert) { - assert.expect(3); - - numberProto.a = 1; - numberProto.b = undefined; - - try { - assert.strictEqual(_.isMatch(1, { 'b': undefined }), true); - } catch (e) { - assert.ok(false, e.message); - } - try { - assert.strictEqual(_.isMatch(1, { 'a': 1, 'b': undefined }), true); - } catch (e) { - assert.ok(false, e.message); - } - numberProto.a = { 'b': 1, 'c': undefined }; - try { - assert.strictEqual(_.isMatch(1, { 'a': { 'c': undefined } }), true); - } catch (e) { - assert.ok(false, e.message); - } - delete numberProto.a; - delete numberProto.b; - }); - - QUnit.test('should return `false` when `object` is nullish', function(assert) { - assert.expect(1); - - var values = [null, undefined], - expected = lodashStable.map(values, stubFalse), - source = { 'a': 1 }; - - var actual = lodashStable.map(values, function(value) { - try { - return _.isMatch(value, source); - } catch (e) {} - }); - - assert.deepEqual(actual, expected); - }); - - QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) { - assert.expect(1); - - var values = [null, undefined], - expected = lodashStable.map(values, stubTrue), - source = {}; - - var actual = lodashStable.map(values, function(value) { - try { - return _.isMatch(value, source); - } catch (e) {} - }); - - assert.deepEqual(actual, expected); - }); - - QUnit.test('should return `true` when comparing an empty `source`', function(assert) { - assert.expect(1); - - var object = { 'a': 1 }, - expected = lodashStable.map(empties, stubTrue); - - var actual = lodashStable.map(empties, function(value) { - return _.isMatch(object, value); - }); - - assert.deepEqual(actual, expected); - }); - - QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) { - assert.expect(1); - - var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }], - source = { 'a': [], 'b': {} }; - - var actual = lodashStable.filter(objects, function(object) { - return _.isMatch(object, source); - }); - - assert.deepEqual(actual, objects); - }); - }()); - - /*--------------------------------------------------------------------------*/ - QUnit.module('lodash.isMatchWith'); (function() { @@ -13895,36 +13555,76 @@ }); }); - /*--------------------------------------------------------------------------*/ - QUnit.module('lodash.matches'); (function() { - QUnit.test('should create a function that performs a deep comparison between `source` and a given object', function(assert) { - assert.expect(6); + QUnit.test('should not change behavior if `source` is modified', function(assert) { + assert.expect(9); + + var sources = [ + { 'a': { 'b': 2, 'c': 3 } }, + { 'a': 1, 'b': 2 }, + { 'a': 1 } + ]; + + lodashStable.each(sources, function(source, index) { + var object = lodashStable.cloneDeep(source), + par = _.matches(source); + + assert.strictEqual(par(object), true); + + if (index) { + source.a = 2; + source.b = 1; + source.c = 3; + } else { + source.a.b = 1; + source.a.c = 2; + source.a.d = 3; + } + assert.strictEqual(par(object), true); + assert.strictEqual(par(source), false); + }); + }); + }()); + + /*--------------------------------------------------------------------------*/ + + QUnit.module('matches methods'); + + lodashStable.each(['matches', 'isMatch'], function(methodName) { + var isMatches = methodName == 'matches'; + + function matches(source) { + return isMatches ? _.matches(source) : function(object) { + return _.isMatch(object, source); + }; + } + + QUnit.test('`_.' + methodName + '` should perform a deep comparison between `source` and `object`', function(assert) { + assert.expect(5); var object = { 'a': 1, 'b': 2, 'c': 3 }, - matches = _.matches({ 'a': 1 }); + par = matches({ 'a': 1 }); - assert.strictEqual(matches.length, 1); - assert.strictEqual(matches(object), true); + assert.strictEqual(par(object), true); - matches = _.matches({ 'b': 1 }); - assert.strictEqual(matches(object), false); + par = matches({ 'b': 1 }); + assert.strictEqual(par(object), false); - matches = _.matches({ 'a': 1, 'c': 3 }); - assert.strictEqual(matches(object), true); + par = matches({ 'a': 1, 'c': 3 }); + assert.strictEqual(par(object), true); - matches = _.matches({ 'c': 3, 'd': 4 }); - assert.strictEqual(matches(object), false); + par = matches({ 'c': 3, 'd': 4 }); + assert.strictEqual(par(object), false); object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 }; - matches = _.matches({ 'a': { 'b': { 'c': 1 } } }); + par = matches({ 'a': { 'b': { 'c': 1 } } }); - assert.strictEqual(matches(object), true); + assert.strictEqual(par(object), true); }); - QUnit.test('should match inherited string keyed `object` properties', function(assert) { + QUnit.test('`_.' + methodName + '` should match inherited string keyed `object` properties', function(assert) { assert.expect(1); function Foo() { @@ -13933,12 +13633,12 @@ Foo.prototype.b = 2; var object = { 'a': new Foo }, - matches = _.matches({ 'a': { 'b': 2 } }); + par = matches({ 'a': { 'b': 2 } }); - assert.strictEqual(matches(object), true); + assert.strictEqual(par(object), true); }); - QUnit.test('should not match by inherited `source` properties', function(assert) { + QUnit.test('`_.' + methodName + '` should not match by inherited `source` properties', function(assert) { assert.expect(1); function Foo() { @@ -13948,60 +13648,60 @@ var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }], source = new Foo, - actual = lodashStable.map(objects, _.matches(source)), + actual = lodashStable.map(objects, matches(source)), expected = lodashStable.map(objects, stubTrue); assert.deepEqual(actual, expected); }); - QUnit.test('should compare a variety of `source` property values', function(assert) { + QUnit.test('`_.' + methodName + '` should compare a variety of `source` property values', function(assert) { assert.expect(2); var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } }, object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } }, - matches = _.matches(object1); + par = matches(object1); - assert.strictEqual(matches(object1), true); - assert.strictEqual(matches(object2), false); + assert.strictEqual(par(object1), true); + assert.strictEqual(par(object2), false); }); - QUnit.test('should match `-0` as `0`', function(assert) { + QUnit.test('`_.' + methodName + '` should match `-0` as `0`', function(assert) { assert.expect(2); var object1 = { 'a': -0 }, object2 = { 'a': 0 }, - matches = _.matches(object1); + par = matches(object1); - assert.strictEqual(matches(object2), true); + assert.strictEqual(par(object2), true); - matches = _.matches(object2); - assert.strictEqual(matches(object1), true); + par = matches(object2); + assert.strictEqual(par(object1), true); }); - QUnit.test('should compare functions by reference', function(assert) { + QUnit.test('`_.' + methodName + '` should compare functions by reference', function(assert) { assert.expect(3); var object1 = { 'a': lodashStable.noop }, object2 = { 'a': noop }, object3 = { 'a': {} }, - matches = _.matches(object1); + par = matches(object1); - assert.strictEqual(matches(object1), true); - assert.strictEqual(matches(object2), false); - assert.strictEqual(matches(object3), false); + assert.strictEqual(par(object1), true); + assert.strictEqual(par(object2), false); + assert.strictEqual(par(object3), false); }); - QUnit.test('should work with a function for `object`', function(assert) { + QUnit.test('`_.' + methodName + '` should work with a function for `object`', function(assert) { assert.expect(1); function Foo() {} Foo.a = { 'b': 2, 'c': 3 }; - var matches = _.matches({ 'a': { 'b': 2 } }); - assert.strictEqual(matches(Foo), true); + var par = matches({ 'a': { 'b': 2 } }); + assert.strictEqual(par(Foo), true); }); - QUnit.test('should work with a function for `source`', function(assert) { + QUnit.test('`_.' + methodName + '` should work with a function for `source`', function(assert) { assert.expect(1); function Foo() {} @@ -14010,42 +13710,42 @@ Foo.c = 3; var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }], - actual = lodashStable.map(objects, _.matches(Foo)); + actual = lodashStable.map(objects, matches(Foo)); assert.deepEqual(actual, [false, true]); }); - QUnit.test('should work with a non-plain `object`', function(assert) { + QUnit.test('`_.' + methodName + '` should work with a non-plain `object`', function(assert) { assert.expect(1); function Foo(object) { lodashStable.assign(this, object); } var object = new Foo({ 'a': new Foo({ 'b': 2, 'c': 3 }) }), - matches = _.matches({ 'a': { 'b': 2 } }); + par = matches({ 'a': { 'b': 2 } }); - assert.strictEqual(matches(object), true); + assert.strictEqual(par(object), true); }); - QUnit.test('should partial match arrays', function(assert) { + QUnit.test('`_.' + methodName + '` should partial match arrays', function(assert) { assert.expect(3); var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }], - actual = lodashStable.filter(objects, _.matches({ 'a': ['d'] })); + actual = lodashStable.filter(objects, matches({ 'a': ['d'] })); assert.deepEqual(actual, [objects[1]]); - actual = lodashStable.filter(objects, _.matches({ 'a': ['b', 'd'] })); + actual = lodashStable.filter(objects, matches({ 'a': ['b', 'd'] })); assert.deepEqual(actual, []); - actual = lodashStable.filter(objects, _.matches({ 'a': ['d', 'b'] })); + actual = lodashStable.filter(objects, matches({ 'a': ['d', 'b'] })); assert.deepEqual(actual, []); }); - QUnit.test('should partial match arrays with duplicate values', function(assert) { + QUnit.test('`_.' + methodName + '` should partial match arrays with duplicate values', function(assert) { assert.expect(1); var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }], - actual = lodashStable.filter(objects, _.matches({ 'a': [2, 2] })); + actual = lodashStable.filter(objects, matches({ 'a': [2, 2] })); assert.deepEqual(actual, [objects[1]]); }); @@ -14058,11 +13758,11 @@ { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] } ]; - var actual = lodashStable.filter(objects, _.matches({ 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] })); + var actual = lodashStable.filter(objects, matches({ 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] })); assert.deepEqual(actual, [objects[0]]); }); - QUnit.test('should partial match maps', function(assert) { + QUnit.test('`_.' + methodName + '` should partial match maps', function(assert) { assert.expect(3); if (Map) { @@ -14073,17 +13773,17 @@ var map = new Map; map.set('b', 2); - var actual = lodashStable.filter(objects, _.matches({ 'a': map })); + var actual = lodashStable.filter(objects, matches({ 'a': map })); assert.deepEqual(actual, [objects[1]]); map['delete']('b'); - actual = lodashStable.filter(objects, _.matches({ 'a': map })); + actual = lodashStable.filter(objects, matches({ 'a': map })); assert.deepEqual(actual, objects); map.set('c', 3); - actual = lodashStable.filter(objects, _.matches({ 'a': map })); + actual = lodashStable.filter(objects, matches({ 'a': map })); assert.deepEqual(actual, []); } @@ -14092,7 +13792,7 @@ } }); - QUnit.test('should partial match sets', function(assert) { + QUnit.test('`_.' + methodName + '` should partial match sets', function(assert) { assert.expect(3); if (Set) { @@ -14103,17 +13803,17 @@ var set = new Set; set.add(2); - var actual = lodashStable.filter(objects, _.matches({ 'a': set })); + var actual = lodashStable.filter(objects, matches({ 'a': set })); assert.deepEqual(actual, [objects[1]]); set['delete'](2); - actual = lodashStable.filter(objects, _.matches({ 'a': set })); + actual = lodashStable.filter(objects, matches({ 'a': set })); assert.deepEqual(actual, objects); set.add(3); - actual = lodashStable.filter(objects, _.matches({ 'a': set })); + actual = lodashStable.filter(objects, matches({ 'a': set })); assert.deepEqual(actual, []); } @@ -14122,47 +13822,47 @@ } }); - QUnit.test('should match `undefined` values', function(assert) { + QUnit.test('`_.' + methodName + '` should match `undefined` values', function(assert) { assert.expect(3); var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }], - actual = lodashStable.map(objects, _.matches({ 'b': undefined })), + actual = lodashStable.map(objects, matches({ 'b': undefined })), expected = [false, false, true]; assert.deepEqual(actual, expected); - actual = lodashStable.map(objects, _.matches({ 'a': 1, 'b': undefined })); + actual = lodashStable.map(objects, matches({ 'a': 1, 'b': undefined })); assert.deepEqual(actual, expected); objects = [{ 'a': { 'b': 2 } }, { 'a': { 'b': 2, 'c': 3 } }, { 'a': { 'b': 2, 'c': undefined } }]; - actual = lodashStable.map(objects, _.matches({ 'a': { 'c': undefined } })); + actual = lodashStable.map(objects, matches({ 'a': { 'c': undefined } })); assert.deepEqual(actual, expected); }); - QUnit.test('should match `undefined` values on primitives', function(assert) { + QUnit.test('`_.' + methodName + '` should match `undefined` values on primitives', function(assert) { assert.expect(3); numberProto.a = 1; numberProto.b = undefined; try { - var matches = _.matches({ 'b': undefined }); - assert.strictEqual(matches(1), true); + var par = matches({ 'b': undefined }); + assert.strictEqual(par(1), true); } catch (e) { assert.ok(false, e.message); } try { - matches = _.matches({ 'a': 1, 'b': undefined }); - assert.strictEqual(matches(1), true); + par = matches({ 'a': 1, 'b': undefined }); + assert.strictEqual(par(1), true); } catch (e) { assert.ok(false, e.message); } numberProto.a = { 'b': 1, 'c': undefined }; try { - matches = _.matches({ 'a': { 'c': undefined } }); - assert.strictEqual(matches(1), true); + par = matches({ 'a': { 'c': undefined } }); + assert.strictEqual(par(1), true); } catch (e) { assert.ok(false, e.message); } @@ -14170,90 +13870,61 @@ delete numberProto.b; }); - QUnit.test('should return `false` when `object` is nullish', function(assert) { + QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) { assert.expect(1); var values = [, null, undefined], expected = lodashStable.map(values, stubFalse), - matches = _.matches({ 'a': 1 }); + par = matches({ 'a': 1 }); var actual = lodashStable.map(values, function(value, index) { try { - return index ? matches(value) : matches(); + return index ? par(value) : par(); } catch (e) {} }); assert.deepEqual(actual, expected); }); - QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) { - assert.expect(1); - - var values = [, null, undefined], - expected = lodashStable.map(values, stubTrue), - matches = _.matches({}); - - var actual = lodashStable.map(values, function(value, index) { - try { - return index ? matches(value) : matches(); - } catch (e) {} - }); - - assert.deepEqual(actual, expected); - }); - - QUnit.test('should return `true` when comparing an empty `source`', function(assert) { + QUnit.test('`_.' + methodName + '` hould return `true` when comparing an empty `source`', function(assert) { assert.expect(1); var object = { 'a': 1 }, expected = lodashStable.map(empties, stubTrue); var actual = lodashStable.map(empties, function(value) { - var matches = _.matches(value); - return matches(object); + var par = matches(value); + return par(object); }); assert.deepEqual(actual, expected); }); - QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) { + QUnit.test('`_.' + methodName + '` should return `true` when comparing an empty `source` to a nullish `object`', function(assert) { + assert.expect(1); + + var values = [, null, undefined], + expected = lodashStable.map(values, stubTrue), + par = matches({}); + + var actual = lodashStable.map(values, function(value, index) { + try { + return index ? par(value) : par(); + } catch (e) {} + }); + + assert.deepEqual(actual, expected); + }); + + QUnit.test('`_.' + methodName + '` should return `true` when comparing a `source` of empty arrays and objects', function(assert) { assert.expect(1); var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }], - actual = lodashStable.filter(objects, _.matches({ 'a': [], 'b': {} })); + actual = lodashStable.filter(objects, matches({ 'a': [], 'b': {} })); assert.deepEqual(actual, objects); }); - - QUnit.test('should not change behavior if `source` is modified', function(assert) { - assert.expect(9); - - var sources = [ - { 'a': { 'b': 2, 'c': 3 } }, - { 'a': 1, 'b': 2 }, - { 'a': 1 } - ]; - - lodashStable.each(sources, function(source, index) { - var object = lodashStable.cloneDeep(source), - matches = _.matches(source); - - assert.strictEqual(matches(object), true); - - if (index) { - source.a = 2; - source.b = 1; - source.c = 3; - } else { - source.a.b = 1; - source.a.c = 2; - source.a.d = 3; - } - assert.strictEqual(matches(object), true); - assert.strictEqual(matches(source), false); - }); - }); - }()); + }); /*--------------------------------------------------------------------------*/