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

Side by Side Diff: corelib/src/expect.dart

Issue 8413018: More strict non-equal cleanups in library code (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | corelib/src/implementation/future_implementation.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 class Expect { 5 class Expect {
6 6
7 /** 7 /**
8 * Checks whether the expected and actual values are equal (using [:==:]). 8 * Checks whether the expected and actual values are equal (using [:==:]).
9 */ 9 */
10 static void equals(var expected, var actual, [String reason = null]) { 10 static void equals(var expected, var actual, [String reason = null]) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 * Expect.throws(myThrowingFunction, 225 * Expect.throws(myThrowingFunction,
226 * (e) { return e is MyException}) 226 * (e) { return e is MyException})
227 * :] 227 * :]
228 */ 228 */
229 static void throws(void f(), 229 static void throws(void f(),
230 [_CheckExceptionFn check = null, 230 [_CheckExceptionFn check = null,
231 String reason = null]) { 231 String reason = null]) {
232 try { 232 try {
233 f(); 233 f();
234 } catch (var e) { 234 } catch (var e) {
235 if (check != null) { 235 if (check !== null) {
236 Expect.isTrue(check(e)); 236 Expect.isTrue(check(e));
237 } 237 }
238 return; 238 return;
239 } 239 }
240 String msg = _getMessage(reason); 240 String msg = _getMessage(reason);
241 _fail('Expect.throws($msg) fails'); 241 _fail('Expect.throws($msg) fails');
242 } 242 }
243 243
244 static String _getMessage(String reason) 244 static String _getMessage(String reason)
245 => (reason === null) ? "" : ", '$reason'"; 245 => (reason === null) ? "" : ", '$reason'";
246 246
247 static void _fail(String message) { 247 static void _fail(String message) {
248 throw new ExpectException(message); 248 throw new ExpectException(message);
249 } 249 }
250 } 250 }
251 251
252 typedef bool _CheckExceptionFn(exception); 252 typedef bool _CheckExceptionFn(exception);
253 253
254 class ExpectException implements Exception { 254 class ExpectException implements Exception {
255 ExpectException(this.message); 255 ExpectException(this.message);
256 String toString() => message; 256 String toString() => message;
257 String message; 257 String message;
258 } 258 }
OLDNEW
« no previous file with comments | « no previous file | corelib/src/implementation/future_implementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698