(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject)
| 18317 | } |
| 18318 | |
| 18319 | function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) { |
| 18320 | var actualType = getTypeForFilter(actual); |
| 18321 | var expectedType = getTypeForFilter(expected); |
| 18322 | |
| 18323 | if ((expectedType === 'string') && (expected.charAt(0) === '!')) { |
| 18324 | return !deepCompare(actual, expected.substring(1), comparator, matchAgainstAnyProp); |
| 18325 | } else if (isArray(actual)) { |
| 18326 | // In case `actual` is an array, consider it a match |
| 18327 | // if ANY of it's items matches `expected` |
| 18328 | return actual.some(function(item) { |
| 18329 | return deepCompare(item, expected, comparator, matchAgainstAnyProp); |
| 18330 | }); |
| 18331 | } |
| 18332 | |
| 18333 | switch (actualType) { |
| 18334 | case 'object': |
| 18335 | var key; |
| 18336 | if (matchAgainstAnyProp) { |
| 18337 | for (key in actual) { |
| 18338 | if ((key.charAt(0) !== '$') && deepCompare(actual[key], expected, comparator, true)) { |
| 18339 | return true; |
| 18340 | } |
| 18341 | } |
| 18342 | return dontMatchWholeObject ? false : deepCompare(actual, expected, comparator, false); |
| 18343 | } else if (expectedType === 'object') { |
| 18344 | for (key in expected) { |
| 18345 | var expectedVal = expected[key]; |
| 18346 | if (isFunction(expectedVal) || isUndefined(expectedVal)) { |
| 18347 | continue; |
| 18348 | } |
| 18349 | |
| 18350 | var matchAnyProperty = key === '$'; |
| 18351 | var actualVal = matchAnyProperty ? actual : actual[key]; |
| 18352 | if (!deepCompare(actualVal, expectedVal, comparator, matchAnyProperty, matchAnyProperty)) { |
| 18353 | return false; |
| 18354 | } |
| 18355 | } |
| 18356 | return true; |
| 18357 | } else { |
| 18358 | return comparator(actual, expected); |
| 18359 | } |
| 18360 | break; |
| 18361 | case 'function': |
| 18362 | return false; |
| 18363 | default: |
| 18364 | return comparator(actual, expected); |
| 18365 | } |
| 18366 | } |
| 18367 | |
| 18368 | // Used for easily differentiating between `null` and actual `object` |
| 18369 | function getTypeForFilter(val) { |
no test coverage detected