| 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 * Returns a matcher which matches [Collection]s in which all elements | 6 * Returns a matcher which matches [Collection]s in which all elements |
| 7 * match the given [matcher]. | 7 * match the given [matcher]. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 part of matcher; | 10 part of matcher; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 * element matches the given [matcher]. | 56 * element matches the given [matcher]. |
| 57 */ | 57 */ |
| 58 Matcher someElement(matcher) => new _SomeElement(wrapMatcher(matcher)); | 58 Matcher someElement(matcher) => new _SomeElement(wrapMatcher(matcher)); |
| 59 | 59 |
| 60 class _SomeElement extends _CollectionMatcher { | 60 class _SomeElement extends _CollectionMatcher { |
| 61 Matcher _matcher; | 61 Matcher _matcher; |
| 62 | 62 |
| 63 _SomeElement(this._matcher); | 63 _SomeElement(this._matcher); |
| 64 | 64 |
| 65 bool matches(item, MatchState matchState) { | 65 bool matches(item, MatchState matchState) { |
| 66 return item.some( (e) => _matcher.matches(e, matchState) ); | 66 return item.any((e) => _matcher.matches(e, matchState)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 Description describe(Description description) => | 69 Description describe(Description description) => |
| 70 description.add('some element ').addDescriptionOf(_matcher); | 70 description.add('some element ').addDescriptionOf(_matcher); |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Returns a matcher which matches [Iterable]s that have the same | 74 * Returns a matcher which matches [Iterable]s that have the same |
| 75 * length and the same elements as [expected], and in the same order. | 75 * length and the same elements as [expected], and in the same order. |
| 76 * This is equivalent to equals but does not recurse. | 76 * This is equivalent to equals but does not recurse. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } else { | 136 } else { |
| 137 for (var element in item) { | 137 for (var element in item) { |
| 138 ++actualLength; | 138 ++actualLength; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 if (expectedLength > actualLength) { | 141 if (expectedLength > actualLength) { |
| 142 return 'has too few elements (${actualLength} < ${expectedLength})'; | 142 return 'has too few elements (${actualLength} < ${expectedLength})'; |
| 143 } else if (expectedLength < actualLength) { | 143 } else if (expectedLength < actualLength) { |
| 144 return 'has too many elements (${actualLength} > ${expectedLength})'; | 144 return 'has too many elements (${actualLength} > ${expectedLength})'; |
| 145 } | 145 } |
| 146 List<bool> matched = new List<bool>(actualLength); | 146 List<bool> matched = new List<bool>.fixedLength(actualLength); |
| 147 for (var i = 0; i < actualLength; i++) { | 147 for (var i = 0; i < actualLength; i++) { |
| 148 matched[i] = false; | 148 matched[i] = false; |
| 149 } | 149 } |
| 150 var expectedPosition = 0; | 150 var expectedPosition = 0; |
| 151 for (var expectedElement in _expected) { | 151 for (var expectedElement in _expected) { |
| 152 var actualPosition = 0; | 152 var actualPosition = 0; |
| 153 var gotMatch = false; | 153 var gotMatch = false; |
| 154 for (var actualElement in item) { | 154 for (var actualElement in item) { |
| 155 if (!matched[actualPosition]) { | 155 if (!matched[actualPosition]) { |
| 156 if (expectedElement == actualElement) { | 156 if (expectedElement == actualElement) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 if (item is !Collection) { | 193 if (item is !Collection) { |
| 194 return mismatchDescription. | 194 return mismatchDescription. |
| 195 addDescriptionOf(item). | 195 addDescriptionOf(item). |
| 196 add(' not a collection'); | 196 add(' not a collection'); |
| 197 } else { | 197 } else { |
| 198 return super.describeMismatch(item, mismatchDescription, matchState, | 198 return super.describeMismatch(item, mismatchDescription, matchState, |
| 199 verbose); | 199 verbose); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 } | 202 } |
| OLD | NEW |