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

Side by Side Diff: pkg/unittest/lib/src/future_matchers.dart

Issue 12393020: Fix build break with dart2js not liking conditional expressions in initializers of const classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 | no next file » | 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 part of matcher; 5 part of matcher;
6 6
7 /** 7 /**
8 * Matches a [Future] that completes successfully with a value. Note that this 8 * Matches a [Future] that completes successfully with a value. Note that this
9 * creates an asynchronous expectation. The call to `expect()` that includes 9 * creates an asynchronous expectation. The call to `expect()` that includes
10 * this will return immediately and execution will continue. Later, when the 10 * this will return immediately and execution will continue. Later, when the
(...skipping 16 matching lines...) Expand all
27 * [id] is an optional tag that can be used to identify the completion matcher 27 * [id] is an optional tag that can be used to identify the completion matcher
28 * in error messages. 28 * in error messages.
29 */ 29 */
30 Matcher completion(matcher, [String id = '']) => 30 Matcher completion(matcher, [String id = '']) =>
31 new _Completes(wrapMatcher(matcher), id); 31 new _Completes(wrapMatcher(matcher), id);
32 32
33 class _Completes extends BaseMatcher { 33 class _Completes extends BaseMatcher {
34 final Matcher _matcher; 34 final Matcher _matcher;
35 final String _id; 35 final String _id;
36 36
37 const _Completes(this._matcher, String id) 37 const _Completes(this._matcher, this._id);
38 : this._id = (id == '') ? '' : '$id ';
39 38
40 bool matches(item, MatchState matchState) { 39 bool matches(item, MatchState matchState) {
41 if (item is! Future) return false; 40 if (item is! Future) return false;
42 var done = wrapAsync((fn) => fn(), _id); 41 var done = wrapAsync((fn) => fn(), _id);
43 42
44 item.then((value) { 43 item.then((value) {
45 done(() { if (_matcher != null) expect(value, _matcher); }); 44 done(() { if (_matcher != null) expect(value, _matcher); });
46 }, onError: (e) { 45 }, onError: (e) {
47 var reason = 'Expected future ${_id}to complete successfully, ' 46 var id = _id == '' ? '' : '${_id} ';
Siggi Cherem (dart-lang) 2013/03/01 22:17:15 I was actually going to suggest this anyways, but
47 var reason = 'Expected future ${id}to complete successfully, '
48 'but it failed with ${e.error}'; 48 'but it failed with ${e.error}';
49 if (e.stackTrace != null) { 49 if (e.stackTrace != null) {
50 var stackTrace = e.stackTrace.toString(); 50 var stackTrace = e.stackTrace.toString();
51 stackTrace = ' ${stackTrace.replaceAll('\n', '\n ')}'; 51 stackTrace = ' ${stackTrace.replaceAll('\n', '\n ')}';
52 reason = '$reason\nStack trace:\n$stackTrace'; 52 reason = '$reason\nStack trace:\n$stackTrace';
53 } 53 }
54 done(() => fail(reason)); 54 done(() => fail(reason));
55 }); 55 });
56 56
57 return true; 57 return true;
58 } 58 }
59 59
60 Description describe(Description description) { 60 Description describe(Description description) {
61 if (_matcher == null) { 61 if (_matcher == null) {
62 description.add('completes successfully'); 62 description.add('completes successfully');
63 } else { 63 } else {
64 description.add('completes to a value that ').addDescriptionOf(_matcher); 64 description.add('completes to a value that ').addDescriptionOf(_matcher);
65 } 65 }
66 return description; 66 return description;
67 } 67 }
68 } 68 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698