Chromium Code Reviews| 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 | 4 |
| 5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'compiler_helper.dart'; | 6 import 'compiler_helper.dart'; |
| 7 | 7 |
| 8 const String TEST_IF = r""" | 8 const String TEST_IF = r""" |
| 9 test(param) { | 9 test(param) { |
| 10 // Ensure a String+ is in the system. | |
| 11 print('foo'); | |
|
kasperl
2013/06/14 06:19:08
So printing foo is enough to ensure that String +
ngeoffray
2013/06/14 06:58:34
Yes, the [: param + 53 :] expression line 15 does
| |
| 10 if (param is int) { | 12 if (param is int) { |
| 11 param = param + 42; | 13 param = param + 42; |
| 12 } | 14 } |
| 13 return param + 53; | 15 return param + 53; |
| 14 } | 16 } |
| 15 """; | 17 """; |
| 16 | 18 |
| 17 const String TEST_IF_ELSE = r""" | 19 const String TEST_IF_ELSE = r""" |
| 18 test(param) { | 20 test(param) { |
| 21 print('foo'); | |
| 19 if (param is int) { | 22 if (param is int) { |
| 20 param = param + 42; | 23 param = param + 42; |
| 21 } else { | 24 } else { |
| 22 param = param + 53; | 25 param = param + 53; |
| 23 } | 26 } |
| 24 return param + 53; | 27 return param + 53; |
| 25 } | 28 } |
| 26 """; | 29 """; |
| 27 | 30 |
| 28 const String TEST_IF_RETURN = r""" | 31 const String TEST_IF_RETURN = r""" |
| 29 test(param) { | 32 test(param) { |
| 33 print('foo'); | |
| 30 if (param is int) { | 34 if (param is int) { |
| 31 return param + 42; | 35 return param + 42; |
| 32 } | 36 } |
| 33 return param + 53; | 37 return param + 53; |
| 34 } | 38 } |
| 35 """; | 39 """; |
| 36 | 40 |
| 37 const String TEST_IF_NOT_ELSE = r""" | 41 const String TEST_IF_NOT_ELSE = r""" |
| 38 test(param) { | 42 test(param) { |
| 43 print('foo'); | |
| 39 if (param is !int) { | 44 if (param is !int) { |
| 40 param = param + 53; | 45 param = param + 53; |
| 41 } else { | 46 } else { |
| 42 param = param + 42; | 47 param = param + 42; |
| 43 } | 48 } |
| 44 return param; | 49 return param; |
| 45 } | 50 } |
| 46 """; | 51 """; |
| 47 | 52 |
| 48 const String TEST_IF_NOT_RETURN = r""" | 53 const String TEST_IF_NOT_RETURN = r""" |
| 49 test(param) { | 54 test(param) { |
| 55 print('foo'); | |
| 50 if (param is !int) return param + 53; | 56 if (param is !int) return param + 53; |
| 51 return param + 42; | 57 return param + 42; |
| 52 } | 58 } |
| 53 """; | 59 """; |
| 54 | 60 |
| 55 const String TEST_IF_NOT_ELSE_RETURN = r""" | 61 const String TEST_IF_NOT_ELSE_RETURN = r""" |
| 56 test(param) { | 62 test(param) { |
| 63 print('foo'); | |
| 57 if (param is !int) { | 64 if (param is !int) { |
| 58 return param + 53; | 65 return param + 53; |
| 59 } else { | 66 } else { |
| 60 param = param + 42; | 67 param = param + 42; |
| 61 } | 68 } |
| 62 return param; | 69 return param; |
| 63 } | 70 } |
| 64 """; | 71 """; |
| 65 | 72 |
| 66 compileAndTest(String code) { | 73 compileAndTest(String code) { |
| 67 String generated = compile(code, entry: 'test'); | 74 String generated = compile(code, entry: 'test'); |
| 68 RegExp validAdd = | 75 RegExp validAdd = |
| 69 new RegExp("($anyIdentifier \\+ 42)|($anyIdentifier \\+= 42)"); | 76 new RegExp("($anyIdentifier \\+ 42)|($anyIdentifier \\+= 42)"); |
| 70 RegExp invalidAdd = new RegExp("$anyIdentifier \\+ 53"); | 77 RegExp invalidAdd = new RegExp("$anyIdentifier \\+ 53"); |
| 71 Expect.isTrue(validAdd.hasMatch(generated)); | 78 Expect.isTrue(validAdd.hasMatch(generated)); |
| 72 Expect.isFalse(invalidAdd.hasMatch(generated)); | 79 Expect.isFalse(invalidAdd.hasMatch(generated)); |
| 73 } | 80 } |
| 74 | 81 |
| 75 main() { | 82 main() { |
| 76 compileAndTest(TEST_IF); | 83 compileAndTest(TEST_IF); |
| 77 compileAndTest(TEST_IF_ELSE); | 84 compileAndTest(TEST_IF_ELSE); |
| 78 compileAndTest(TEST_IF_RETURN); | 85 compileAndTest(TEST_IF_RETURN); |
| 79 compileAndTest(TEST_IF_NOT_ELSE); | 86 compileAndTest(TEST_IF_NOT_ELSE); |
| 80 compileAndTest(TEST_IF_NOT_RETURN); | 87 compileAndTest(TEST_IF_NOT_RETURN); |
| 81 compileAndTest(TEST_IF_NOT_ELSE_RETURN); | 88 compileAndTest(TEST_IF_NOT_ELSE_RETURN); |
| 82 } | 89 } |
| OLD | NEW |