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

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

Issue 10891022: Update corelib/ and lib/ to use the new try-catch syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | 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) 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 * Expect is used for tests that do not want to make use of the 6 * Expect is used for tests that do not want to make use of the
7 * Dart unit test library - for example, the core language tests. 7 * Dart unit test library - for example, the core language tests.
8 * Third parties are discouraged from using this, and should use 8 * Third parties are discouraged from using this, and should use
9 * the expect() function in the unit test library instead for 9 * the expect() function in the unit test library instead for
10 * test assertions. 10 * test assertions.
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 * that the correct exception is being thrown. For example, to check 258 * that the correct exception is being thrown. For example, to check
259 * the type of the exception you could write this: 259 * the type of the exception you could write this:
260 * 260 *
261 * Expect.throws(myThrowingFunction, (e) => e is MyException); 261 * Expect.throws(myThrowingFunction, (e) => e is MyException);
262 */ 262 */
263 static void throws(void f(), 263 static void throws(void f(),
264 [_CheckExceptionFn check = null, 264 [_CheckExceptionFn check = null,
265 String reason = null]) { 265 String reason = null]) {
266 try { 266 try {
267 f(); 267 f();
268 } catch (var e) { 268 } catch (e) {
269 if (check !== null) { 269 if (check !== null) {
270 Expect.isTrue(check(e)); 270 Expect.isTrue(check(e));
271 } 271 }
272 return; 272 return;
273 } 273 }
274 String msg = _getMessage(reason); 274 String msg = _getMessage(reason);
275 _fail('Expect.throws($msg) fails'); 275 _fail('Expect.throws($msg) fails');
276 } 276 }
277 277
278 static String _getMessage(String reason) 278 static String _getMessage(String reason)
279 => (reason === null) ? "" : ", '$reason'"; 279 => (reason === null) ? "" : ", '$reason'";
280 280
281 static void _fail(String message) { 281 static void _fail(String message) {
282 throw new ExpectException(message); 282 throw new ExpectException(message);
283 } 283 }
284 } 284 }
285 285
286 typedef bool _CheckExceptionFn(exception); 286 typedef bool _CheckExceptionFn(exception);
287 287
288 class ExpectException implements Exception { 288 class ExpectException implements Exception {
289 ExpectException(this.message); 289 ExpectException(this.message);
290 String toString() => message; 290 String toString() => message;
291 String message; 291 String message;
292 } 292 }
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