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

Unified Diff: tests/lib/async/future_test.dart

Issue 1177343004: Add Stream.empty. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Remove the null future "optimization". Fix some missing type parameters. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | tests/lib/async/stream_empty_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/future_test.dart
diff --git a/tests/lib/async/future_test.dart b/tests/lib/async/future_test.dart
index 900eea65c3cb2524111728aa9aaec4a0056ba8e6..030340d6468ed9686aee59e2df9a672c5f35a050 100644
--- a/tests/lib/async/future_test.dart
+++ b/tests/lib/async/future_test.dart
@@ -882,7 +882,7 @@ void testBadFuture() {
asyncStart();
Completer completer = new Completer();
completer.complete(bad);
- completer.future.then((_) { fail("unreachable"); },
+ completer.future.then((_) { Expect.fail("unreachable"); },
onError: (e, s) {
Expect.isTrue(completer.isCompleted);
asyncEnd();
@@ -890,12 +890,42 @@ void testBadFuture() {
asyncStart();
var f = new Future.value().then((_) => bad);
- f.then((_) { fail("unreachable"); },
+ f.then((_) { Expect.fail("unreachable"); },
onError: (e, s) {
asyncEnd();
});
}
+void testTypes() {
+ // Test that future is a Future<int> and not something less precise.
+ testType(name, future, [depth = 2]) {
+ var desc = "$name${".whenComplete"*(2-depth)}";
+ Expect.isTrue(future is Future<int>, "$desc is Future<int>");
+ Expect.isFalse(future is Future<String>, "$desc is! Future<String>");
+ var stream = future.asStream();
+ Expect.isTrue(stream is Stream<int>, "$desc.asStream() is Stream<int>");
+ Expect.isFalse(stream is Stream<String>,
+ "$desc.asStream() is! Stream<String>");
+ if (depth > 0) {
+ testType(name, future.whenComplete((){}), depth - 1);
+ }
+ }
+ for (var value in [42, null]) {
+ testType("Future($value)",
+ new Future<int>(() => value));
+ testType("Future.delayed($value)",
+ new Future<int>.delayed(Duration.ZERO, () => value));
+ testType("Future.microtask($value)",
+ new Future<int>.microtask(() => value));
+ testType("Future.sync($value)", new Future<int>.sync(() => value)); /// 01: ok
+ testType("Future.sync(future($value))", /// 01: continued
+ new Future<int>.sync(() async => new Future.value(value))); /// 01: continued
+ testType("Future.value($value)", new Future<int>.value(value));
+ }
+ testType("Completer.future", new Completer<int>().future);
+ testType("Future.error", new Future<int>.error("ERR")..catchError((_){}));
+}
+
main() {
asyncStart();
@@ -957,6 +987,8 @@ main() {
testBadFuture();
+ testTypes();
+
asyncEnd();
}
@@ -977,13 +1009,19 @@ class CustomFuture<T> implements Future<T> {
}
class BadFuture<T> implements Future<T> {
- Future then(action(result)) {
+ Future then(action(T result), {Function onError}) {
throw "then GOTCHA!";
}
- Future catchError(Function onError) {
+ Future catchError(Function onError, {bool test(e)}) {
throw "catch GOTCHA!";
}
Future whenComplete(action()) {
throw "finally GOTCHA!";
}
+ Stream<T> asStream() {
+ throw "asStream GOTCHA!";
+ }
+ Future timeout(Duration duration, {onTimeout()}) {
+ throw "timeout GOTCHA!";
+ }
}
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | tests/lib/async/stream_empty_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698