OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import "package:async_helper/async_helper.dart"; | 6 import "package:async_helper/async_helper.dart"; |
7 | 7 |
8 // Two loop variables | 8 // Two loop variables |
9 test1() async { | 9 test1() async { |
10 var r = 0; | 10 var r = 0; |
11 label: | 11 label: |
12 for (var i = 1, | 12 for(var i = 1, j = |
13 j = | |
14 await //# await_in_init: ok | 13 await //# await_in_init: ok |
15 10; | 14 10; i < 10 && j > |
16 i < 10 && | |
17 j > | |
18 await //# await_in_condition: ok | 15 await //# await_in_condition: ok |
19 -5; | 16 -5; j--, i += |
20 j--, | |
21 i += | |
22 await //# await_in_update: ok | 17 await //# await_in_update: ok |
23 1) { | 18 1) { |
24 if (i < | 19 if (i < |
25 await //# await_in_body: ok | 20 await //# await_in_body: ok |
26 5 || | 21 5 || j < -5) { |
27 j < -5) { | |
28 continue label; | 22 continue label; |
29 } | 23 } |
30 r++; | 24 r++; |
31 } | 25 } |
32 Expect.equals(5, r); | 26 Expect.equals(5, r); |
33 } | 27 } |
34 | 28 |
35 // One loop variable | 29 // One loop variable |
36 test2() async { | 30 test2() async { |
37 var r = 0; | 31 var r = 0; |
38 label: | 32 label: |
39 for (var i = | 33 for(var i = |
40 await //# await_in_init: ok | 34 await //# await_in_init: ok |
41 0; | 35 0; i < |
42 i < | |
43 await //# await_in_condition: ok | 36 await //# await_in_condition: ok |
44 10; | 37 10; i += |
45 i += | |
46 await //# await_in_update: ok | 38 await //# await_in_update: ok |
47 1) { | 39 1) { |
48 if (i < | 40 if (i < |
49 await //# await_in_body: ok | 41 await //# await_in_body: ok |
50 5) { | 42 5) { |
51 continue label; | 43 continue label; |
52 } | 44 } |
53 r++; | 45 r++; |
54 } | 46 } |
55 Expect.equals(5, r); | 47 Expect.equals(5, r); |
56 } | 48 } |
57 | 49 |
58 // Variable not declared in initializer; | 50 // Variable not declared in initializer; |
59 test3() async { | 51 test3() async { |
60 var r = 0, i, j; | 52 var r = 0, i, j; |
61 label: | 53 label: |
62 for (i = | 54 for(i = |
63 await //# await_in_init: ok | 55 await //# await_in_init: ok |
64 0; | 56 0; i < |
65 i < | |
66 await //# await_in_condition: ok | 57 await //# await_in_condition: ok |
67 10; | 58 10; i += |
68 i += | |
69 await //# await_in_update: ok | 59 await //# await_in_update: ok |
70 1) { | 60 1) { |
71 if (i < | 61 if (i < |
72 await //# await_in_body: ok | 62 await //# await_in_body: ok |
73 5) { | 63 5) { |
74 continue label; | 64 continue label; |
75 } | 65 } |
76 r++; | 66 r++; |
77 } | 67 } |
78 Expect.equals(5, r); | 68 Expect.equals(5, r); |
79 } | 69 } |
80 | 70 |
81 // Nested loop | 71 // Nested loop |
82 test4() async { | 72 test4() async { |
83 var r = 0; | 73 var r = 0; |
84 label: | 74 label: |
85 for (var i = | 75 for(var i = |
86 await //# await_in_init: ok | 76 await //# await_in_init: ok |
87 0; | 77 0; i < |
88 i < | |
89 await //# await_in_condition: ok | 78 await //# await_in_condition: ok |
90 10; | 79 10; i+= |
91 i += | |
92 await //# await_in_update: ok | 80 await //# await_in_update: ok |
93 1) { | 81 1) { |
94 if (i < | 82 if (i < |
95 await //# await_in_body: ok | 83 await //# await_in_body: ok |
96 5) { | 84 5) { |
97 for (int i = 0; i < 10; i++) { | 85 for (int i = 0; i < 10; i++) { |
98 continue label; | 86 continue label; |
99 } | 87 } |
100 } | 88 } |
101 r++; | 89 r++; |
102 } | 90 } |
103 Expect.equals(5, r); | 91 Expect.equals(5, r); |
104 } | 92 } |
105 | 93 |
106 test() async { | 94 test() async { |
107 await test1(); | 95 await test1(); |
108 await test2(); | 96 await test2(); |
109 await test3(); | 97 await test3(); |
110 await test4(); | 98 await test4(); |
111 } | 99 } |
112 | 100 |
113 main() { | 101 main() { |
114 asyncStart(); | 102 asyncStart(); |
115 test().then((_) => asyncEnd()); | 103 test().then((_) => asyncEnd()); |
116 } | 104 } |
OLD | NEW |