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

Unified Diff: tests/language/await_future_test.dart

Issue 484933003: Await it! (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 6 years, 4 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 | « runtime/vm/symbols.h ('k') | tests/standalone/issue14236_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/await_future_test.dart
diff --git a/tests/language/await_future_test.dart b/tests/language/await_future_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9811f37f171181069532add2933a3c9748fa6ce6
--- /dev/null
+++ b/tests/language/await_future_test.dart
@@ -0,0 +1,61 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// VMOptions=--enable_async --optimization-counter-threshold=5
+
+import 'package:expect/expect.dart';
+
+import 'dart:async';
+
+// It does not matter where a future is generated.
+bar(p) async => p;
+baz(p) => new Future(() => p);
+
+foo() async {
+ var b = 0;
+ for(int i = 0; i < 10; i++) {
+ b += (await bar(1)) + (await baz(2));
+ }
+ return b;
+}
+
+quaz(p) async {
+ var x = 0;
+ try {
+ for (var j = 0; j < 10; j++) {
+ x += await baz(j);
+ }
+ return x;
+ } finally {
+ Expect.equals(x, 45);
+ return p;
+ }
+}
+
+quazz() async {
+ var x = 0;
+ try {
+ try {
+ x = await bar(1);
+ throw x;
+ } catch (e1) {
+ var y = await baz(e1 + 1);
+ throw y;
+ }
+ } catch (e2) {
+ return e2;
+ }
+}
+
+main() async {
+ var result;
+ for (int i = 0; i < 10; i++) {
+ result = await foo();
+ Expect.equals(result, 30);
+ result = await quaz(17);
+ Expect.equals(result, 17);
+ result = await quazz();
+ Expect.equals(result, 2);
+ }
+}
« no previous file with comments | « runtime/vm/symbols.h ('k') | tests/standalone/issue14236_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698