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 test.src.task.dart_test; | 5 library test.src.task.dart_test; |
6 | 6 |
7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 CompilationUnit unit = _resolveSource(source); | 1260 CompilationUnit unit = _resolveSource(source); |
1261 // Compute the constant value of the annotation on C. | 1261 // Compute the constant value of the annotation on C. |
1262 EvaluationResultImpl evaluationResult = | 1262 EvaluationResultImpl evaluationResult = |
1263 computeClassAnnotation(source, unit, 'C'); | 1263 computeClassAnnotation(source, unit, 'C'); |
1264 // And check that it has the expected value. | 1264 // And check that it has the expected value. |
1265 expect(evaluationResult, isNotNull); | 1265 expect(evaluationResult, isNotNull); |
1266 expect(evaluationResult.value, isNotNull); | 1266 expect(evaluationResult.value, isNotNull); |
1267 expect(evaluationResult.value.type, isNotNull); | 1267 expect(evaluationResult.value.type, isNotNull); |
1268 expect(evaluationResult.value.type.name, 'D'); | 1268 expect(evaluationResult.value.type.name, 'D'); |
1269 expect(evaluationResult.value.fields, contains('value')); | 1269 expect(evaluationResult.value.fields, contains('value')); |
1270 expect(evaluationResult.value.fields['value'].intValue, 1); | 1270 expect(evaluationResult.value.fields['value'].toIntValue(), 1); |
1271 } | 1271 } |
1272 | 1272 |
1273 test_annotation_without_args() { | 1273 test_annotation_without_args() { |
1274 Source source = newSource( | 1274 Source source = newSource( |
1275 '/test.dart', | 1275 '/test.dart', |
1276 ''' | 1276 ''' |
1277 const x = 1; | 1277 const x = 1; |
1278 @x class C {} | 1278 @x class C {} |
1279 '''); | 1279 '''); |
1280 // First compute the resolved unit for the source. | 1280 // First compute the resolved unit for the source. |
1281 CompilationUnit unit = _resolveSource(source); | 1281 CompilationUnit unit = _resolveSource(source); |
1282 // Compute the constant value of the annotation on C. | 1282 // Compute the constant value of the annotation on C. |
1283 EvaluationResultImpl evaluationResult = | 1283 EvaluationResultImpl evaluationResult = |
1284 computeClassAnnotation(source, unit, 'C'); | 1284 computeClassAnnotation(source, unit, 'C'); |
1285 // And check that it has the expected value. | 1285 // And check that it has the expected value. |
1286 expect(evaluationResult, isNotNull); | 1286 expect(evaluationResult, isNotNull); |
1287 expect(evaluationResult.value, isNotNull); | 1287 expect(evaluationResult.value, isNotNull); |
1288 expect(evaluationResult.value.intValue, 1); | 1288 expect(evaluationResult.value.toIntValue(), 1); |
1289 } | 1289 } |
1290 | 1290 |
1291 test_circular_reference() { | 1291 test_circular_reference() { |
1292 _checkCircularities( | 1292 _checkCircularities( |
1293 'x', | 1293 'x', |
1294 ['y'], | 1294 ['y'], |
1295 ''' | 1295 ''' |
1296 const x = y + 1; | 1296 const x = y + 1; |
1297 const y = x + 1; | 1297 const y = x + 1; |
1298 '''); | 1298 '''); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 | 1335 |
1336 test_dependency() { | 1336 test_dependency() { |
1337 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1337 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( |
1338 'x', | 1338 'x', |
1339 ''' | 1339 ''' |
1340 const x = y + 1; | 1340 const x = y + 1; |
1341 const y = 1; | 1341 const y = 1; |
1342 '''); | 1342 '''); |
1343 expect(evaluationResult, isNotNull); | 1343 expect(evaluationResult, isNotNull); |
1344 expect(evaluationResult.value, isNotNull); | 1344 expect(evaluationResult.value, isNotNull); |
1345 expect(evaluationResult.value.intValue, 2); | 1345 expect(evaluationResult.value.toIntValue(), 2); |
1346 } | 1346 } |
1347 | 1347 |
1348 test_external_const_factory() { | 1348 test_external_const_factory() { |
1349 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1349 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( |
1350 'x', | 1350 'x', |
1351 ''' | 1351 ''' |
1352 const x = const C.foo(); | 1352 const x = const C.foo(); |
1353 | 1353 |
1354 class C extends B { | 1354 class C extends B { |
1355 external const factory C.foo(); | 1355 external const factory C.foo(); |
1356 } | 1356 } |
1357 | 1357 |
1358 class B {} | 1358 class B {} |
1359 '''); | 1359 '''); |
1360 expect(evaluationResult, isNotNull); | 1360 expect(evaluationResult, isNotNull); |
1361 } | 1361 } |
1362 | 1362 |
1363 test_simple_constant() { | 1363 test_simple_constant() { |
1364 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1364 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( |
1365 'x', | 1365 'x', |
1366 ''' | 1366 ''' |
1367 const x = 1; | 1367 const x = 1; |
1368 '''); | 1368 '''); |
1369 expect(evaluationResult, isNotNull); | 1369 expect(evaluationResult, isNotNull); |
1370 expect(evaluationResult.value, isNotNull); | 1370 expect(evaluationResult.value, isNotNull); |
1371 expect(evaluationResult.value.intValue, 1); | 1371 expect(evaluationResult.value.toIntValue(), 1); |
1372 } | 1372 } |
1373 | 1373 |
1374 void _checkCircularities( | 1374 void _checkCircularities( |
1375 String variableName, List<String> otherVariables, String content) { | 1375 String variableName, List<String> otherVariables, String content) { |
1376 // Evaluating the first constant should produce an error. | 1376 // Evaluating the first constant should produce an error. |
1377 CompilationUnit unit = _resolveUnit(content); | 1377 CompilationUnit unit = _resolveUnit(content); |
1378 _expectCircularityError(_evaluateConstant(unit, variableName)); | 1378 _expectCircularityError(_evaluateConstant(unit, variableName)); |
1379 // And all the other constants involved in the strongly connected component | 1379 // And all the other constants involved in the strongly connected component |
1380 // should be set to the same error state. | 1380 // should be set to the same error state. |
1381 for (String otherVariableName in otherVariables) { | 1381 for (String otherVariableName in otherVariables) { |
(...skipping 2926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4308 /** | 4308 /** |
4309 * Fill [errorListener] with [result] errors in the current [task]. | 4309 * Fill [errorListener] with [result] errors in the current [task]. |
4310 */ | 4310 */ |
4311 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4311 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
4312 List<AnalysisError> errors = task.outputs[result]; | 4312 List<AnalysisError> errors = task.outputs[result]; |
4313 expect(errors, isNotNull, reason: result.name); | 4313 expect(errors, isNotNull, reason: result.name); |
4314 errorListener = new GatheringErrorListener(); | 4314 errorListener = new GatheringErrorListener(); |
4315 errorListener.addAll(errors); | 4315 errorListener.addAll(errors); |
4316 } | 4316 } |
4317 } | 4317 } |
OLD | NEW |