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

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

Issue 10545167: 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/unittest.dart » ('j') | lib/unittest/unittest.dart » ('J')
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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 * (the second time to get the failure description). 134 * (the second time to get the failure description).
135 */ 135 */
136 final Matcher throws = const _Throws(); 136 final Matcher throws = const _Throws();
137 137
138 /** 138 /**
139 * Returns a matcher that matches a function call against an exception, 139 * Returns a matcher that matches a function call against an exception,
140 * which is in turn constrained by a [matcher]. 140 * which is in turn constrained by a [matcher].
141 * The value passed to expect() should be a reference to the function. 141 * The value passed to expect() should be a reference to the function.
142 * Note that the function cannot take arguments; to handle this 142 * Note that the function cannot take arguments; to handle this
143 * a wrapper will have to be created. 143 * a wrapper will have to be created.
144 * The function will be called once upon success, or twice upon failure
145 * (the second time to get the failure description).
146 */ 144 */
147 Matcher throwsA(Matcher matcher) => new _Throws(matcher); 145 Matcher throwsA(Matcher matcher) => new _Throws(matcher);
148 146
149 /** 147 /**
150 * A matcher that matches a function call against no exception. 148 * A matcher that matches a function call against no exception.
151 * The function will be called once. Any exceptions will be silently swallowed. 149 * The function will be called once. Any exceptions will be silently swallowed.
152 * The value passed to expect() should be a reference to the function. 150 * The value passed to expect() should be a reference to the function.
153 * Note that the function cannot take arguments; to handle this 151 * Note that the function cannot take arguments; to handle this
154 * a wrapper will have to be created. 152 * a wrapper will have to be created.
155 */ 153 */
(...skipping 16 matching lines...) Expand all
172 Description describe(Description description) { 170 Description describe(Description description) {
173 if (_matcher == null) { 171 if (_matcher == null) {
174 return description.add("throws an exception"); 172 return description.add("throws an exception");
175 } else { 173 } else {
176 return description.add('throws an exception which matches '). 174 return description.add('throws an exception which matches ').
177 addDescriptionOf(_matcher); 175 addDescriptionOf(_matcher);
178 } 176 }
179 } 177 }
180 178
181 Description describeMismatch(item, Description mismatchDescription) { 179 Description describeMismatch(item, Description mismatchDescription) {
182 try { 180 if (_matcher == null) {
183 item();
184 return mismatchDescription.add(' no exception'); 181 return mismatchDescription.add(' no exception');
185 } catch (final e) { 182 } else {
186 return mismatchDescription.add(' exception does not match '). 183 return mismatchDescription.
184 add(' no exception or exception does not match ').
187 addDescriptionOf(_matcher); 185 addDescriptionOf(_matcher);
188 } 186 }
189 } 187 }
190 } 188 }
191 189
192 class _ReturnsNormally extends BaseMatcher { 190 class _ReturnsNormally extends BaseMatcher {
193 191
194 const _ReturnsNormally(); 192 const _ReturnsNormally();
195 193
196 bool matches(f) { 194 bool matches(f) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 399 }
402 } else if (item is Map) { 400 } else if (item is Map) {
403 return item.containsKey(_expected); 401 return item.containsKey(_expected);
404 } 402 }
405 return false; 403 return false;
406 } 404 }
407 405
408 Description describe(Description description) => 406 Description describe(Description description) =>
409 description.add('contains ').addDescriptionOf(_expected); 407 description.add('contains ').addDescriptionOf(_expected);
410 } 408 }
OLDNEW
« no previous file with comments | « no previous file | lib/unittest/unittest.dart » ('j') | lib/unittest/unittest.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698