From 31e81d7be26b865623b1595230a2cedcf0482558 Mon Sep 17 00:00:00 2001 From: jdalton Date: Sat, 16 May 2015 20:27:01 -0700 Subject: [PATCH] Add string tests for `_.isMatch`, `_.matches`, & `_.matchesProperty`. --- test/test.js | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/test/test.js b/test/test.js index 7fe206cb0..23a74551c 100644 --- a/test/test.js +++ b/test/test.js @@ -8327,6 +8327,15 @@ deepEqual(actual, [false, true]); }); + test('should work with strings', 4, function() { + var pairs = [['hi', Object('h')], [Object('hi'), 'h']]; + + _.each(pairs, function(pair) { + strictEqual(_.isMatch(pair[0], pair[1]), true); + strictEqual(_.isMatch(pair[1], pair[0]), false); + }); + }); + test('should return `true` when comparing a `source` of empty arrays and objects', 1, function() { var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }], source = { 'a': [], 'b': {} }; @@ -8423,20 +8432,6 @@ strictEqual(matches(object), true); }); - test('should work with a function for `source`', 1, function() { - function source() {} - - source.a = 1; - source.b = function() {}; - source.c = 3; - - var matches = _.matches(source), - objects = [{ 'a': 1 }, { 'a': 1, 'b': source.b, 'c': 3 }], - actual = _.map(objects, matches); - - deepEqual(actual, [false, true]); - }); - test('should match problem JScript properties (test in IE < 9)', 1, function() { var objects = [{}, shadowObject]; @@ -10046,6 +10041,18 @@ deepEqual(actual, [false, true]); }); + test('should work with strings', 4, function() { + var pairs = [['hi', Object('h')], [Object('hi'), 'h']]; + + _.each(pairs, function(pair) { + var matches = _.matches(pair[1]); + strictEqual(matches(pair[0]), true); + + matches = _.matches(pair[0]); + strictEqual(matches(pair[1]), false); + }); + }); + test('should match problem JScript properties (test in IE < 9)', 1, function() { var matches = _.matches(shadowObject), objects = [{}, shadowObject], @@ -10328,6 +10335,18 @@ deepEqual(actual, [false, true]); }); + test('should work with strings', 4, function() { + var pairs = [['hi', Object('h')], [Object('hi'), 'h']]; + + _.each(pairs, function(pair) { + var matches = _.matchesProperty('0', pair[1]); + strictEqual(matches(pair[0]), true); + + matches = _.matchesProperty('0', pair[0]); + strictEqual(matches(pair[1]), false); + }); + }); + test('should match properties when `value` is not a plain object', 1, function() { function Foo(object) { _.assign(this, object); }