OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Tests of control flow statements. | 5 // Tests of control flow statements. |
6 | 6 |
7 library control_flow_tests; | 7 library control_flow_tests; |
8 | 8 |
9 import 'js_backend_cps_ir.dart'; | 9 import 'js_backend_cps_ir.dart'; |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 while (foo(true)) { | 27 while (foo(true)) { |
28 if (foo(false)) break l; | 28 if (foo(false)) break l; |
29 } | 29 } |
30 print(1); | 30 print(1); |
31 } | 31 } |
32 print(2); | 32 print(2); |
33 } | 33 } |
34 } | 34 } |
35 """, """ | 35 """, """ |
36 function() { | 36 function() { |
37 L0: | 37 L1: |
38 while (true) | 38 while (true) |
39 while (true) { | 39 L0: |
40 while (V.foo(true)) | 40 while (true) |
41 if (V.foo(false)) { | 41 while (true) { |
42 P.print(2); | 42 P.print(true); |
43 continue L0; | 43 if (false) { |
| 44 P.print(1); |
| 45 continue L0; |
| 46 } |
| 47 P.print(false); |
| 48 if (false) { |
| 49 P.print(2); |
| 50 continue L1; |
| 51 } |
44 } | 52 } |
45 P.print(1); | |
46 } | |
47 }"""), | 53 }"""), |
48 const TestEntry(""" | 54 const TestEntry(""" |
49 foo(a) { print(a); return a; } | 55 foo(a) { print(a); return a; } |
50 | 56 |
51 main() { | 57 main() { |
52 for (int i = 0; foo(true); i = foo(i)) { | 58 for (int i = 0; foo(true); i = foo(i)) { |
53 print(1); | 59 print(1); |
54 if (foo(false)) break; | 60 if (foo(false)) break; |
55 } | 61 } |
56 print(2); | 62 print(2); |
57 }""", """ | 63 }""", """ |
58 function() { | 64 function() { |
59 var i = 0; | 65 while (true) { |
60 for (; V.foo(true) === true; i = V.foo(i)) { | 66 P.print(true); |
61 P.print(1); | 67 if (true === true) { |
62 if (V.foo(false) === true) | 68 P.print(1); |
63 break; | 69 P.print(false); |
| 70 if (false !== true) { |
| 71 P.print(0); |
| 72 continue; |
| 73 } |
| 74 } |
| 75 P.print(2); |
| 76 return null; |
64 } | 77 } |
65 P.print(2); | |
66 }"""), | 78 }"""), |
67 const TestEntry(""" | 79 const TestEntry(""" |
68 foo(a) { print(a); return a; } | 80 foo(a) { print(a); return a; } |
69 | 81 |
70 main() { | 82 main() { |
71 foo(false); | 83 foo(false); |
72 if (foo(true)) { | 84 if (foo(true)) { |
73 print(1); | 85 print(1); |
74 } else { | 86 } else { |
75 print(2); | 87 print(2); |
76 } | 88 } |
77 print(3); | 89 print(3); |
78 }""", """ | 90 }""", """ |
79 function() { | 91 function() { |
80 V.foo(false); | 92 P.print(false); |
81 V.foo(true) ? P.print(1) : P.print(2); | 93 P.print(true); |
| 94 true ? P.print(1) : P.print(2); |
82 P.print(3); | 95 P.print(3); |
83 }"""), | 96 }"""), |
84 const TestEntry(""" | 97 const TestEntry(""" |
85 foo(a) { print(a); return a; } | 98 foo(a) { print(a); return a; } |
86 | 99 |
87 main() { | 100 main() { |
88 foo(false); | 101 foo(false); |
89 if (foo(true)) { | 102 if (foo(true)) { |
90 print(1); | 103 print(1); |
91 print(1); | 104 print(1); |
92 } else { | 105 } else { |
93 print(2); | 106 print(2); |
94 print(2); | 107 print(2); |
95 } | 108 } |
96 print(3); | 109 print(3); |
97 }""", """ | 110 }""", """ |
98 function() { | 111 function() { |
99 V.foo(false); | 112 P.print(false); |
100 if (V.foo(true)) { | 113 P.print(true); |
| 114 if (true) { |
101 P.print(1); | 115 P.print(1); |
102 P.print(1); | 116 P.print(1); |
103 } else { | 117 } else { |
104 P.print(2); | 118 P.print(2); |
105 P.print(2); | 119 P.print(2); |
106 } | 120 } |
107 P.print(3); | 121 P.print(3); |
108 }"""), | 122 }"""), |
109 const TestEntry(""" | 123 const TestEntry(""" |
110 main() { | 124 main() { |
111 if (1) { | 125 if (1) { |
112 print('bad'); | 126 print('bad'); |
113 } else { | 127 } else { |
114 print('good'); | 128 print('good'); |
115 } | 129 } |
116 }""",""" | 130 }""",""" |
117 function() { | 131 function() { |
118 P.print("good"); | 132 P.print("good"); |
119 }"""), | 133 }"""), |
120 const TestEntry(""" | 134 const TestEntry(""" |
121 foo() { print('2'); return 2; } | 135 foo() { print('2'); return 2; } |
122 main() { | 136 main() { |
123 if (foo()) { | 137 if (foo()) { |
124 print('bad'); | 138 print('bad'); |
125 } else { | 139 } else { |
126 print('good'); | 140 print('good'); |
127 } | 141 } |
128 }""",""" | 142 }""",""" |
129 function() { | 143 function() { |
130 V.foo(); | 144 P.print("2"); |
131 P.print("good"); | 145 P.print("good"); |
132 }"""), | 146 }"""), |
133 const TestEntry(""" | 147 const TestEntry(""" |
134 main() { | 148 main() { |
135 var list = [1,2,3,4,5,6]; | 149 var list = [1,2,3,4,5,6]; |
136 for (var x in list) { | 150 for (var x in list) { |
137 print(x); | 151 print(x); |
138 } | 152 } |
139 }""",r""" | 153 }""",r""" |
140 function() { | 154 function() { |
141 var list = [1, 2, 3, 4, 5, 6], i = 0; | 155 var list = [1, 2, 3, 4, 5, 6], i = 0, v0; |
142 for (; i < 6; i = i + 1) | 156 for (; i < 6; i = i + 1) { |
143 P.print(list[i]); | 157 v0 = H.S(list[i]); |
| 158 if (typeof dartPrint == "function") |
| 159 dartPrint(v0); |
| 160 else if (typeof console == "object" && typeof console.log != "undefined") |
| 161 console.log(v0); |
| 162 else if (!(typeof window == "object")) { |
| 163 if (!(typeof print == "function")) |
| 164 throw "Unable to print message: " + String(v0); |
| 165 print(v0); |
| 166 } |
| 167 } |
144 }"""), | 168 }"""), |
145 const TestEntry(""" | 169 const TestEntry(""" |
146 main() { | 170 main() { |
147 var xs = ['x', 'y', 'z'], ys = ['A', 'B', 'C']; | 171 var xs = ['x', 'y', 'z'], ys = ['A', 'B', 'C']; |
148 var xit = xs.iterator, yit = ys.iterator; | 172 var xit = xs.iterator, yit = ys.iterator; |
149 while (xit.moveNext() && yit.moveNext()) { | 173 while (xit.moveNext() && yit.moveNext()) { |
150 print(xit.current); | 174 print(xit.current); |
151 print(yit.current); | 175 print(yit.current); |
152 } | 176 } |
153 }""",r""" | 177 }""",r""" |
154 function() { | 178 function() { |
155 var xs = ["x", "y", "z"], ys = ["A", "B", "C"], i = 0, i1 = 0, current, curren
t1; | 179 var xs = ["x", "y", "z"], ys = ["A", "B", "C"], i = 0, i1 = 0, current, curren
t1; |
156 for (; i < 3; i = i + 1, i1 = i1 + 1) { | 180 for (; i < 3; i = i + 1, i1 = i1 + 1) { |
157 current = xs[i]; | 181 current = xs[i]; |
158 if (!(i1 < 3)) | 182 if (!(i1 < 3)) |
159 break; | 183 break; |
160 current1 = ys[i1]; | 184 current1 = ys[i1]; |
161 P.print(current); | 185 P.print(current); |
162 P.print(current1); | 186 P.print(current1); |
163 } | 187 } |
164 }"""), | 188 }"""), |
165 ]; | 189 ]; |
166 | 190 |
167 void main() { | 191 void main() { |
168 runTests(tests); | 192 runTests(tests); |
169 } | 193 } |
OLD | NEW |