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

Unified Diff: tests/language/async_switch_test.dart

Issue 976603002: Fix problems with default-cases in async code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | « tests/compiler/dart2js/async_await_js_transform_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/async_switch_test.dart
diff --git a/tests/language/async_switch_test.dart b/tests/language/async_switch_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5e70ad65083c6e7bcc14d0176bb8cb2d57ef7487
--- /dev/null
+++ b/tests/language/async_switch_test.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2015, 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.
+
+import "dart:async";
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+foo1(a) async {
+ int k = 0;
+ switch(a) {
+ case 1:
+ await 3;
+ k += 1;
+ break;
+ case 2:
+ k += a;
+ return k+2;
+ default: k = 2; /// withDefault: ok
+ }
+ return k;
+}
+
+foo2(a) async {
+ int k = 0;
+ switch(await a) {
+ case 1:
+ await 3;
+ k += 1;
+ break;
+ case 2:
+ k += await a;
+ return k+2;
+ default: k = 2; /// withDefault: ok
+ }
+ return k;
+}
+
+foo3(a) async {
+ int k = 0;
+ switch(a) {
+ case 1:
+ k += 1;
+ break;
+ case 2:
+ k += a;
+ return k+2;
+ default: k = 2; /// withDefault: ok
+ }
+ return k;
+}
+
+futureOf(a) async => await a;
+
+test() async {
+ Expect.equals(1, await foo1(1));
+ Expect.equals(4, await foo1(2));
+ Expect.equals(2, await foo1(3)); /// withDefault: ok
+ Expect.equals(0, await foo1(3)); /// none: ok
+ Expect.equals(1, await foo2(futureOf(1)));
+ Expect.equals(4, await foo2(futureOf(2)));
+ Expect.equals(2, await foo2(futureOf(3))); /// withDefault: ok
+ Expect.equals(0, await foo2(futureOf(3))); /// none: ok
+ Expect.equals(1, await foo3(1));
+ Expect.equals(4, await foo3(2));
+ Expect.equals(2, await foo3(3)); /// withDefault: ok
+ Expect.equals(0, await foo3(3)); /// none: ok
+}
+
+void main() {
+ asyncStart();
+ test().then((_) => asyncEnd());
+}
« no previous file with comments | « tests/compiler/dart2js/async_await_js_transform_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698