(actual, expected, comparator, anyPropertyKey, matchAgainstAnyProp, dontMatchWholeObject)
| 20566 | } |
| 20567 | |
| 20568 | function deepCompare(actual, expected, comparator, anyPropertyKey, matchAgainstAnyProp, dontMatchWholeObject) { |
| 20569 | var actualType = getTypeForFilter(actual); |
| 20570 | var expectedType = getTypeForFilter(expected); |
| 20571 | |
| 20572 | if ((expectedType === 'string') && (expected.charAt(0) === '!')) { |
| 20573 | return !deepCompare(actual, expected.substring(1), comparator, anyPropertyKey, matchAgainstAnyProp); |
| 20574 | } else if (isArray(actual)) { |
| 20575 | // In case `actual` is an array, consider it a match |
| 20576 | // if ANY of it's items matches `expected` |
| 20577 | return actual.some(function(item) { |
| 20578 | return deepCompare(item, expected, comparator, anyPropertyKey, matchAgainstAnyProp); |
| 20579 | }); |
| 20580 | } |
| 20581 | |
| 20582 | switch (actualType) { |
| 20583 | case 'object': |
| 20584 | var key; |
| 20585 | if (matchAgainstAnyProp) { |
| 20586 | for (key in actual) { |
| 20587 | if ((key.charAt(0) !== '$') && deepCompare(actual[key], expected, comparator, anyPropertyKey, true)) { |
| 20588 | return true; |
| 20589 | } |
| 20590 | } |
| 20591 | return dontMatchWholeObject ? false : deepCompare(actual, expected, comparator, anyPropertyKey, false); |
| 20592 | } else if (expectedType === 'object') { |
| 20593 | for (key in expected) { |
| 20594 | var expectedVal = expected[key]; |
| 20595 | if (isFunction(expectedVal) || isUndefined(expectedVal)) { |
| 20596 | continue; |
| 20597 | } |
| 20598 | |
| 20599 | var matchAnyProperty = key === anyPropertyKey; |
| 20600 | var actualVal = matchAnyProperty ? actual : actual[key]; |
| 20601 | if (!deepCompare(actualVal, expectedVal, comparator, anyPropertyKey, matchAnyProperty, matchAnyProperty)) { |
| 20602 | return false; |
| 20603 | } |
| 20604 | } |
| 20605 | return true; |
| 20606 | } else { |
| 20607 | return comparator(actual, expected); |
| 20608 | } |
| 20609 | case 'function': |
| 20610 | return false; |
| 20611 | default: |
| 20612 | return comparator(actual, expected); |
| 20613 | } |
| 20614 | } |
| 20615 | |
| 20616 | // Used for easily differentiating between `null` and actual `object` |
| 20617 | function getTypeForFilter(val) { |
no test coverage detected