OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Test that parameters keep their names in the output. | |
5 | |
6 #import("compiler_helper.dart"); | |
7 | |
8 final String TEST_ONE = @""" | |
9 void foo(bar) { | |
10 var a = 1; | |
11 if (bar) { | |
12 a = 2; | |
13 } else { | |
14 a = 3; | |
15 } | |
16 print(a); | |
17 } | |
18 """; | |
19 | |
20 final String TEST_TWO = @""" | |
21 void main() { | |
22 var t = 0; | |
23 for (var i = 0; i == 0; i = i + 1) { | |
24 t = t + 10; | |
25 } | |
26 print(t); | |
27 } | |
28 """; | |
29 | |
30 final String TEST_THREE = @""" | |
31 foo(b, c) { | |
32 var val = 42; | |
33 if (b) { | |
34 if (c) { | |
35 val = 43; | |
36 } | |
37 } | |
38 return val; | |
39 } | |
40 """; | |
41 | |
42 final String TEST_FOUR = @""" | |
43 foo() { | |
44 var cond1 = true; | |
45 var cond2 = false; | |
46 for (var i = 0; cond1; i = i + 1) { | |
47 if (i == 9) cond1 = false; | |
48 for (var j = 0; cond2; j = j + 1) { | |
49 if (j == 9) cond2 = false; | |
50 } | |
51 } | |
52 print(cond1); | |
53 print(cond2); | |
54 } | |
55 """; | |
56 | |
57 main() { | |
58 String generated = compile(TEST_ONE, 'foo'); | |
59 Expect.isTrue(generated.contains('var a = bar === true ? 2 : 3;')); | |
60 Expect.isTrue(generated.contains('print(a);')); | |
61 | |
62 generated = compile(TEST_TWO, 'main'); | |
63 RegExp regexp = new RegExp("t \\+= 10"); | |
64 Expect.isTrue(regexp.hasMatch(generated)); | |
65 | |
66 regexp = new RegExp("\\+\\+i"); | |
67 Expect.isTrue(regexp.hasMatch(generated)); | |
68 | |
69 generated = compile(TEST_THREE, 'foo'); | |
70 | |
71 // Check that we don't have 'val = val'. | |
72 regexp = const RegExp("val = val;"); | |
73 Expect.isTrue(!regexp.hasMatch(generated)); | |
74 | |
75 regexp = const RegExp("return val"); | |
76 Expect.isTrue(regexp.hasMatch(generated)); | |
77 // Check that a store just after the declaration of the local | |
78 // only generates one instruction. | |
79 regexp = const RegExp(@"val = 42"); | |
80 Expect.isTrue(regexp.hasMatch(generated)); | |
81 | |
82 generated = compile(TEST_FOUR, 'foo'); | |
83 | |
84 regexp = const RegExp("cond1 = cond1;"); | |
85 Expect.isTrue(!regexp.hasMatch(generated)); | |
86 | |
87 regexp = const RegExp("cond2 = cond2;"); | |
88 Expect.isTrue(!regexp.hasMatch(generated)); | |
89 } | |
OLD | NEW |