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'; | |
11 import 'package:compiler/src/constants/constructors.dart'; | 10 import 'package:compiler/src/constants/constructors.dart'; |
12 import 'package:compiler/src/constants/evaluation.dart'; | 11 import 'package:compiler/src/constants/evaluation.dart'; |
13 import 'package:compiler/src/constants/expressions.dart'; | 12 import 'package:compiler/src/constants/expressions.dart'; |
14 import 'package:compiler/src/constants/values.dart'; | 13 import 'package:compiler/src/constants/values.dart'; |
15 import 'package:compiler/src/constant_system_dart.dart'; | 14 import 'package:compiler/src/constant_system_dart.dart'; |
16 import 'package:compiler/src/compiler.dart'; | 15 import 'package:compiler/src/compiler.dart'; |
17 import 'package:compiler/src/common_elements.dart'; | 16 import 'package:compiler/src/common_elements.dart'; |
18 import 'package:compiler/src/elements/elements.dart'; | 17 import 'package:compiler/src/elements/elements.dart'; |
19 import 'package:compiler/src/elements/resolution_types.dart'; | 18 import 'package:compiler/src/elements/resolution_types.dart'; |
20 import 'memory_compiler.dart'; | 19 import 'memory_compiler.dart'; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 data.constants.forEach((ConstantData constantData) { | 268 data.constants.forEach((ConstantData constantData) { |
270 String name = 'c${constants.length}'; | 269 String name = 'c${constants.length}'; |
271 sb.write('const $name = ${constantData.code};\n'); | 270 sb.write('const $name = ${constantData.code};\n'); |
272 constants[name] = constantData; | 271 constants[name] = constantData; |
273 }); | 272 }); |
274 sb.write('main() {}\n'); | 273 sb.write('main() {}\n'); |
275 String source = sb.toString(); | 274 String source = sb.toString(); |
276 CompilationResult result = await runCompiler( | 275 CompilationResult result = await runCompiler( |
277 memorySourceFiles: {'main.dart': source}, options: ['--analyze-all']); | 276 memorySourceFiles: {'main.dart': source}, options: ['--analyze-all']); |
278 Compiler compiler = result.compiler; | 277 Compiler compiler = result.compiler; |
279 var library = compiler.mainApp; | 278 dynamic library = compiler.mainApp; |
280 constants.forEach((String name, ConstantData data) { | 279 constants.forEach((String name, ConstantData data) { |
281 FieldElement field = library.localLookup(name); | 280 FieldElement field = library.localLookup(name); |
282 ConstantExpression constant = field.constant; | 281 ConstantExpression constant = field.constant; |
283 data.expectedValues.forEach((Map<String, String> env, String expectedText) { | 282 data.expectedValues.forEach((Map<String, String> env, String expectedText) { |
284 EvaluationEnvironment environment = new MemoryEnvironment(compiler, env); | 283 EvaluationEnvironment environment = new MemoryEnvironment(compiler, env); |
285 ConstantValue value = | 284 ConstantValue value = |
286 constant.evaluate(environment, DART_CONSTANT_SYSTEM); | 285 constant.evaluate(environment, DART_CONSTANT_SYSTEM); |
287 String valueText = value.toStructuredText(); | 286 String valueText = value.toStructuredText(); |
288 Expect.equals( | 287 Expect.equals( |
289 expectedText, | 288 expectedText, |
290 valueText, | 289 valueText, |
291 "Unexpected value '${valueText}' for constant " | 290 "Unexpected value '${valueText}' for constant " |
292 "`${constant.toDartText()}`, expected '${expectedText}'."); | 291 "`${constant.toDartText()}`, expected '${expectedText}'."); |
293 }); | 292 }); |
294 }); | 293 }); |
295 } | 294 } |
OLD | NEW |