| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Test that constants depended on by other constants are correctly deferred. | 5 // Test that constants depended on by other constants are correctly deferred. |
| 6 | 6 |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:compiler/src/common.dart'; | |
| 9 import 'package:compiler/src/constants/values.dart'; | 8 import 'package:compiler/src/constants/values.dart'; |
| 10 import 'package:compiler/src/compiler.dart'; | 9 import 'package:compiler/src/compiler.dart'; |
| 11 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| 12 import 'memory_compiler.dart'; | 11 import 'memory_compiler.dart'; |
| 13 | 12 |
| 14 void main() { | 13 void main() { |
| 15 asyncTest(() async { | 14 asyncTest(() async { |
| 16 CompilationResult result = | 15 CompilationResult result = |
| 17 await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES); | 16 await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES); |
| 18 Compiler compiler = result.compiler; | 17 Compiler compiler = result.compiler; |
| 19 var outputUnitForConstant = compiler.deferredLoadTask.outputUnitForConstant; | 18 var outputUnitForConstant = compiler.deferredLoadTask.outputUnitForConstant; |
| 20 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; | 19 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; |
| 21 List<ConstantValue> allConstants = []; | 20 List<ConstantValue> allConstants = []; |
| 22 | 21 |
| 23 addConstantWithDependendencies(ConstantValue c) { | 22 addConstantWithDependendencies(ConstantValue c) { |
| 24 allConstants.add(c); | 23 allConstants.add(c); |
| 25 c.getDependencies().forEach(addConstantWithDependendencies); | 24 c.getDependencies().forEach(addConstantWithDependendencies); |
| 26 } | 25 } |
| 27 | 26 |
| 28 var codegenWorldBuilder = compiler.codegenWorldBuilder; | 27 dynamic codegenWorldBuilder = compiler.codegenWorldBuilder; |
| 29 codegenWorldBuilder.compiledConstants | 28 codegenWorldBuilder.compiledConstants |
| 30 .forEach(addConstantWithDependendencies); | 29 .forEach(addConstantWithDependendencies); |
| 31 for (String stringValue in ["cA", "cB", "cC"]) { | 30 for (String stringValue in ["cA", "cB", "cC"]) { |
| 32 ConstantValue constant = allConstants.firstWhere((constant) { | 31 ConstantValue constant = allConstants.firstWhere((dynamic constant) { |
| 33 return constant.isString && constant.primitiveValue == stringValue; | 32 return constant.isString && constant.primitiveValue == stringValue; |
| 34 }); | 33 }); |
| 35 Expect.notEquals(null, outputUnitForConstant(constant), | 34 Expect.notEquals(null, outputUnitForConstant(constant), |
| 36 "Constant value ${constant.toStructuredText()} has no output unit."); | 35 "Constant value ${constant.toStructuredText()} has no output unit."); |
| 37 Expect.notEquals( | 36 Expect.notEquals( |
| 38 mainOutputUnit, | 37 mainOutputUnit, |
| 39 outputUnitForConstant(constant), | 38 outputUnitForConstant(constant), |
| 40 "Constant value ${constant.toStructuredText()} " | 39 "Constant value ${constant.toStructuredText()} " |
| 41 "is in the main output unit."); | 40 "is in the main output unit."); |
| 42 } | 41 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 63 """, | 62 """, |
| 64 "lib.dart": """ | 63 "lib.dart": """ |
| 65 class C { | 64 class C { |
| 66 final a; | 65 final a; |
| 67 const C(this.a); | 66 const C(this.a); |
| 68 } | 67 } |
| 69 | 68 |
| 70 const L = const {"cA": const C(const {"cB": "cC"})}; | 69 const L = const {"cA": const C(const {"cB": "cC"})}; |
| 71 """, | 70 """, |
| 72 }; | 71 }; |
| OLD | NEW |