| OLD | NEW |
| (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 // Tests of control flow statements. | |
| 6 | |
| 7 library control_flow_tests; | |
| 8 | |
| 9 import 'js_backend_cps_ir.dart'; | |
| 10 | |
| 11 const List<TestEntry> tests = const [ | |
| 12 const TestEntry(""" | |
| 13 main() { | |
| 14 while (true); | |
| 15 } | |
| 16 """, """ | |
| 17 function() { | |
| 18 while (true) | |
| 19 ; | |
| 20 }"""), | |
| 21 const TestEntry(""" | |
| 22 foo(a) { print(a); return a; } | |
| 23 | |
| 24 main() { | |
| 25 while (true) { | |
| 26 l: while (true) { | |
| 27 while (foo(true)) { | |
| 28 if (foo(false)) break l; | |
| 29 } | |
| 30 print(1); | |
| 31 } | |
| 32 print(2); | |
| 33 } | |
| 34 } | |
| 35 """, """ | |
| 36 function() { | |
| 37 L1: | |
| 38 while (true) | |
| 39 L0: | |
| 40 while (true) | |
| 41 while (true) { | |
| 42 P.print(true); | |
| 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 } | |
| 52 } | |
| 53 }"""), | |
| 54 const TestEntry(""" | |
| 55 foo(a) { print(a); return a; } | |
| 56 | |
| 57 main() { | |
| 58 for (int i = 0; foo(true); i = foo(i)) { | |
| 59 print(1); | |
| 60 if (foo(false)) break; | |
| 61 } | |
| 62 print(2); | |
| 63 }""", """ | |
| 64 function() { | |
| 65 while (true) { | |
| 66 P.print(true); | |
| 67 if (true === true) { | |
| 68 P.print(1); | |
| 69 P.print(false); | |
| 70 if (false !== true) { | |
| 71 P.print(0); | |
| 72 continue; | |
| 73 } | |
| 74 } | |
| 75 P.print(2); | |
| 76 return null; | |
| 77 } | |
| 78 }"""), | |
| 79 const TestEntry(""" | |
| 80 foo(a) { print(a); return a; } | |
| 81 | |
| 82 main() { | |
| 83 foo(false); | |
| 84 if (foo(true)) { | |
| 85 print(1); | |
| 86 } else { | |
| 87 print(2); | |
| 88 } | |
| 89 print(3); | |
| 90 }""", """ | |
| 91 function() { | |
| 92 P.print(false); | |
| 93 P.print(true); | |
| 94 true ? P.print(1) : P.print(2); | |
| 95 P.print(3); | |
| 96 }"""), | |
| 97 const TestEntry(""" | |
| 98 foo(a) { print(a); return a; } | |
| 99 | |
| 100 main() { | |
| 101 foo(false); | |
| 102 if (foo(true)) { | |
| 103 print(1); | |
| 104 print(1); | |
| 105 } else { | |
| 106 print(2); | |
| 107 print(2); | |
| 108 } | |
| 109 print(3); | |
| 110 }""", """ | |
| 111 function() { | |
| 112 P.print(false); | |
| 113 P.print(true); | |
| 114 if (true) { | |
| 115 P.print(1); | |
| 116 P.print(1); | |
| 117 } else { | |
| 118 P.print(2); | |
| 119 P.print(2); | |
| 120 } | |
| 121 P.print(3); | |
| 122 }"""), | |
| 123 const TestEntry(""" | |
| 124 main() { | |
| 125 if (1) { | |
| 126 print('bad'); | |
| 127 } else { | |
| 128 print('good'); | |
| 129 } | |
| 130 }""",""" | |
| 131 function() { | |
| 132 P.print("good"); | |
| 133 }"""), | |
| 134 const TestEntry(""" | |
| 135 foo() { print('2'); return 2; } | |
| 136 main() { | |
| 137 if (foo()) { | |
| 138 print('bad'); | |
| 139 } else { | |
| 140 print('good'); | |
| 141 } | |
| 142 }""",""" | |
| 143 function() { | |
| 144 P.print("2"); | |
| 145 P.print("good"); | |
| 146 }"""), | |
| 147 const TestEntry(""" | |
| 148 main() { | |
| 149 var list = [1,2,3,4,5,6]; | |
| 150 for (var x in list) { | |
| 151 print(x); | |
| 152 } | |
| 153 }""",r""" | |
| 154 function() { | |
| 155 var list = [1, 2, 3, 4, 5, 6], i = 0, v0; | |
| 156 for (; i < 6; ++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 } | |
| 168 }"""), | |
| 169 const TestEntry(""" | |
| 170 main() { | |
| 171 var xs = ['x', 'y', 'z'], ys = ['A', 'B', 'C']; | |
| 172 var xit = xs.iterator, yit = ys.iterator; | |
| 173 while (xit.moveNext() && yit.moveNext()) { | |
| 174 print(xit.current); | |
| 175 print(yit.current); | |
| 176 } | |
| 177 }""",r""" | |
| 178 function() { | |
| 179 var xs = ["x", "y", "z"], ys = ["A", "B", "C"], i = 0, i1 = 0, current, curren
t1; | |
| 180 for (; i < 3; ++i, ++i1) { | |
| 181 current = xs[i]; | |
| 182 if (!(i1 < 3)) | |
| 183 break; | |
| 184 current1 = ys[i1]; | |
| 185 P.print(current); | |
| 186 P.print(current1); | |
| 187 } | |
| 188 }"""), | |
| 189 ]; | |
| 190 | |
| 191 void main() { | |
| 192 runTests(tests); | |
| 193 } | |
| OLD | NEW |