| 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 that parameters keep their names in the output. | 4 // Test that parameters keep their names in the output. |
| 5 | 5 |
| 6 #import("compiler_helper.dart"); | 6 #import("compiler_helper.dart"); |
| 7 | 7 |
| 8 const String TEST_ONE = r""" | 8 const String TEST_ONE = r""" |
| 9 void foo(bar) { | 9 void foo(bar) { |
| 10 var a = 1; | 10 var a = 1; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 if (c) { | 35 if (c) { |
| 36 val = 43; | 36 val = 43; |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 return val; | 39 return val; |
| 40 } | 40 } |
| 41 """; | 41 """; |
| 42 | 42 |
| 43 const String TEST_FOUR = r""" | 43 const String TEST_FOUR = r""" |
| 44 foo() { | 44 foo() { |
| 45 var cond1 = true; | 45 var a = true; |
| 46 var cond2 = false; | 46 var b = false; |
| 47 for (var i = 0; cond1; i = i + 1) { | 47 for (var i = 0; a; i = i + 1) { |
| 48 if (i == 9) cond1 = false; | 48 if (i == 9) a = false; |
| 49 for (var j = 0; cond2; j = j + 1) { | 49 for (var j = 0; b; j = j + 1) { |
| 50 if (j == 9) cond2 = false; | 50 if (j == 9) b = false; |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 print(cond1); | 53 print(a); |
| 54 print(cond2); | 54 print(b); |
| 55 } | 55 } |
| 56 """; | 56 """; |
| 57 | 57 |
| 58 main() { | 58 main() { |
| 59 String generated = compile(TEST_ONE, 'foo'); | 59 compileAndMatchFuzzy(TEST_ONE, 'foo', "var x = x === true \\? 2 : 3;"); |
| 60 Expect.isTrue(generated.contains('var a = bar === true ? 2 : 3;')); | 60 compileAndMatchFuzzy(TEST_ONE, 'foo', "print\\(x\\);"); |
| 61 Expect.isTrue(generated.contains('print(a);')); | |
| 62 | 61 |
| 63 generated = compile(TEST_TWO, 'main'); | 62 compileAndMatchFuzzy(TEST_TWO, 'main', "x \\+= 10"); |
| 64 RegExp regexp = new RegExp("t \\+= 10"); | 63 compileAndMatchFuzzy(TEST_TWO, 'main', "\\+\\+x"); |
| 65 Expect.isTrue(regexp.hasMatch(generated)); | |
| 66 | 64 |
| 67 regexp = new RegExp("\\+\\+i"); | 65 // Check that we don't have 'd = d' (using regexp back references). |
| 68 Expect.isTrue(regexp.hasMatch(generated)); | 66 compileAndDoNotMatchFuzzy(TEST_THREE, 'foo', '(x) = \1'); |
| 69 | 67 compileAndMatchFuzzy(TEST_THREE, 'foo', 'return x'); |
| 70 generated = compile(TEST_THREE, 'foo'); | |
| 71 | |
| 72 // Check that we don't have 'val = val'. | |
| 73 regexp = const RegExp("val = val;"); | |
| 74 Expect.isTrue(!regexp.hasMatch(generated)); | |
| 75 | |
| 76 regexp = const RegExp("return val"); | |
| 77 Expect.isTrue(regexp.hasMatch(generated)); | |
| 78 // Check that a store just after the declaration of the local | 68 // Check that a store just after the declaration of the local |
| 79 // only generates one instruction. | 69 // only generates one instruction. |
| 80 regexp = const RegExp(r"val = 42"); | 70 compileAndMatchFuzzy(TEST_THREE, 'foo', 'x = 42'); |
| 81 Expect.isTrue(regexp.hasMatch(generated)); | |
| 82 | 71 |
| 83 generated = compile(TEST_FOUR, 'foo'); | 72 var generated = compile(TEST_FOUR, 'foo'); |
| 84 | 73 compileAndDoNotMatchFuzzy(TEST_FOUR, 'foo', '(x) = \1;'); |
| 85 regexp = const RegExp("cond1 = cond1;"); | |
| 86 Expect.isTrue(!regexp.hasMatch(generated)); | |
| 87 | |
| 88 regexp = const RegExp("cond2 = cond2;"); | |
| 89 Expect.isTrue(!regexp.hasMatch(generated)); | |
| 90 } | 74 } |
| OLD | NEW |