Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * Matches a [Future] that completes successfully with a value. Note that this | |
| 7 * creates an asynchronous expectation. The call to `expect()` that includes | |
| 8 * this will return immediately and execution will continue. Later, when the | |
| 9 * future completes, the actual expectation will run. | |
| 10 * | |
| 11 * To test that a Future completes with an exception, you can use [throws] and | |
| 12 * [throwsA]. | |
| 13 */ | |
| 14 Matcher completes = const _Completes(null); | |
|
Siggi Cherem (dart-lang)
2012/06/13 00:04:39
completes => completesWithValue or completesNormal
Bob Nystrom
2012/06/13 20:22:06
Hmm. I see the ambiguity with the current name sin
| |
| 15 | |
| 16 /** | |
| 17 * Matches a [Future] that completes succesfully with a value that matches | |
| 18 * [matcher]. Note that this creates an asynchronous expectation. The call to | |
| 19 * `expect()` that includes this will return immediately and execution will | |
| 20 * continue. Later, when the future completes, the actual expectation will run. | |
| 21 * | |
| 22 * To test that a Future completes with an exception, you can use [throws] and | |
| 23 * [throwsA]. | |
| 24 */ | |
| 25 Matcher completion(matcher) => new _Completes(wrapMatcher(matcher)); | |
|
Siggi Cherem (dart-lang)
2012/06/13 00:04:39
I'm trying to think if there are other names that
Bob Nystrom
2012/06/13 20:22:06
Right, this is what I was thinking too. "completio
Siggi Cherem (dart-lang)
2012/06/13 20:27:20
I guess I like 'completion' less because it is a n
Bob Nystrom
2012/06/13 20:35:51
Yeah, but I think that's consistent with other mat
| |
| 26 | |
| 27 class _Completes extends BaseMatcher { | |
| 28 final Matcher _matcher; | |
| 29 | |
| 30 const _Completes(this._matcher); | |
| 31 | |
| 32 bool matches(item) { | |
| 33 if (item is! Future) return false; | |
|
Siggi Cherem (dart-lang)
2012/06/13 00:04:39
should this by a synchronous expectation (e.g.
Bob Nystrom
2012/06/13 20:22:06
That feels a little confusing since this will be r
| |
| 34 | |
| 35 item.onComplete(expectAsync1((future) { | |
| 36 expect(future.hasValue, | |
| 37 'Expected future to complete successfully, but it failed'); | |
| 38 if (_matcher != null) expect(future.value, _matcher); | |
| 39 })); | |
| 40 | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 Description describe(Description description) { | |
| 45 if (_matcher == null) { | |
| 46 description.add('completes successfully'); | |
| 47 } else { | |
| 48 description.add('completes to a value that ').addDescriptionOf(_matcher); | |
| 49 } | |
| 50 return description; | |
| 51 } | |
| 52 } | |
| OLD | NEW |