| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'compiler_helper.dart'; | 8 import 'compiler_helper.dart'; |
| 9 | 9 |
| 10 const String TEST_ONE = r""" | 10 const String TEST_ONE = r""" |
| 11 foo(a) { | 11 foo(a) { |
| 12 var myVariableName = a.toString(); | 12 var myVariableName = a.toString(); |
| 13 print(myVariableName); | 13 print(myVariableName); |
| 14 print(myVariableName); | 14 print(myVariableName); |
| 15 } | 15 } |
| 16 """; | 16 """; |
| 17 | 17 |
| 18 const String TEST_TWO = r""" | 18 const String TEST_TWO = r""" |
| 19 class A { | 19 class A { |
| 20 var length; | 20 var length; |
| 21 } | 21 } |
| 22 foo(a) { | 22 foo(a) { |
| 23 print([]); // Make sure the array class is instantiated. | 23 print([]); // Make sure the array class is instantiated. |
| 24 return new A().length + a.length; | 24 return new A().length + a.length; |
| 25 } | 25 } |
| 26 """; | 26 """; |
| 27 | 27 |
| 28 main() { | 28 main() { |
| 29 asyncTest(() => Future.wait([ | 29 asyncTest(() => Future.wait([ |
| 30 // Check that one-shot interceptors preserve variable names, see | 30 // Check that one-shot interceptors preserve variable names, see |
| 31 // https://code.google.com/p/dart/issues/detail?id=8106. | 31 // https://code.google.com/p/dart/issues/detail?id=8106. |
| 32 compile(TEST_ONE, entry: 'foo', check: (String generated) { | 32 compile(TEST_ONE, entry: 'foo', check: (String generated) { |
| 33 Expect.isTrue( | 33 Expect.isTrue( |
| 34 generated.contains(new RegExp(r'[$A-Z]+\.toString\$0\$\(a\)'))); | 34 generated.contains(new RegExp(r'[$A-Z]+\.toString\$0\$\(a\)'))); |
| 35 Expect.isTrue(generated.contains('myVariableName')); | 35 Expect.isTrue(generated.contains('myVariableName')); |
| 36 }), | 36 }), |
| 37 // Check that an intercepted getter that does not need to be | 37 // Check that an intercepted getter that does not need to be |
| 38 // intercepted, is turned into a regular getter call or field | 38 // intercepted, is turned into a regular getter call or field |
| 39 // access. | 39 // access. |
| 40 compile(TEST_TWO, entry: 'foo', check: (String generated) { | 40 compile(TEST_TWO, entry: 'foo', check: (String generated) { |
| 41 Expect.isFalse(generated.contains(r'a.get$length()')); | 41 Expect.isFalse(generated.contains(r'a.get$length()')); |
| 42 Expect.isTrue( | 42 Expect.isTrue( |
| 43 generated.contains(new RegExp(r'[$A-Z]+\.A\$\(\)\.length'))); | 43 generated.contains(new RegExp(r'[$A-Z]+\.A\$\(\)\.length'))); |
| 44 Expect.isTrue( | 44 Expect.isTrue( |
| 45 generated.contains(new RegExp(r'[$A-Z]+\.get\$length\$as\(a\)'))); | 45 generated.contains(new RegExp(r'[$A-Z]+\.get\$length\$as\(a\)'))); |
| 46 }), | 46 }), |
| 47 ])); | 47 ])); |
| 48 } | 48 } |
| OLD | NEW |