| 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 // Test constant folding on numbers. | 4 // Test constant folding on numbers. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import 'dart:async'; |
| 7 import 'package:expect/expect.dart'; |
| 8 import 'package:async_helper/async_helper.dart'; |
| 7 import 'compiler_helper.dart'; | 9 import 'compiler_helper.dart'; |
| 8 | 10 |
| 9 const String NUMBER_FOLDING = """ | 11 const String NUMBER_FOLDING = """ |
| 10 void main() { | 12 void main() { |
| 11 var a = 4; | 13 var a = 4; |
| 12 var b = 3; | 14 var b = 3; |
| 13 print(a + b); | 15 print(a + b); |
| 14 } | 16 } |
| 15 """; | 17 """; |
| 16 | 18 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 51 } |
| 50 """; | 52 """; |
| 51 | 53 |
| 52 const String RANGE_ERROR_INDEX_FOLDING = """ | 54 const String RANGE_ERROR_INDEX_FOLDING = """ |
| 53 foo() { | 55 foo() { |
| 54 return [1][1]; | 56 return [1][1]; |
| 55 } | 57 } |
| 56 """; | 58 """; |
| 57 | 59 |
| 58 main() { | 60 main() { |
| 59 compileAndMatch( | 61 asyncTest(() => Future.wait([ |
| 60 NUMBER_FOLDING, 'main', new RegExp(r"print\(7\)")); | 62 compileAndMatch( |
| 61 compileAndMatch( | 63 NUMBER_FOLDING, 'main', new RegExp(r"print\(7\)")), |
| 62 NEGATIVE_NUMBER_FOLDING, 'main', new RegExp(r"print\(1\)")); | 64 compileAndMatch( |
| 65 NEGATIVE_NUMBER_FOLDING, 'main', new RegExp(r"print\(1\)")), |
| 63 | 66 |
| 64 String generated = compile(NULL_EQUALS_FOLDING, entry: 'foo'); | 67 compile(NULL_EQUALS_FOLDING, entry: 'foo', check: (String generated) { |
| 65 RegExp regexp = new RegExp(r'a == null'); | 68 RegExp regexp = new RegExp(r'a == null'); |
| 66 Expect.isTrue(regexp.hasMatch(generated)); | 69 Expect.isTrue(regexp.hasMatch(generated)); |
| 67 | 70 |
| 68 regexp = new RegExp(r'null == b'); | 71 regexp = new RegExp(r'null == b'); |
| 69 Expect.isTrue(regexp.hasMatch(generated)); | 72 Expect.isTrue(regexp.hasMatch(generated)); |
| 70 | 73 |
| 71 regexp = new RegExp(r'4 === c'); | 74 regexp = new RegExp(r'4 === c'); |
| 72 Expect.isTrue(regexp.hasMatch(generated)); | 75 Expect.isTrue(regexp.hasMatch(generated)); |
| 73 | 76 |
| 74 regexp = new RegExp('"foo" === d'); | 77 regexp = new RegExp('"foo" === d'); |
| 75 Expect.isTrue(regexp.hasMatch(generated)); | 78 Expect.isTrue(regexp.hasMatch(generated)); |
| 79 }), |
| 76 | 80 |
| 77 compileAndMatch( | 81 compileAndMatch( |
| 78 LIST_LENGTH_FOLDING, 'foo', new RegExp(r"return 3")); | 82 LIST_LENGTH_FOLDING, 'foo', new RegExp(r"return 3")), |
| 79 | 83 |
| 80 compileAndMatch( | 84 compileAndMatch( |
| 81 LIST_INDEX_FOLDING, 'foo', new RegExp(r"return 1")); | 85 LIST_INDEX_FOLDING, 'foo', new RegExp(r"return 1")), |
| 82 | 86 |
| 83 compileAndDoNotMatch( | 87 compileAndDoNotMatch( |
| 84 LIST_INDEX_FOLDING, 'foo', new RegExp(r"ioore")); | 88 LIST_INDEX_FOLDING, 'foo', new RegExp(r"ioore")), |
| 85 | 89 |
| 86 compileAndMatch( | 90 compileAndMatch( |
| 87 STRING_LENGTH_FOLDING, 'foo', new RegExp(r"return 3")); | 91 STRING_LENGTH_FOLDING, 'foo', new RegExp(r"return 3")), |
| 88 | 92 |
| 89 compileAndMatch( | 93 compileAndMatch( |
| 90 RANGE_ERROR_INDEX_FOLDING, 'foo', new RegExp(r"ioore")); | 94 RANGE_ERROR_INDEX_FOLDING, 'foo', new RegExp(r"ioore")), |
| 95 ])); |
| 91 } | 96 } |
| OLD | NEW |