| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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("compiler_helper.dart"); | 6 #import("compiler_helper.dart"); |
| 7 | 7 |
| 8 final String NUMBER_FOLDING = """ | 8 final String NUMBER_FOLDING = """ |
| 9 void main() { | 9 void main() { |
| 10 var a = 4; | 10 var a = 4; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 print("foo" + 1); | 35 print("foo" + 1); |
| 36 print("geez" + (-1)); | 36 print("geez" + (-1)); |
| 37 print("bar" + true); | 37 print("bar" + true); |
| 38 print("toto" + false); | 38 print("toto" + false); |
| 39 print("str" + "ingie"); | 39 print("str" + "ingie"); |
| 40 } | 40 } |
| 41 """; | 41 """; |
| 42 | 42 |
| 43 void compileAndTest(String code, String entry, RegExp regexp) { | 43 void compileAndTest(String code, String entry, RegExp regexp) { |
| 44 String generated = compile(code, entry); | 44 String generated = compile(code, entry); |
| 45 Expect.isTrue(regexp.hasMatch(generated)); | 45 Expect.isTrue(regexp.hasMatch(generated), |
| 46 '"$generated" does not match /$regexp/'); |
| 46 } | 47 } |
| 47 | 48 |
| 48 main() { | 49 main() { |
| 49 compileAndTest( | 50 compileAndTest( |
| 50 NUMBER_FOLDING, 'main', const RegExp(@"print\$1\(\(7\)\)")); | 51 NUMBER_FOLDING, 'main', const RegExp(@"print\(\(7\)\)")); |
| 51 compileAndTest( | 52 compileAndTest( |
| 52 NEGATIVE_NUMBER_FOLDING, 'main', const RegExp(@"print\$1\(\(1\)\)")); | 53 NEGATIVE_NUMBER_FOLDING, 'main', const RegExp(@"print\(\(1\)\)")); |
| 53 | 54 |
| 54 String generated = compile(NULL_EQUALS_FOLDING, 'foo'); | 55 String generated = compile(NULL_EQUALS_FOLDING, 'foo'); |
| 55 RegExp regexp = const RegExp(@'eqNull\$1\(a\)'); | 56 RegExp regexp = const RegExp(@'eqNull\(a\)'); |
| 56 Expect.isTrue(regexp.hasMatch(generated)); | 57 Expect.isTrue(regexp.hasMatch(generated)); |
| 57 | 58 |
| 58 regexp = const RegExp(@'\(?void 0\)? === b'); | 59 regexp = const RegExp(@'\(?void 0\)? === b'); |
| 59 Expect.isTrue(regexp.hasMatch(generated)); | 60 Expect.isTrue(regexp.hasMatch(generated)); |
| 60 | 61 |
| 61 regexp = const RegExp(@'\(4\) === c'); | 62 regexp = const RegExp(@'\(4\) === c'); |
| 62 Expect.isTrue(regexp.hasMatch(generated)); | 63 Expect.isTrue(regexp.hasMatch(generated)); |
| 63 | 64 |
| 64 regexp = const RegExp("'foo' === d"); | 65 regexp = const RegExp("'foo' === d"); |
| 65 Expect.isTrue(regexp.hasMatch(generated)); | 66 Expect.isTrue(regexp.hasMatch(generated)); |
| 66 | 67 |
| 67 generated = compile(STRING_FOLDING); | 68 generated = compile(STRING_FOLDING); |
| 68 Expect.isTrue(const RegExp("'foo1'").hasMatch(generated)); | 69 Expect.isTrue(const RegExp("'foo1'").hasMatch(generated)); |
| 69 Expect.isTrue(const RegExp("'geez-1'").hasMatch(generated)); | 70 Expect.isTrue(const RegExp("'geez-1'").hasMatch(generated)); |
| 70 Expect.isTrue(const RegExp("'bartrue'").hasMatch(generated)); | 71 Expect.isTrue(const RegExp("'bartrue'").hasMatch(generated)); |
| 71 Expect.isTrue(const RegExp("'totofalse'").hasMatch(generated)); | 72 Expect.isTrue(const RegExp("'totofalse'").hasMatch(generated)); |
| 72 Expect.isTrue(const RegExp("'stringie'").hasMatch(generated)); | 73 Expect.isTrue(const RegExp("'stringie'").hasMatch(generated)); |
| 73 } | 74 } |
| OLD | NEW |