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 const Matcher isEmpty = const _Empty(); | 9 const Matcher isEmpty = const _Empty(); |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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'); |
143 } else { | 143 } else { |
144 for (var key in expected.getKeys()) { | 144 for (var key in expected.keys) { |
145 if (!actual.containsKey(key)) { | 145 if (!actual.containsKey(key)) { |
146 reason = new StringDescription('missing map key '); | 146 reason = new StringDescription('missing map key '); |
147 reason.addDescriptionOf(key); | 147 reason.addDescriptionOf(key); |
148 break; | 148 break; |
149 } | 149 } |
150 reason = _recursiveMatch(expected[key], actual[key], | 150 reason = _recursiveMatch(expected[key], actual[key], |
151 'with key <${key}> ${location}', depth+1); | 151 'with key <${key}> ${location}', depth+1); |
152 if (reason != null) { | 152 if (reason != null) { |
153 break; | 153 break; |
154 } | 154 } |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 final _matcher; | 618 final _matcher; |
619 final String _description; | 619 final String _description; |
620 | 620 |
621 const _Predicate(this._matcher, this._description); | 621 const _Predicate(this._matcher, this._description); |
622 | 622 |
623 bool matches(item, MatchState matchState) => _matcher(item); | 623 bool matches(item, MatchState matchState) => _matcher(item); |
624 | 624 |
625 Description describe(Description description) => | 625 Description describe(Description description) => |
626 description.add(_description); | 626 description.add(_description); |
627 } | 627 } |
OLD | NEW |