| 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 part of unittest.matcher; | 5 part of unittest.matcher; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Returns a matcher which matches [Iterable]s in which all elements | 8 * Returns a matcher which matches [Iterable]s in which all elements |
| 9 * match the given [matcher]. | 9 * match the given [matcher]. |
| 10 */ | 10 */ |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * Returns a matcher which matches [Iterable]s whose elements match the matchers | 154 * Returns a matcher which matches [Iterable]s whose elements match the matchers |
| 155 * in [expected], but not necessarily in the same order. | 155 * in [expected], but not necessarily in the same order. |
| 156 * | 156 * |
| 157 * Note that this is `O(n^2)` and so should only be used on small objects. | 157 * Note that this is `O(n^2)` and so should only be used on small objects. |
| 158 */ | 158 */ |
| 159 Matcher unorderedMatches(Iterable expected) => | 159 Matcher unorderedMatches(Iterable expected) => new _UnorderedMatches(expected); |
| 160 new _UnorderedMatches(expected); | |
| 161 | 160 |
| 162 class _UnorderedMatches extends Matcher { | 161 class _UnorderedMatches extends Matcher { |
| 163 final List<Matcher> _expected; | 162 final List<Matcher> _expected; |
| 164 | 163 |
| 165 _UnorderedMatches(Iterable expected) | 164 _UnorderedMatches(Iterable expected) |
| 166 : _expected = expected.map(wrapMatcher).toList(); | 165 : _expected = expected.map(wrapMatcher).toList(); |
| 167 | 166 |
| 168 String _test(item) { | 167 String _test(item) { |
| 169 if (item is !Iterable) return 'not iterable'; | 168 if (item is! Iterable) return 'not iterable'; |
| 170 item = item.toList(); | 169 item = item.toList(); |
| 171 | 170 |
| 172 // Check the lengths are the same. | 171 // Check the lengths are the same. |
| 173 if (_expected.length > item.length) { | 172 if (_expected.length > item.length) { |
| 174 return 'has too few elements (${item.length} < ${_expected.length})'; | 173 return 'has too few elements (${item.length} < ${_expected.length})'; |
| 175 } else if (_expected.length < item.length) { | 174 } else if (_expected.length < item.length) { |
| 176 return 'has too many elements (${item.length} > ${_expected.length})'; | 175 return 'has too many elements (${item.length} > ${_expected.length})'; |
| 177 } | 176 } |
| 178 | 177 |
| 179 var matched = new List<bool>.filled(item.length, false); | 178 var matched = new List<bool>.filled(item.length, false); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 return mismatchDescription. | 264 return mismatchDescription. |
| 266 add('has '). | 265 add('has '). |
| 267 addDescriptionOf(matchState["actual"]). | 266 addDescriptionOf(matchState["actual"]). |
| 268 add(' which is not $_description '). | 267 add(' which is not $_description '). |
| 269 addDescriptionOf(matchState["expected"]). | 268 addDescriptionOf(matchState["expected"]). |
| 270 add(' at index ${matchState["index"]}'); | 269 add(' at index ${matchState["index"]}'); |
| 271 } | 270 } |
| 272 } | 271 } |
| 273 } | 272 } |
| 274 | 273 |
| OLD | NEW |