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 constant_expression_test; | 5 library constant_expression_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/constants/expressions.dart'; | 10 import 'package:compiler/src/constants/expressions.dart'; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 String name = 'c${constants.length}'; | 203 String name = 'c${constants.length}'; |
204 sb.write('const $name = ${constantData.code};\n'); | 204 sb.write('const $name = ${constantData.code};\n'); |
205 constants[name] = constantData; | 205 constants[name] = constantData; |
206 }); | 206 }); |
207 sb.write('main() {}\n'); | 207 sb.write('main() {}\n'); |
208 String source = sb.toString(); | 208 String source = sb.toString(); |
209 CompilationResult result = await runCompiler( | 209 CompilationResult result = await runCompiler( |
210 memorySourceFiles: {'main.dart': source}, options: ['--analyze-all']); | 210 memorySourceFiles: {'main.dart': source}, options: ['--analyze-all']); |
211 Compiler compiler = result.compiler; | 211 Compiler compiler = result.compiler; |
212 MemoryEnvironment environment = new MemoryEnvironment(compiler); | 212 MemoryEnvironment environment = new MemoryEnvironment(compiler); |
213 var library = compiler.frontendStrategy.elementEnvironment.mainLibrary; | 213 dynamic library = compiler.frontendStrategy.elementEnvironment.mainLibrary; |
214 constants.forEach((String name, ConstantData data) { | 214 constants.forEach((String name, ConstantData data) { |
215 FieldElement field = library.localLookup(name); | 215 FieldElement field = library.localLookup(name); |
216 var constant = field.constant; | 216 dynamic constant = field.constant; |
217 Expect.equals( | 217 Expect.equals( |
218 data.kind, | 218 data.kind, |
219 constant.kind, | 219 constant.kind, |
220 "Unexpected kind '${constant.kind}' for constant " | 220 "Unexpected kind '${constant.kind}' for constant " |
221 "`${constant.toDartText()}`, expected '${data.kind}'."); | 221 "`${constant.toDartText()}`, expected '${data.kind}'."); |
222 Expect.equals( | 222 Expect.equals( |
223 data.text, | 223 data.text, |
224 constant.toDartText(), | 224 constant.toDartText(), |
225 "Unexpected text '${constant.toDartText()}' for constant, " | 225 "Unexpected text '${constant.toDartText()}' for constant, " |
226 "expected '${data.text}'."); | 226 "expected '${data.text}'."); |
(...skipping 19 matching lines...) Expand all Loading... |
246 String expected = data.fields[name]; | 246 String expected = data.fields[name]; |
247 Expect.equals( | 247 Expect.equals( |
248 expected, | 248 expected, |
249 expression, | 249 expression, |
250 "Unexpected field expression ${expression} for field '$name' in " | 250 "Unexpected field expression ${expression} for field '$name' in " |
251 "constant `${constant.toDartText()}`, expected '${expected}'."); | 251 "constant `${constant.toDartText()}`, expected '${expected}'."); |
252 }); | 252 }); |
253 } | 253 } |
254 }); | 254 }); |
255 } | 255 } |
OLD | NEW |