| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * Returns a matcher that matches empty strings, maps or collections. | 7 * Returns a matcher that matches empty strings, maps or collections. |
| 8 */ | 8 */ |
| 9 final Matcher isEmpty = const _Empty(); | 9 final Matcher isEmpty = const _Empty(); |
| 10 | 10 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return reason; | 122 return reason; |
| 123 } | 123 } |
| 124 | 124 |
| 125 Description _recursiveMatch(expected, actual, String location, int depth) { | 125 Description _recursiveMatch(expected, actual, String location, int depth) { |
| 126 Description reason = null; | 126 Description reason = null; |
| 127 // If _limit is 1 we can only recurse one level into object. | 127 // If _limit is 1 we can only recurse one level into object. |
| 128 bool canRecurse = depth == 0 || _limit > 1; | 128 bool canRecurse = depth == 0 || _limit > 1; |
| 129 if (expected == actual) { | 129 if (expected == actual) { |
| 130 // Do nothing. | 130 // Do nothing. |
| 131 } else if (depth > _limit) { | 131 } else if (depth > _limit) { |
| 132 reason = new StringDescription('recursion depth limit exceeded'); | 132 reason = new StringDescription('recursion depth limit exceeded'); |
| 133 } else { | 133 } else { |
| 134 if (expected is Iterable && canRecurse) { | 134 if (expected is Iterable && canRecurse) { |
| 135 String r = _compareIterables(expected, actual, | 135 String r = _compareIterables(expected, actual, |
| 136 _recursiveMatch, depth+1); | 136 _recursiveMatch, depth+1); |
| 137 if (r != null) reason = new StringDescription(r); | 137 if (r != null) reason = new StringDescription(r); |
| 138 } else if (expected is Map && canRecurse) { | 138 } else if (expected is Map && canRecurse) { |
| 139 if (actual is !Map) { | 139 if (actual is !Map) { |
| 140 reason = new StringDescription('expected a map'); | 140 reason = new StringDescription('expected a map'); |
| 141 } else if (expected.length != actual.length) { | 141 } else if (expected.length != actual.length) { |
| 142 reason = new StringDescription('different map lengths'); | 142 reason = new StringDescription('different map lengths'); |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 final _matcher; | 581 final _matcher; |
| 582 final String _description; | 582 final String _description; |
| 583 | 583 |
| 584 const _Predicate(this._matcher, this._description); | 584 const _Predicate(this._matcher, this._description); |
| 585 | 585 |
| 586 bool matches(item) => _matcher(item); | 586 bool matches(item) => _matcher(item); |
| 587 | 587 |
| 588 Description describe(Description description) => | 588 Description describe(Description description) => |
| 589 description.add(_description); | 589 description.add(_description); |
| 590 } | 590 } |
| OLD | NEW |