| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 'compiler_helper.dart'; | 6 import 'compiler_helper.dart'; |
| 7 | 7 |
| 8 const int REMOVED = 0; | 8 const int REMOVED = 0; |
| 9 const int ABOVE_ZERO = 1; | 9 const int ABOVE_ZERO = 1; |
| 10 const int BELOW_LENGTH = 2; | 10 const int BELOW_LENGTH = 2; |
| 11 const int KEPT = 3; | 11 const int KEPT = 3; |
| 12 const int ONE_CHECK = 4; | 12 const int ONE_CHECK = 4; |
| 13 const int ONE_ZERO_CHECK = 5; | 13 const int ONE_ZERO_CHECK = 5; |
| 14 const int BELOW_ZERO_CHECK = 6; | |
| 15 | 14 |
| 16 final List TESTS = [ | 15 final List TESTS = [ |
| 17 """ | 16 """ |
| 18 main() { | 17 main() { |
| 19 var a = new List(); | 18 var a = new List(); |
| 20 var sum = 0; | 19 var sum = 0; |
| 21 for (int i = 0; i < a.length; i++) { | 20 for (int i = 0; i < a.length; i++) { |
| 22 sum += a[i]; | 21 sum += a[i]; |
| 23 } | 22 } |
| 24 return sum; | 23 return sum; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // want an int. | 190 // want an int. |
| 192 int sum = ~value; | 191 int sum = ~value; |
| 193 for (int i = 0; i < 42; i++) sum += (value & 4); | 192 for (int i = 0; i < 42; i++) sum += (value & 4); |
| 194 var a = new List(); | 193 var a = new List(); |
| 195 if (value >= a.length) return; | 194 if (value >= a.length) return; |
| 196 if (value <= -1) return; | 195 if (value <= -1) return; |
| 197 return a[value]; | 196 return a[value]; |
| 198 } | 197 } |
| 199 """, | 198 """, |
| 200 REMOVED, | 199 REMOVED, |
| 201 """ | |
| 202 main(value) { | |
| 203 var a = new List(4); | |
| 204 var sum = 0; | |
| 205 for (int i = 0; i < a.length; i++) { | |
| 206 sum += a[i]; | |
| 207 if (sum == 0) i++; | |
| 208 } | |
| 209 return sum; | |
| 210 } | |
| 211 """, | |
| 212 REMOVED, | |
| 213 """ | |
| 214 main(value) { | |
| 215 var a = new List(5); | |
| 216 var sum = 0; | |
| 217 for (int i = a.length - 1; i >= 0; i--) { | |
| 218 sum += a[i]; | |
| 219 if (sum == 0) i--; | |
| 220 } | |
| 221 return sum; | |
| 222 } | |
| 223 """, | |
| 224 REMOVED, | |
| 225 """ | |
| 226 main(value) { | |
| 227 var a = new List(6); | |
| 228 var sum = 0; | |
| 229 for (int i = 0; i < a.length; i++) { | |
| 230 sum += a[i]; | |
| 231 if (sum == 0) i--; | |
| 232 } | |
| 233 return sum; | |
| 234 } | |
| 235 """, | |
| 236 BELOW_ZERO_CHECK, | |
| 237 """ | |
| 238 main(value) { | |
| 239 var a = new List(7); | |
| 240 var sum = 0; | |
| 241 for (int i = 0; i < a.length;) { | |
| 242 sum += a[i]; | |
| 243 sum == 0 ? i-- : i++; | |
| 244 } | |
| 245 return sum; | |
| 246 } | |
| 247 """, | |
| 248 BELOW_ZERO_CHECK, | |
| 249 ]; | 200 ]; |
| 250 | 201 |
| 251 // TODO(ahe): It would probably be better if this test used the real | 202 // TODO(ahe): It would probably be better if this test used the real |
| 252 // core library sources, as its purpose is to detect failure to | 203 // core library sources, as its purpose is to detect failure to |
| 253 // optimize fixed-sized arrays. | 204 // optimize fixed-sized arrays. |
| 254 const String DEFAULT_CORELIB_WITH_LIST_INTERFACE = r''' | 205 const String DEFAULT_CORELIB_WITH_LIST_INTERFACE = r''' |
| 255 print(var obj) {} | 206 print(var obj) {} |
| 256 abstract class num {} | 207 abstract class num {} |
| 257 abstract class int extends num { } | 208 abstract class int extends num { } |
| 258 abstract class double extends num { } | 209 abstract class double extends num { } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 coreSource: DEFAULT_CORELIB_WITH_LIST_INTERFACE, | 283 coreSource: DEFAULT_CORELIB_WITH_LIST_INTERFACE, |
| 333 interceptorsSource: INTERCEPTORSLIB_WITH_MEMBERS); | 284 interceptorsSource: INTERCEPTORSLIB_WITH_MEMBERS); |
| 334 switch (kind) { | 285 switch (kind) { |
| 335 case REMOVED: | 286 case REMOVED: |
| 336 Expect.isTrue(!generated.contains('ioore')); | 287 Expect.isTrue(!generated.contains('ioore')); |
| 337 break; | 288 break; |
| 338 | 289 |
| 339 case ABOVE_ZERO: | 290 case ABOVE_ZERO: |
| 340 Expect.isTrue(!generated.contains('< 0')); | 291 Expect.isTrue(!generated.contains('< 0')); |
| 341 Expect.isTrue(generated.contains('ioore')); | 292 Expect.isTrue(generated.contains('ioore')); |
| 342 break; | |
| 343 | |
| 344 case BELOW_ZERO_CHECK: | |
| 345 Expect.isTrue(generated.contains('< 0')); | |
| 346 Expect.isTrue(!generated.contains('||')); | |
| 347 Expect.isTrue(generated.contains('ioore')); | 293 Expect.isTrue(generated.contains('ioore')); |
| 348 break; | 294 break; |
| 349 | 295 |
| 350 case BELOW_LENGTH: | 296 case BELOW_LENGTH: |
| 351 Expect.isTrue(!generated.contains('||')); | 297 Expect.isTrue(!generated.contains('||')); |
| 352 Expect.isTrue(generated.contains('ioore')); | 298 Expect.isTrue(generated.contains('ioore')); |
| 353 break; | 299 break; |
| 354 | 300 |
| 355 case KEPT: | 301 case KEPT: |
| 356 Expect.isTrue(generated.contains('ioore')); | 302 Expect.isTrue(generated.contains('ioore')); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 369 break; | 315 break; |
| 370 } | 316 } |
| 371 } | 317 } |
| 372 | 318 |
| 373 | 319 |
| 374 main() { | 320 main() { |
| 375 for (int i = 0; i < TESTS.length; i += 2) { | 321 for (int i = 0; i < TESTS.length; i += 2) { |
| 376 expect(TESTS[i], TESTS[i + 1]); | 322 expect(TESTS[i], TESTS[i + 1]); |
| 377 } | 323 } |
| 378 } | 324 } |
| OLD | NEW |