| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.constants.expressions.evaluate_test; | 5 library dart2js.constants.expressions.evaluate_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import 'package:compiler/src/common/backend_api.dart'; | 10 import 'package:compiler/src/common/backend_api.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 class ConstantData { | 32 class ConstantData { |
| 33 /// Source code for the constant expression. | 33 /// Source code for the constant expression. |
| 34 final String code; | 34 final String code; |
| 35 | 35 |
| 36 /// Map from environment to expected constant value as structured text. | 36 /// Map from environment to expected constant value as structured text. |
| 37 final Map<Map<String, String>, String> expectedValues; | 37 final Map<Map<String, String>, String> expectedValues; |
| 38 | 38 |
| 39 const ConstantData(this.code, this.expectedValues); | 39 const ConstantData(this.code, this.expectedValues); |
| 40 } | 40 } |
| 41 | 41 |
| 42 class MemoryEnvironment implements Environment { | 42 class MemoryEnvironment implements EvaluationEnvironment { |
| 43 final Compiler _compiler; | 43 final Compiler _compiler; |
| 44 final Map<String, String> env; | 44 final Map<String, String> env; |
| 45 | 45 |
| 46 MemoryEnvironment(this._compiler, [this.env = const <String, String>{}]); | 46 MemoryEnvironment(this._compiler, [this.env = const <String, String>{}]); |
| 47 | 47 |
| 48 @override | 48 @override |
| 49 String readFromEnvironment(String name) => env[name]; | 49 String readFromEnvironment(String name) => env[name]; |
| 50 | 50 |
| 51 @override | 51 @override |
| 52 ResolutionInterfaceType substByContext( | 52 ResolutionInterfaceType substByContext( |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 sb.write('main() {}\n'); | 274 sb.write('main() {}\n'); |
| 275 String source = sb.toString(); | 275 String source = sb.toString(); |
| 276 CompilationResult result = await runCompiler( | 276 CompilationResult result = await runCompiler( |
| 277 memorySourceFiles: {'main.dart': source}, options: ['--analyze-all']); | 277 memorySourceFiles: {'main.dart': source}, options: ['--analyze-all']); |
| 278 Compiler compiler = result.compiler; | 278 Compiler compiler = result.compiler; |
| 279 var library = compiler.mainApp; | 279 var library = compiler.mainApp; |
| 280 constants.forEach((String name, ConstantData data) { | 280 constants.forEach((String name, ConstantData data) { |
| 281 FieldElement field = library.localLookup(name); | 281 FieldElement field = library.localLookup(name); |
| 282 ConstantExpression constant = field.constant; | 282 ConstantExpression constant = field.constant; |
| 283 data.expectedValues.forEach((Map<String, String> env, String expectedText) { | 283 data.expectedValues.forEach((Map<String, String> env, String expectedText) { |
| 284 Environment environment = new MemoryEnvironment(compiler, env); | 284 EvaluationEnvironment environment = new MemoryEnvironment(compiler, env); |
| 285 ConstantValue value = | 285 ConstantValue value = |
| 286 constant.evaluate(environment, DART_CONSTANT_SYSTEM); | 286 constant.evaluate(environment, DART_CONSTANT_SYSTEM); |
| 287 String valueText = value.toStructuredText(); | 287 String valueText = value.toStructuredText(); |
| 288 Expect.equals( | 288 Expect.equals( |
| 289 expectedText, | 289 expectedText, |
| 290 valueText, | 290 valueText, |
| 291 "Unexpected value '${valueText}' for constant " | 291 "Unexpected value '${valueText}' for constant " |
| 292 "`${constant.toDartText()}`, expected '${expectedText}'."); | 292 "`${constant.toDartText()}`, expected '${expectedText}'."); |
| 293 }); | 293 }); |
| 294 }); | 294 }); |
| 295 } | 295 } |
| OLD | NEW |