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

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

Issue 10544167: Some unit test fixes (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/expect.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. The function will be called once upon success, 150 * the one you want to test.
151 * or twice upon failure (the second time to get the failure description).
152 * 151 *
153 * * A [Future] that completes with an exception. Note that this creates an 152 * * A [Future] that completes with an exception. Note that this creates an
154 * asynchronous expectation. The call to `expect()` that includes this will 153 * asynchronous expectation. The call to `expect()` that includes this will
155 * return immediately and execution will continue. Later, when the future 154 * return immediately and execution will continue. Later, when the future
156 * completes, the actual expectation will run. 155 * completes, the actual expectation will run.
157 * 156 *
158 * In both cases, when an exception is thrown, this will test that the exception 157 * In both cases, when an exception is thrown, this will test that the exception
159 * object matches [matcher]. If [matcher] is not an instance of [Matcher], it 158 * object matches [matcher]. If [matcher] is not an instance of [Matcher], it
160 * will implicitly be treated as `equals(matcher)`. 159 * will implicitly be treated as `equals(matcher)`.
161 */ 160 */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 Description describe(Description description) { 202 Description describe(Description description) {
204 if (_matcher == null) { 203 if (_matcher == null) {
205 return description.add("throws an exception"); 204 return description.add("throws an exception");
206 } else { 205 } else {
207 return description.add('throws an exception which matches '). 206 return description.add('throws an exception which matches ').
208 addDescriptionOf(_matcher); 207 addDescriptionOf(_matcher);
209 } 208 }
210 } 209 }
211 210
212 Description describeMismatch(item, Description mismatchDescription) { 211 Description describeMismatch(item, Description mismatchDescription) {
213 try { 212 if (_matcher == null) {
214 item();
215 return mismatchDescription.add(' no exception'); 213 return mismatchDescription.add(' no exception');
216 } catch (final e) { 214 } else {
217 return mismatchDescription.add(' exception does not match '). 215 return mismatchDescription.
216 add(' no exception or exception does not match ').
218 addDescriptionOf(_matcher); 217 addDescriptionOf(_matcher);
219 } 218 }
220 } 219 }
221 } 220 }
222 221
223 class _ReturnsNormally extends BaseMatcher { 222 class _ReturnsNormally extends BaseMatcher {
224 223
225 const _ReturnsNormally(); 224 const _ReturnsNormally();
226 225
227 bool matches(f) { 226 bool matches(f) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 431 }
433 } else if (item is Map) { 432 } else if (item is Map) {
434 return item.containsKey(_expected); 433 return item.containsKey(_expected);
435 } 434 }
436 return false; 435 return false;
437 } 436 }
438 437
439 Description describe(Description description) => 438 Description describe(Description description) =>
440 description.add('contains ').addDescriptionOf(_expected); 439 description.add('contains ').addDescriptionOf(_expected);
441 } 440 }
441
OLDNEW
« no previous file with comments | « no previous file | lib/unittest/expect.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698