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

Side by Side Diff: tests/language/async_control_structures_test.dart

Issue 2985173002: Migrate language/async_backwards... ... language/async_star_take... (Closed)
Patch Set: Update tests to Dart 2.0. Created 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014, 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 // VMOptions=--optimization-counter-threshold=10 --no-background-compilation
6
7 import 'package:expect/expect.dart';
8
9 import 'dart:async';
10
11 expectThenValue(future, value) {
12 Expect.isTrue(future is Future);
13 future.then((result) {
14 Expect.equals(value, result);
15 });
16 }
17
18 asyncIf(condition) async {
19 if (condition) {
20 return 1;
21 } else {
22 return 2;
23 }
24 // This return is never reached as the finally block returns from the
25 // function.
26 return 3;
27 }
28
29 asyncFor(condition) async {
30 for (int i = 0; i < 10; i++) {
31 if (i == 5 && condition) {
32 return 1;
33 }
34 }
35 return 2;
36 }
37
38 asyncTryCatchFinally(overrideInFinally, doThrow) async {
39 try {
40 if (doThrow) throw 444;
41 return 1;
42 } catch (e) {
43 return e;
44 } finally {
45 if (overrideInFinally) return 3;
46 }
47 }
48
49 asyncTryCatchLoop() async {
50 var i = 0;
51 var throws = 13;
52 while (true) {
53 try {
54 throw throws;
55 } catch (e) {
56 if (i == throws) {
57 return e;
58 }
59 } finally {
60 i++;
61 }
62 }
63 }
64
65 asyncImplicitReturn() async {
66 try {} catch (e) {} finally {}
67 }
68
69 main() {
70 var asyncReturn;
71
72 for (int i = 0; i < 10; i++) {
73 asyncReturn = asyncIf(true);
74 expectThenValue(asyncReturn, 1);
75 asyncReturn = asyncIf(false);
76 expectThenValue(asyncReturn, 2);
77
78 asyncReturn = asyncFor(true);
79 expectThenValue(asyncReturn, 1);
80 asyncReturn = asyncFor(false);
81 expectThenValue(asyncReturn, 2);
82
83 asyncReturn = asyncTryCatchFinally(true, false);
84 expectThenValue(asyncReturn, 3);
85 asyncReturn = asyncTryCatchFinally(false, false);
86 expectThenValue(asyncReturn, 1);
87 asyncReturn = asyncTryCatchFinally(true, true);
88 expectThenValue(asyncReturn, 3);
89 asyncReturn = asyncTryCatchFinally(false, true);
90 expectThenValue(asyncReturn, 444);
91 asyncReturn = asyncTryCatchLoop();
92 expectThenValue(asyncReturn, 13);
93
94 asyncReturn = asyncImplicitReturn();
95 expectThenValue(asyncReturn, null);
96 }
97 }
OLDNEW
« no previous file with comments | « tests/language/async_continue_label_test.dart ('k') | tests/language/async_finally_rethrow_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698