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 | 4 |
5 #import("compiler_helper.dart"); | 5 #import("compiler_helper.dart"); |
6 | 6 |
7 final String TEST_ONE = @""" | 7 const String TEST_ONE = @""" |
8 sum(param0, param1) { | 8 sum(param0, param1) { |
9 var sum = 0; | 9 var sum = 0; |
10 for (var i = param0; i < param1; i += 1) sum = sum + i; | 10 for (var i = param0; i < param1; i += 1) sum = sum + i; |
11 return sum; | 11 return sum; |
12 } | 12 } |
13 """; | 13 """; |
14 | 14 |
15 final String TEST_TWO = @""" | 15 const String TEST_TWO = @""" |
16 foo(int param0) { | 16 foo(int param0) { |
17 return -param0; | 17 return -param0; |
18 } | 18 } |
19 """; | 19 """; |
20 | 20 |
21 final String TEST_TWO_WITH_BAILOUT = @""" | 21 const String TEST_TWO_WITH_BAILOUT = @""" |
22 foo(int param0) { | 22 foo(int param0) { |
23 for (int i = 0; i < 1; i++) { | 23 for (int i = 0; i < 1; i++) { |
24 param0 = -param0; | 24 param0 = -param0; |
25 } | 25 } |
26 return param0; | 26 return param0; |
27 } | 27 } |
28 """; | 28 """; |
29 | 29 |
30 final String TEST_THREE = @""" | 30 const String TEST_THREE = @""" |
31 foo(c) { | 31 foo(c) { |
32 for (int i = 0; i < 10; i++) print(c[i]); | 32 for (int i = 0; i < 10; i++) print(c[i]); |
33 } | 33 } |
34 """; | 34 """; |
35 | 35 |
36 final String TEST_FOUR = @""" | 36 const String TEST_FOUR = @""" |
37 foo(String c) { | 37 foo(String c) { |
38 print(c[0]); // Force a type guard. | 38 print(c[0]); // Force a type guard. |
39 while (true) print(c.length); | 39 while (true) print(c.length); |
40 } | 40 } |
41 """; | 41 """; |
42 | 42 |
43 final String TEST_FIVE = @""" | 43 const String TEST_FIVE = @""" |
44 foo(a) { | 44 foo(a) { |
45 a[0] = 1; | 45 a[0] = 1; |
46 print(a[1]); | 46 print(a[1]); |
47 } | 47 } |
48 """; | 48 """; |
49 | 49 |
50 final String TEST_FIVE_WITH_BAILOUT = @""" | 50 const String TEST_FIVE_WITH_BAILOUT = @""" |
51 foo(a) { | 51 foo(a) { |
52 for (int i = 0; i < 1; i++) { | 52 for (int i = 0; i < 1; i++) { |
53 a[0] = 1; | 53 a[0] = 1; |
54 print(a[1]); | 54 print(a[1]); |
55 } | 55 } |
56 } | 56 } |
57 """; | 57 """; |
58 | 58 |
59 final String TEST_SIX = @""" | 59 const String TEST_SIX = @""" |
60 foo(a) { | 60 foo(a) { |
61 print(a[0]); | 61 print(a[0]); |
62 while (true) { | 62 while (true) { |
63 a[0] = a[1]; | 63 a[0] = a[1]; |
64 } | 64 } |
65 } | 65 } |
66 """; | 66 """; |
67 | 67 |
68 main() { | 68 main() { |
69 String generated = compile(TEST_ONE, 'sum'); | 69 String generated = compile(TEST_ONE, 'sum'); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 Expect.isTrue(regexp.hasMatch(generated)); | 103 Expect.isTrue(regexp.hasMatch(generated)); |
104 Expect.isTrue(!generated.contains('index')); | 104 Expect.isTrue(!generated.contains('index')); |
105 Expect.isTrue(!generated.contains('indexSet')); | 105 Expect.isTrue(!generated.contains('indexSet')); |
106 | 106 |
107 generated = compile(TEST_SIX, 'foo'); | 107 generated = compile(TEST_SIX, 'foo'); |
108 regexp = const RegExp('a.constructor !== Array'); | 108 regexp = const RegExp('a.constructor !== Array'); |
109 Expect.isTrue(regexp.hasMatch(generated)); | 109 Expect.isTrue(regexp.hasMatch(generated)); |
110 Expect.isTrue(!generated.contains('index')); | 110 Expect.isTrue(!generated.contains('index')); |
111 Expect.isTrue(!generated.contains('indexSet')); | 111 Expect.isTrue(!generated.contains('indexSet')); |
112 } | 112 } |
OLD | NEW |