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

Side by Side Diff: lib/unittest/core_matchers.dart

Issue 10539163: Revert 8668 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | « no previous file | lib/unittest/unittest.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 /** 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 * completes, the actual expectation will run. 140 * completes, the actual expectation will run.
141 */ 141 */
142 final Matcher throws = const _Throws(); 142 final Matcher throws = const _Throws();
143 143
144 /** 144 /**
145 * This can be used to match two kinds of objects: 145 * This can be used to match two kinds of objects:
146 * 146 *
147 * * A [Function] that throws an exception when called. The function cannot 147 * * A [Function] that throws an exception when called. The function cannot
148 * take any arguments. If you want to test that a function expecting 148 * take any arguments. If you want to test that a function expecting
149 * arguments throws, wrap it in another zero-argument function that calls 149 * arguments throws, wrap it in another zero-argument function that calls
150 * the one you want to test. 150 * the one you want to test. The function will be called once upon success,
151 * or twice upon failure (the second time to get the failure description).
151 * 152 *
152 * * A [Future] that completes with an exception. Note that this creates an 153 * * A [Future] that completes with an exception. Note that this creates an
153 * asynchronous expectation. The call to `expect()` that includes this will 154 * asynchronous expectation. The call to `expect()` that includes this will
154 * return immediately and execution will continue. Later, when the future 155 * return immediately and execution will continue. Later, when the future
155 * completes, the actual expectation will run. 156 * completes, the actual expectation will run.
156 * 157 *
157 * In both cases, when an exception is thrown, this will test that the exception 158 * In both cases, when an exception is thrown, this will test that the exception
158 * object matches [matcher]. If [matcher] is not an instance of [Matcher], it 159 * object matches [matcher]. If [matcher] is not an instance of [Matcher], it
159 * will implicitly be treated as `equals(matcher)`. 160 * will implicitly be treated as `equals(matcher)`.
160 */ 161 */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 Description describe(Description description) { 203 Description describe(Description description) {
203 if (_matcher == null) { 204 if (_matcher == null) {
204 return description.add("throws an exception"); 205 return description.add("throws an exception");
205 } else { 206 } else {
206 return description.add('throws an exception which matches '). 207 return description.add('throws an exception which matches ').
207 addDescriptionOf(_matcher); 208 addDescriptionOf(_matcher);
208 } 209 }
209 } 210 }
210 211
211 Description describeMismatch(item, Description mismatchDescription) { 212 Description describeMismatch(item, Description mismatchDescription) {
212 if (_matcher == null) { 213 try {
214 item();
213 return mismatchDescription.add(' no exception'); 215 return mismatchDescription.add(' no exception');
214 } else { 216 } catch (final e) {
215 return mismatchDescription. 217 return mismatchDescription.add(' exception does not match ').
216 add(' no exception or exception does not match ').
217 addDescriptionOf(_matcher); 218 addDescriptionOf(_matcher);
218 } 219 }
219 } 220 }
220 } 221 }
221 222
222 class _ReturnsNormally extends BaseMatcher { 223 class _ReturnsNormally extends BaseMatcher {
223 224
224 const _ReturnsNormally(); 225 const _ReturnsNormally();
225 226
226 bool matches(f) { 227 bool matches(f) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 432 }
432 } else if (item is Map) { 433 } else if (item is Map) {
433 return item.containsKey(_expected); 434 return item.containsKey(_expected);
434 } 435 }
435 return false; 436 return false;
436 } 437 }
437 438
438 Description describe(Description description) => 439 Description describe(Description description) =>
439 description.add('contains ').addDescriptionOf(_expected); 440 description.add('contains ').addDescriptionOf(_expected);
440 } 441 }
OLDNEW
« no previous file with comments | « no previous file | lib/unittest/unittest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698