| 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 final 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 final 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 = @""" |
| 22 foo(int param0) { |
| 23 var t; |
| 24 for (int i = 0; i < 1; i++) { |
| 25 t = -param0; |
| 26 } |
| 27 return t; |
| 28 } |
| 29 """; |
| 30 |
| 21 final String TEST_THREE = @""" | 31 final String TEST_THREE = @""" |
| 22 foo(c) { | 32 foo(c) { |
| 23 for (int i = 0; i < 10; i++) print(c[i]); | 33 for (int i = 0; i < 10; i++) print(c[i]); |
| 24 } | 34 } |
| 25 """; | 35 """; |
| 26 | 36 |
| 27 final String TEST_FOUR = @""" | 37 final String TEST_FOUR = @""" |
| 28 foo(String c) { | 38 foo(String c) { |
| 29 print(c[0]); // Force a type guard. | 39 print(c[0]); // Force a type guard. |
| 30 while (true) print(c.length); | 40 while (true) print(c.length); |
| 31 } | 41 } |
| 32 """; | 42 """; |
| 33 | 43 |
| 34 final String TEST_FIVE = @""" | 44 final String TEST_FIVE = @""" |
| 35 foo(a) { | 45 foo(a) { |
| 36 a[0] = 1; | 46 a[0] = 1; |
| 37 print(a[1]); | 47 print(a[1]); |
| 38 } | 48 } |
| 39 """; | 49 """; |
| 40 | 50 |
| 51 final String TEST_FIVE_WITH_BAILOUT = @""" |
| 52 foo(a) { |
| 53 for (int i = 0; i < 1; i++) { |
| 54 a[0] = 1; |
| 55 print(a[1]); |
| 56 } |
| 57 } |
| 58 """; |
| 59 |
| 41 final String TEST_SIX = @""" | 60 final String TEST_SIX = @""" |
| 42 main(a) { | 61 foo(a) { |
| 43 print(a[0]); | 62 print(a[0]); |
| 44 while (true) { | 63 while (true) { |
| 45 a[0] = a[1]; | 64 a[0] = a[1]; |
| 46 } | 65 } |
| 47 } | 66 } |
| 48 """; | 67 """; |
| 49 | 68 |
| 50 main() { | 69 main() { |
| 51 String generated = compile(TEST_ONE, 'sum'); | 70 String generated = compile(TEST_ONE, 'sum'); |
| 52 | 71 |
| 53 RegExp regexp = new RegExp("sum = \\(?$anyIdentifier \\+ $anyIdentifier\\)?"); | 72 RegExp regexp = new RegExp("sum = \\(?$anyIdentifier \\+ $anyIdentifier\\)?"); |
| 54 Expect.isTrue(regexp.hasMatch(generated)); | 73 Expect.isTrue(regexp.hasMatch(generated)); |
| 55 | 74 |
| 56 regexp = const RegExp("typeof param1 !== 'number'"); | 75 regexp = const RegExp("typeof param1 !== 'number'"); |
| 57 Expect.isTrue(regexp.hasMatch(generated)); | 76 Expect.isTrue(regexp.hasMatch(generated)); |
| 58 | 77 |
| 59 generated = compile(TEST_TWO, 'foo'); | 78 generated = compile(TEST_TWO, 'foo'); |
| 60 regexp = new RegExp(getNumberTypeCheck('param0')); | 79 regexp = new RegExp(getNumberTypeCheck('param0')); |
| 80 Expect.isTrue(!regexp.hasMatch(generated)); |
| 81 |
| 82 regexp = const RegExp('-param0'); |
| 83 Expect.isTrue(!regexp.hasMatch(generated)); |
| 84 |
| 85 generated = compile(TEST_TWO_WITH_BAILOUT, 'foo'); |
| 86 regexp = new RegExp(getNumberTypeCheck('param0')); |
| 61 Expect.isTrue(regexp.hasMatch(generated)); | 87 Expect.isTrue(regexp.hasMatch(generated)); |
| 62 | 88 |
| 63 regexp = const RegExp('-param0'); | 89 regexp = const RegExp('-param0'); |
| 64 Expect.isTrue(regexp.hasMatch(generated)); | 90 Expect.isTrue(regexp.hasMatch(generated)); |
| 65 | 91 |
| 66 generated = compile(TEST_THREE, 'foo'); | 92 generated = compile(TEST_THREE, 'foo'); |
| 67 regexp = new RegExp("c[$anyIdentifier]"); | 93 regexp = new RegExp("c[$anyIdentifier]"); |
| 68 Expect.isTrue(regexp.hasMatch(generated)); | 94 Expect.isTrue(regexp.hasMatch(generated)); |
| 69 | 95 |
| 70 generated = compile(TEST_FOUR, 'foo'); | 96 generated = compile(TEST_FOUR, 'foo'); |
| 71 regexp = new RegExp("c.length"); | 97 regexp = new RegExp("c.length"); |
| 72 Expect.isTrue(regexp.hasMatch(generated)); | 98 Expect.isTrue(regexp.hasMatch(generated)); |
| 73 | 99 |
| 74 generated = compile(TEST_FIVE, 'foo'); | 100 generated = compile(TEST_FIVE, 'foo'); |
| 75 regexp = const RegExp('a.constructor !== Array'); | 101 regexp = const RegExp('a.constructor !== Array'); |
| 102 Expect.isTrue(!regexp.hasMatch(generated)); |
| 103 Expect.isTrue(generated.contains('index')); |
| 104 Expect.isTrue(generated.contains('indexSet')); |
| 105 |
| 106 generated = compile(TEST_FIVE_WITH_BAILOUT, 'foo'); |
| 107 regexp = const RegExp('a.constructor !== Array'); |
| 76 Expect.isTrue(regexp.hasMatch(generated)); | 108 Expect.isTrue(regexp.hasMatch(generated)); |
| 77 Expect.isTrue(!generated.contains('index')); | 109 Expect.isTrue(!generated.contains('index')); |
| 78 Expect.isTrue(!generated.contains('indexSet')); | 110 Expect.isTrue(!generated.contains('indexSet')); |
| 79 | 111 |
| 80 generated = compile(TEST_FIVE, 'foo'); | 112 generated = compile(TEST_SIX, 'foo'); |
| 81 regexp = const RegExp('a.constructor !== Array'); | 113 regexp = const RegExp('a.constructor !== Array'); |
| 82 Expect.isTrue(regexp.hasMatch(generated)); | 114 Expect.isTrue(regexp.hasMatch(generated)); |
| 83 Expect.isTrue(!generated.contains('index')); | 115 Expect.isTrue(!generated.contains('index')); |
| 84 Expect.isTrue(!generated.contains('indexSet')); | 116 Expect.isTrue(!generated.contains('indexSet')); |
| 85 } | 117 } |
| OLD | NEW |