| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 * | 23 * |
| 24 * To test that a Future completes with an exception, you can use [throws] and | 24 * To test that a Future completes with an exception, you can use [throws] and |
| 25 * [throwsA]. | 25 * [throwsA]. |
| 26 * | 26 * |
| 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 Matcher { |
| 34 final Matcher _matcher; | 34 final Matcher _matcher; |
| 35 final String _id; | 35 final String _id; |
| 36 | 36 |
| 37 const _Completes(this._matcher, this._id); | 37 const _Completes(this._matcher, this._id); |
| 38 | 38 |
| 39 bool matches(item, Map matchState) { | 39 bool matches(item, Map matchState) { |
| 40 if (item is! Future) return false; | 40 if (item is! Future) return false; |
| 41 var done = wrapAsync((fn) => fn(), _id); | 41 var done = wrapAsync((fn) => fn(), _id); |
| 42 | 42 |
| 43 item.then((value) { | 43 item.then((value) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 60 | 60 |
| 61 Description describe(Description description) { | 61 Description describe(Description description) { |
| 62 if (_matcher == null) { | 62 if (_matcher == null) { |
| 63 description.add('completes successfully'); | 63 description.add('completes successfully'); |
| 64 } else { | 64 } else { |
| 65 description.add('completes to a value that ').addDescriptionOf(_matcher); | 65 description.add('completes to a value that ').addDescriptionOf(_matcher); |
| 66 } | 66 } |
| 67 return description; | 67 return description; |
| 68 } | 68 } |
| 69 } | 69 } |
| OLD | NEW |