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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/compiler/dart2js/async_await_js_transform_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 import "dart:async";
6 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart";
8
9 foo1(a) async {
10 int k = 0;
11 switch(a) {
12 case 1:
13 await 3;
14 k += 1;
15 break;
16 case 2:
17 k += a;
18 return k+2;
19 default: k = 2; /// withDefault: ok
20 }
21 return k;
22 }
23
24 foo2(a) async {
25 int k = 0;
26 switch(await a) {
27 case 1:
28 await 3;
29 k += 1;
30 break;
31 case 2:
32 k += await a;
33 return k+2;
34 default: k = 2; /// withDefault: ok
35 }
36 return k;
37 }
38
39 foo3(a) async {
40 int k = 0;
41 switch(a) {
42 case 1:
43 k += 1;
44 break;
45 case 2:
46 k += a;
47 return k+2;
48 default: k = 2; /// withDefault: ok
49 }
50 return k;
51 }
52
53 futureOf(a) async => await a;
54
55 test() async {
56 Expect.equals(1, await foo1(1));
57 Expect.equals(4, await foo1(2));
58 Expect.equals(2, await foo1(3)); /// withDefault: ok
59 Expect.equals(0, await foo1(3)); /// none: ok
60 Expect.equals(1, await foo2(futureOf(1)));
61 Expect.equals(4, await foo2(futureOf(2)));
62 Expect.equals(2, await foo2(futureOf(3))); /// withDefault: ok
63 Expect.equals(0, await foo2(futureOf(3))); /// none: ok
64 Expect.equals(1, await foo3(1));
65 Expect.equals(4, await foo3(2));
66 Expect.equals(2, await foo3(3)); /// withDefault: ok
67 Expect.equals(0, await foo3(3)); /// none: ok
68 }
69
70 void main() {
71 asyncStart();
72 test().then((_) => asyncEnd());
73 }
OLDNEW
« 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