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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
7 | 7 |
8 library engine.all_the_rest_test; | 8 library engine.all_the_rest_test; |
9 | 9 |
10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 DartObject value = result.value; | 871 DartObject value = result.value; |
872 expect(value, isNotNull); | 872 expect(value, isNotNull); |
873 ParameterizedType type = value.type; | 873 ParameterizedType type = value.type; |
874 expect(type, isNotNull); | 874 expect(type, isNotNull); |
875 expect(type.name, "String"); | 875 expect(type.name, "String"); |
876 expect(value.stringValue, expectedValue); | 876 expect(value.stringValue, expectedValue); |
877 } | 877 } |
878 | 878 |
879 EvaluationResult _getExpressionValue(String contents) { | 879 EvaluationResult _getExpressionValue(String contents) { |
880 Source source = addSource("var x = $contents;"); | 880 Source source = addSource("var x = $contents;"); |
881 LibraryElement library = resolve(source); | 881 LibraryElement library = resolve2(source); |
882 CompilationUnit unit = | 882 CompilationUnit unit = |
883 analysisContext.resolveCompilationUnit(source, library); | 883 analysisContext.resolveCompilationUnit(source, library); |
884 expect(unit, isNotNull); | 884 expect(unit, isNotNull); |
885 NodeList<CompilationUnitMember> declarations = unit.declarations; | 885 NodeList<CompilationUnitMember> declarations = unit.declarations; |
886 expect(declarations, hasLength(1)); | 886 expect(declarations, hasLength(1)); |
887 CompilationUnitMember declaration = declarations[0]; | 887 CompilationUnitMember declaration = declarations[0]; |
888 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, | 888 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
889 TopLevelVariableDeclaration, declaration); | 889 TopLevelVariableDeclaration, declaration); |
890 NodeList<VariableDeclaration> variables = | 890 NodeList<VariableDeclaration> variables = |
891 (declaration as TopLevelVariableDeclaration).variables.variables; | 891 (declaration as TopLevelVariableDeclaration).variables.variables; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 _evaluateAnnotation(compilationUnit, "C", "f"); | 1259 _evaluateAnnotation(compilationUnit, "C", "f"); |
1260 } | 1260 } |
1261 | 1261 |
1262 void test_computeValues_cycle() { | 1262 void test_computeValues_cycle() { |
1263 TestLogger logger = new TestLogger(); | 1263 TestLogger logger = new TestLogger(); |
1264 AnalysisEngine.instance.logger = logger; | 1264 AnalysisEngine.instance.logger = logger; |
1265 Source librarySource = addSource(r''' | 1265 Source librarySource = addSource(r''' |
1266 const int a = c; | 1266 const int a = c; |
1267 const int b = a; | 1267 const int b = a; |
1268 const int c = b;'''); | 1268 const int c = b;'''); |
1269 LibraryElement libraryElement = resolve(librarySource); | 1269 LibraryElement libraryElement = resolve2(librarySource); |
1270 CompilationUnit unit = | 1270 CompilationUnit unit = |
1271 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1271 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
1272 analysisContext.computeErrors(librarySource); | 1272 analysisContext.computeErrors(librarySource); |
1273 expect(unit, isNotNull); | 1273 expect(unit, isNotNull); |
1274 ConstantValueComputer computer = _makeConstantValueComputer(); | 1274 ConstantValueComputer computer = _makeConstantValueComputer(); |
1275 computer.add(unit, librarySource, librarySource); | 1275 computer.add(unit, librarySource, librarySource); |
1276 computer.computeValues(); | 1276 computer.computeValues(); |
1277 NodeList<CompilationUnitMember> members = unit.declarations; | 1277 NodeList<CompilationUnitMember> members = unit.declarations; |
1278 expect(members, hasLength(3)); | 1278 expect(members, hasLength(3)); |
1279 _validate(false, (members[0] as TopLevelVariableDeclaration).variables); | 1279 _validate(false, (members[0] as TopLevelVariableDeclaration).variables); |
1280 _validate(false, (members[1] as TopLevelVariableDeclaration).variables); | 1280 _validate(false, (members[1] as TopLevelVariableDeclaration).variables); |
1281 _validate(false, (members[2] as TopLevelVariableDeclaration).variables); | 1281 _validate(false, (members[2] as TopLevelVariableDeclaration).variables); |
1282 } | 1282 } |
1283 | 1283 |
1284 void test_computeValues_dependentVariables() { | 1284 void test_computeValues_dependentVariables() { |
1285 Source librarySource = addSource(r''' | 1285 Source librarySource = addSource(r''' |
1286 const int b = a; | 1286 const int b = a; |
1287 const int a = 0;'''); | 1287 const int a = 0;'''); |
1288 LibraryElement libraryElement = resolve(librarySource); | 1288 LibraryElement libraryElement = resolve2(librarySource); |
1289 CompilationUnit unit = | 1289 CompilationUnit unit = |
1290 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1290 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
1291 expect(unit, isNotNull); | 1291 expect(unit, isNotNull); |
1292 ConstantValueComputer computer = _makeConstantValueComputer(); | 1292 ConstantValueComputer computer = _makeConstantValueComputer(); |
1293 computer.add(unit, librarySource, librarySource); | 1293 computer.add(unit, librarySource, librarySource); |
1294 computer.computeValues(); | 1294 computer.computeValues(); |
1295 NodeList<CompilationUnitMember> members = unit.declarations; | 1295 NodeList<CompilationUnitMember> members = unit.declarations; |
1296 expect(members, hasLength(2)); | 1296 expect(members, hasLength(2)); |
1297 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); | 1297 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); |
1298 _validate(true, (members[1] as TopLevelVariableDeclaration).variables); | 1298 _validate(true, (members[1] as TopLevelVariableDeclaration).variables); |
1299 } | 1299 } |
1300 | 1300 |
1301 void test_computeValues_empty() { | 1301 void test_computeValues_empty() { |
1302 ConstantValueComputer computer = _makeConstantValueComputer(); | 1302 ConstantValueComputer computer = _makeConstantValueComputer(); |
1303 computer.computeValues(); | 1303 computer.computeValues(); |
1304 } | 1304 } |
1305 | 1305 |
1306 void test_computeValues_multipleSources() { | 1306 void test_computeValues_multipleSources() { |
1307 Source librarySource = addNamedSource("/lib.dart", r''' | 1307 Source librarySource = addNamedSource("/lib.dart", r''' |
1308 library lib; | 1308 library lib; |
1309 part 'part.dart'; | 1309 part 'part.dart'; |
1310 const int c = b; | 1310 const int c = b; |
1311 const int a = 0;'''); | 1311 const int a = 0;'''); |
1312 Source partSource = addNamedSource("/part.dart", r''' | 1312 Source partSource = addNamedSource("/part.dart", r''' |
1313 part of lib; | 1313 part of lib; |
1314 const int b = a; | 1314 const int b = a; |
1315 const int d = c;'''); | 1315 const int d = c;'''); |
1316 LibraryElement libraryElement = resolve(librarySource); | 1316 LibraryElement libraryElement = resolve2(librarySource); |
1317 CompilationUnit libraryUnit = | 1317 CompilationUnit libraryUnit = |
1318 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1318 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
1319 expect(libraryUnit, isNotNull); | 1319 expect(libraryUnit, isNotNull); |
1320 CompilationUnit partUnit = | 1320 CompilationUnit partUnit = |
1321 analysisContext.resolveCompilationUnit(partSource, libraryElement); | 1321 analysisContext.resolveCompilationUnit(partSource, libraryElement); |
1322 expect(partUnit, isNotNull); | 1322 expect(partUnit, isNotNull); |
1323 ConstantValueComputer computer = _makeConstantValueComputer(); | 1323 ConstantValueComputer computer = _makeConstantValueComputer(); |
1324 computer.add(libraryUnit, librarySource, librarySource); | 1324 computer.add(libraryUnit, librarySource, librarySource); |
1325 computer.add(partUnit, partSource, librarySource); | 1325 computer.add(partUnit, partSource, librarySource); |
1326 computer.computeValues(); | 1326 computer.computeValues(); |
1327 NodeList<CompilationUnitMember> libraryMembers = libraryUnit.declarations; | 1327 NodeList<CompilationUnitMember> libraryMembers = libraryUnit.declarations; |
1328 expect(libraryMembers, hasLength(2)); | 1328 expect(libraryMembers, hasLength(2)); |
1329 _validate( | 1329 _validate( |
1330 true, (libraryMembers[0] as TopLevelVariableDeclaration).variables); | 1330 true, (libraryMembers[0] as TopLevelVariableDeclaration).variables); |
1331 _validate( | 1331 _validate( |
1332 true, (libraryMembers[1] as TopLevelVariableDeclaration).variables); | 1332 true, (libraryMembers[1] as TopLevelVariableDeclaration).variables); |
1333 NodeList<CompilationUnitMember> partMembers = libraryUnit.declarations; | 1333 NodeList<CompilationUnitMember> partMembers = libraryUnit.declarations; |
1334 expect(partMembers, hasLength(2)); | 1334 expect(partMembers, hasLength(2)); |
1335 _validate(true, (partMembers[0] as TopLevelVariableDeclaration).variables); | 1335 _validate(true, (partMembers[0] as TopLevelVariableDeclaration).variables); |
1336 _validate(true, (partMembers[1] as TopLevelVariableDeclaration).variables); | 1336 _validate(true, (partMembers[1] as TopLevelVariableDeclaration).variables); |
1337 } | 1337 } |
1338 | 1338 |
1339 void test_computeValues_singleVariable() { | 1339 void test_computeValues_singleVariable() { |
1340 Source librarySource = addSource("const int a = 0;"); | 1340 Source librarySource = addSource("const int a = 0;"); |
1341 LibraryElement libraryElement = resolve(librarySource); | 1341 LibraryElement libraryElement = resolve2(librarySource); |
1342 CompilationUnit unit = | 1342 CompilationUnit unit = |
1343 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1343 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
1344 expect(unit, isNotNull); | 1344 expect(unit, isNotNull); |
1345 ConstantValueComputer computer = _makeConstantValueComputer(); | 1345 ConstantValueComputer computer = _makeConstantValueComputer(); |
1346 computer.add(unit, librarySource, librarySource); | 1346 computer.add(unit, librarySource, librarySource); |
1347 computer.computeValues(); | 1347 computer.computeValues(); |
1348 NodeList<CompilationUnitMember> members = unit.declarations; | 1348 NodeList<CompilationUnitMember> members = unit.declarations; |
1349 expect(members, hasLength(1)); | 1349 expect(members, hasLength(1)); |
1350 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); | 1350 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); |
1351 } | 1351 } |
1352 | 1352 |
1353 void test_computeValues_value_depends_on_enum() { | 1353 void test_computeValues_value_depends_on_enum() { |
1354 Source librarySource = addSource(''' | 1354 Source librarySource = addSource(''' |
1355 enum E { id0, id1 } | 1355 enum E { id0, id1 } |
1356 const E e = E.id0; | 1356 const E e = E.id0; |
1357 '''); | 1357 '''); |
1358 LibraryElement libraryElement = resolve(librarySource); | 1358 LibraryElement libraryElement = resolve2(librarySource); |
1359 CompilationUnit unit = | 1359 CompilationUnit unit = |
1360 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1360 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
1361 expect(unit, isNotNull); | 1361 expect(unit, isNotNull); |
1362 ConstantValueComputer computer = _makeConstantValueComputer(); | 1362 ConstantValueComputer computer = _makeConstantValueComputer(); |
1363 computer.add(unit, librarySource, librarySource); | 1363 computer.add(unit, librarySource, librarySource); |
1364 computer.computeValues(); | 1364 computer.computeValues(); |
1365 TopLevelVariableDeclaration declaration = unit.declarations | 1365 TopLevelVariableDeclaration declaration = unit.declarations |
1366 .firstWhere((member) => member is TopLevelVariableDeclaration); | 1366 .firstWhere((member) => member is TopLevelVariableDeclaration); |
1367 _validate(true, declaration.variables); | 1367 _validate(true, declaration.variables); |
1368 } | 1368 } |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2164 } | 2164 } |
2165 | 2165 |
2166 void _assertNullField(Map<String, DartObjectImpl> fields, String fieldName) { | 2166 void _assertNullField(Map<String, DartObjectImpl> fields, String fieldName) { |
2167 DartObjectImpl field = fields[fieldName]; | 2167 DartObjectImpl field = fields[fieldName]; |
2168 expect(field.isNull, isTrue); | 2168 expect(field.isNull, isTrue); |
2169 } | 2169 } |
2170 | 2170 |
2171 void _assertProperDependencies(String sourceText, | 2171 void _assertProperDependencies(String sourceText, |
2172 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { | 2172 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { |
2173 Source source = addSource(sourceText); | 2173 Source source = addSource(sourceText); |
2174 LibraryElement element = resolve(source); | 2174 LibraryElement element = resolve2(source); |
2175 CompilationUnit unit = | 2175 CompilationUnit unit = |
2176 analysisContext.resolveCompilationUnit(source, element); | 2176 analysisContext.resolveCompilationUnit(source, element); |
2177 expect(unit, isNotNull); | 2177 expect(unit, isNotNull); |
2178 ConstantValueComputer computer = _makeConstantValueComputer(); | 2178 ConstantValueComputer computer = _makeConstantValueComputer(); |
2179 computer.add(unit, source, source); | 2179 computer.add(unit, source, source); |
2180 computer.computeValues(); | 2180 computer.computeValues(); |
2181 assertErrors(source, expectedErrorCodes); | 2181 assertErrors(source, expectedErrorCodes); |
2182 } | 2182 } |
2183 | 2183 |
2184 Map<String, DartObjectImpl> _assertType( | 2184 Map<String, DartObjectImpl> _assertType( |
(...skipping 4401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6586 * | 6586 * |
6587 * [code] the code to resolve. | 6587 * [code] the code to resolve. |
6588 * | 6588 * |
6589 * Returns the result of resolving the AST structure representing the content | 6589 * Returns the result of resolving the AST structure representing the content |
6590 * of the source. | 6590 * of the source. |
6591 * | 6591 * |
6592 * Throws if source cannot be verified. | 6592 * Throws if source cannot be verified. |
6593 */ | 6593 */ |
6594 CompilationUnit _resolveContents(String code) { | 6594 CompilationUnit _resolveContents(String code) { |
6595 Source source = addSource(code); | 6595 Source source = addSource(code); |
6596 LibraryElement library = resolve(source); | 6596 LibraryElement library = resolve2(source); |
6597 assertNoErrors(source); | 6597 assertNoErrors(source); |
6598 verify([source]); | 6598 verify([source]); |
6599 return analysisContext.resolveCompilationUnit(source, library); | 6599 return analysisContext.resolveCompilationUnit(source, library); |
6600 } | 6600 } |
6601 } | 6601 } |
6602 | 6602 |
6603 @reflectiveTest | 6603 @reflectiveTest |
6604 class EnumMemberBuilderTest extends EngineTestCase { | 6604 class EnumMemberBuilderTest extends EngineTestCase { |
6605 void test_visitEnumDeclaration_multiple() { | 6605 void test_visitEnumDeclaration_multiple() { |
6606 String firstName = "ONE"; | 6606 String firstName = "ONE"; |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7325 var x; | 7325 var x; |
7326 switch (e) { | 7326 switch (e) { |
7327 case A: | 7327 case A: |
7328 x = 'A'; | 7328 x = 'A'; |
7329 case B: | 7329 case B: |
7330 x = 'B'; | 7330 x = 'B'; |
7331 } | 7331 } |
7332 return x; | 7332 return x; |
7333 } | 7333 } |
7334 '''); | 7334 '''); |
7335 LibraryElement element = resolve(source); | 7335 LibraryElement element = resolve2(source); |
7336 CompilationUnit unit = resolveCompilationUnit(source, element); | 7336 CompilationUnit unit = resolveCompilationUnit(source, element); |
7337 FunctionDeclaration function = unit.declarations.last; | 7337 FunctionDeclaration function = unit.declarations.last; |
7338 BlockFunctionBody body = function.functionExpression.body; | 7338 BlockFunctionBody body = function.functionExpression.body; |
7339 Statement statement = body.block.statements[1]; | 7339 Statement statement = body.block.statements[1]; |
7340 expect(ExitDetector.exits(statement), false); | 7340 expect(ExitDetector.exits(statement), false); |
7341 } | 7341 } |
7342 | 7342 |
7343 void test_switch_withEnum_false_withDefault() { | 7343 void test_switch_withEnum_false_withDefault() { |
7344 Source source = addSource(r''' | 7344 Source source = addSource(r''' |
7345 enum E { A, B } | 7345 enum E { A, B } |
7346 String f(E e) { | 7346 String f(E e) { |
7347 var x; | 7347 var x; |
7348 switch (e) { | 7348 switch (e) { |
7349 case A: | 7349 case A: |
7350 x = 'A'; | 7350 x = 'A'; |
7351 default: | 7351 default: |
7352 x = '?'; | 7352 x = '?'; |
7353 } | 7353 } |
7354 return x; | 7354 return x; |
7355 } | 7355 } |
7356 '''); | 7356 '''); |
7357 LibraryElement element = resolve(source); | 7357 LibraryElement element = resolve2(source); |
7358 CompilationUnit unit = resolveCompilationUnit(source, element); | 7358 CompilationUnit unit = resolveCompilationUnit(source, element); |
7359 FunctionDeclaration function = unit.declarations.last; | 7359 FunctionDeclaration function = unit.declarations.last; |
7360 BlockFunctionBody body = function.functionExpression.body; | 7360 BlockFunctionBody body = function.functionExpression.body; |
7361 Statement statement = body.block.statements[1]; | 7361 Statement statement = body.block.statements[1]; |
7362 expect(ExitDetector.exits(statement), false); | 7362 expect(ExitDetector.exits(statement), false); |
7363 } | 7363 } |
7364 | 7364 |
7365 void test_switch_withEnum_true_noDefault() { | 7365 void test_switch_withEnum_true_noDefault() { |
7366 Source source = addSource(r''' | 7366 Source source = addSource(r''' |
7367 enum E { A, B } | 7367 enum E { A, B } |
7368 String f(E e) { | 7368 String f(E e) { |
7369 switch (e) { | 7369 switch (e) { |
7370 case A: | 7370 case A: |
7371 return 'A'; | 7371 return 'A'; |
7372 case B: | 7372 case B: |
7373 return 'B'; | 7373 return 'B'; |
7374 } | 7374 } |
7375 } | 7375 } |
7376 '''); | 7376 '''); |
7377 LibraryElement element = resolve(source); | 7377 LibraryElement element = resolve2(source); |
7378 CompilationUnit unit = resolveCompilationUnit(source, element); | 7378 CompilationUnit unit = resolveCompilationUnit(source, element); |
7379 FunctionDeclaration function = unit.declarations.last; | 7379 FunctionDeclaration function = unit.declarations.last; |
7380 BlockFunctionBody body = function.functionExpression.body; | 7380 BlockFunctionBody body = function.functionExpression.body; |
7381 Statement statement = body.block.statements[0]; | 7381 Statement statement = body.block.statements[0]; |
7382 expect(ExitDetector.exits(statement), true); | 7382 expect(ExitDetector.exits(statement), true); |
7383 } | 7383 } |
7384 | 7384 |
7385 void test_switch_withEnum_true_withDefault() { | 7385 void test_switch_withEnum_true_withDefault() { |
7386 Source source = addSource(r''' | 7386 Source source = addSource(r''' |
7387 enum E { A, B } | 7387 enum E { A, B } |
7388 String f(E e) { | 7388 String f(E e) { |
7389 switch (e) { | 7389 switch (e) { |
7390 case A: | 7390 case A: |
7391 return 'A'; | 7391 return 'A'; |
7392 default: | 7392 default: |
7393 return '?'; | 7393 return '?'; |
7394 } | 7394 } |
7395 } | 7395 } |
7396 '''); | 7396 '''); |
7397 LibraryElement element = resolve(source); | 7397 LibraryElement element = resolve2(source); |
7398 CompilationUnit unit = resolveCompilationUnit(source, element); | 7398 CompilationUnit unit = resolveCompilationUnit(source, element); |
7399 FunctionDeclaration function = unit.declarations.last; | 7399 FunctionDeclaration function = unit.declarations.last; |
7400 BlockFunctionBody body = function.functionExpression.body; | 7400 BlockFunctionBody body = function.functionExpression.body; |
7401 Statement statement = body.block.statements[0]; | 7401 Statement statement = body.block.statements[0]; |
7402 expect(ExitDetector.exits(statement), true); | 7402 expect(ExitDetector.exits(statement), true); |
7403 } | 7403 } |
7404 } | 7404 } |
7405 | 7405 |
7406 @reflectiveTest | 7406 @reflectiveTest |
7407 class FileBasedSourceTest { | 7407 class FileBasedSourceTest { |
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8754 if (_expectedExternalScriptName == null) { | 8754 if (_expectedExternalScriptName == null) { |
8755 expect(scriptSource, isNull, reason: "script $scriptIndex"); | 8755 expect(scriptSource, isNull, reason: "script $scriptIndex"); |
8756 } else { | 8756 } else { |
8757 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | 8757 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); |
8758 String actualExternalScriptName = scriptSource.shortName; | 8758 String actualExternalScriptName = scriptSource.shortName; |
8759 expect(actualExternalScriptName, _expectedExternalScriptName, | 8759 expect(actualExternalScriptName, _expectedExternalScriptName, |
8760 reason: "script $scriptIndex"); | 8760 reason: "script $scriptIndex"); |
8761 } | 8761 } |
8762 } | 8762 } |
8763 } | 8763 } |
OLD | NEW |