Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1331)

Side by Side Diff: pkg/unittest/lib/src/collection_matchers.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/lib/mock.dart ('k') | pkg/unittest/lib/src/config.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/mock.dart ('k') | pkg/unittest/lib/src/config.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698