| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyzer.test.generated.resolver_test_case; | 5 library analyzer.test.generated.resolver_test_case; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| 11 import 'package:analyzer/error/error.dart'; | 11 import 'package:analyzer/error/error.dart'; |
| 12 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 12 import 'package:analyzer/file_system/physical_file_system.dart'; | 13 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 13 import 'package:analyzer/src/dart/element/element.dart'; | 14 import 'package:analyzer/src/dart/element/element.dart'; |
| 14 import 'package:analyzer/src/dart/element/type.dart'; | 15 import 'package:analyzer/src/dart/element/type.dart'; |
| 15 import 'package:analyzer/src/error/codes.dart'; | 16 import 'package:analyzer/src/error/codes.dart'; |
| 16 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/java_engine.dart'; | 18 import 'package:analyzer/src/generated/java_engine.dart'; |
| 18 import 'package:analyzer/src/generated/resolver.dart'; | 19 import 'package:analyzer/src/generated/resolver.dart'; |
| 19 import 'package:analyzer/src/generated/source_io.dart'; | 20 import 'package:analyzer/src/generated/source_io.dart'; |
| 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 21 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 21 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 22 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 buffer.write(_getFileName(identifier)); | 293 buffer.write(_getFileName(identifier)); |
| 293 buffer.write(" : "); | 294 buffer.write(" : "); |
| 294 buffer.write(identifier.offset); | 295 buffer.write(identifier.offset); |
| 295 buffer.writeln(")"); | 296 buffer.writeln(")"); |
| 296 } | 297 } |
| 297 } | 298 } |
| 298 } | 299 } |
| 299 | 300 |
| 300 class ResolverTestCase extends EngineTestCase { | 301 class ResolverTestCase extends EngineTestCase { |
| 301 /** | 302 /** |
| 303 * The resource provider used by the test case. |
| 304 */ |
| 305 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 306 |
| 307 /** |
| 302 * The analysis context used to parse the compilation units being resolved. | 308 * The analysis context used to parse the compilation units being resolved. |
| 303 */ | 309 */ |
| 304 InternalAnalysisContext analysisContext2; | 310 InternalAnalysisContext analysisContext2; |
| 305 | 311 |
| 306 /** | 312 /** |
| 307 * Specifies if [assertErrors] should check for [HintCode.UNUSED_ELEMENT] and | 313 * Specifies if [assertErrors] should check for [HintCode.UNUSED_ELEMENT] and |
| 308 * [HintCode.UNUSED_FIELD]. | 314 * [HintCode.UNUSED_FIELD]. |
| 309 */ | 315 */ |
| 310 bool enableUnusedElement = false; | 316 bool enableUnusedElement = false; |
| 311 | 317 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 325 TypeProvider get typeProvider => analysisContext2.typeProvider; | 331 TypeProvider get typeProvider => analysisContext2.typeProvider; |
| 326 | 332 |
| 327 /** | 333 /** |
| 328 * Return a type system that can be used to test the results of resolution. | 334 * Return a type system that can be used to test the results of resolution. |
| 329 * | 335 * |
| 330 * @return a type system | 336 * @return a type system |
| 331 */ | 337 */ |
| 332 TypeSystem get typeSystem => analysisContext2.typeSystem; | 338 TypeSystem get typeSystem => analysisContext2.typeSystem; |
| 333 | 339 |
| 334 /** | 340 /** |
| 335 * Add a source file to the content provider. The file path should be absolute
. | 341 * Add a source file with the given [filePath] in the root of the file system. |
| 336 * | 342 * The file path should be absolute. The file will have the given [contents] |
| 337 * @param filePath the path of the file being added | 343 * set in the content provider. Return the source representing the added file. |
| 338 * @param contents the contents to be returned by the content provider for the
specified file | |
| 339 * @return the source object representing the added file | |
| 340 */ | 344 */ |
| 341 Source addNamedSource(String filePath, String contents) { | 345 Source addNamedSource(String filePath, String contents) { |
| 342 Source source = cacheSource(filePath, contents); | 346 Source source = |
| 347 cacheSource(resourceProvider.convertPath(filePath), contents); |
| 343 ChangeSet changeSet = new ChangeSet(); | 348 ChangeSet changeSet = new ChangeSet(); |
| 344 changeSet.addedSource(source); | 349 changeSet.addedSource(source); |
| 345 analysisContext2.applyChanges(changeSet); | 350 analysisContext2.applyChanges(changeSet); |
| 346 return source; | 351 return source; |
| 347 } | 352 } |
| 348 | 353 |
| 349 /** | 354 /** |
| 350 * Add a source file to the content provider. | 355 * Add a source file named 'test.dart' in the root of the file system. The |
| 351 * | 356 * file will have the given [contents] set in the content provider. Return the |
| 352 * @param contents the contents to be returned by the content provider for the
specified file | 357 * source representing the added file. |
| 353 * @return the source object representing the added file | |
| 354 */ | 358 */ |
| 355 Source addSource(String contents) => addNamedSource("/test.dart", contents); | 359 Source addSource(String contents) => addNamedSource("/test.dart", contents); |
| 356 | 360 |
| 357 /** | 361 /** |
| 358 * Assert that the number of errors reported against the given source matches
the number of errors | 362 * Assert that the number of errors reported against the given source matches
the number of errors |
| 359 * that are given and that they have the expected error codes. The order in wh
ich the errors were | 363 * that are given and that they have the expected error codes. The order in wh
ich the errors were |
| 360 * gathered is ignored. | 364 * gathered is ignored. |
| 361 * | 365 * |
| 362 * @param source the source against which the errors should have been reported | 366 * @param source the source against which the errors should have been reported |
| 363 * @param expectedErrorCodes the error codes of the errors that should have be
en reported | 367 * @param expectedErrorCodes the error codes of the errors that should have be
en reported |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 return variable; | 611 return variable; |
| 608 } | 612 } |
| 609 } | 613 } |
| 610 } | 614 } |
| 611 } | 615 } |
| 612 return null; | 616 return null; |
| 613 // Not found | 617 // Not found |
| 614 } | 618 } |
| 615 | 619 |
| 616 /** | 620 /** |
| 617 * In the rare cases we want to group several tests into single "test_" method
, so need a way to | 621 * Re-create the analysis context being used by the test case. |
| 618 * reset test instance to reuse it. | |
| 619 */ | 622 */ |
| 620 void reset() { | 623 void reset() { |
| 621 analysisContext2 = AnalysisContextFactory.contextWithCore(); | 624 analysisContext2 = AnalysisContextFactory.contextWithCore( |
| 625 resourceProvider: resourceProvider); |
| 622 } | 626 } |
| 623 | 627 |
| 624 /** | 628 /** |
| 625 * Reset the analysis context to have the given options applied. | 629 * Re-create the analysis context being used by the test case and set the |
| 626 * | 630 * [options] in the newly created context to the given [options]. |
| 627 * @param options the analysis options to be applied to the context | |
| 628 */ | 631 */ |
| 629 void resetWithOptions(AnalysisOptions options) { | 632 void resetWithOptions(AnalysisOptions options) { |
| 630 analysisContext2 = | 633 analysisContext2 = AnalysisContextFactory.contextWithCoreAndOptions(options, |
| 631 AnalysisContextFactory.contextWithCoreAndOptions(options); | 634 resourceProvider: resourceProvider); |
| 632 } | 635 } |
| 633 | 636 |
| 634 /** | 637 /** |
| 635 * Given a library and all of its parts, resolve the contents of the library a
nd the contents of | 638 * Given a library and all of its parts, resolve the contents of the library a
nd the contents of |
| 636 * the parts. This assumes that the sources for the library and its parts have
already been added | 639 * the parts. This assumes that the sources for the library and its parts have
already been added |
| 637 * to the content provider using the method [addNamedSource]. | 640 * to the content provider using the method [addNamedSource]. |
| 638 * | 641 * |
| 639 * @param librarySource the source for the compilation unit that defines the l
ibrary | 642 * @param librarySource the source for the compilation unit that defines the l
ibrary |
| 640 * @return the element representing the resolved library | 643 * @return the element representing the resolved library |
| 641 * @throws AnalysisException if the analysis could not be performed | 644 * @throws AnalysisException if the analysis could not be performed |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 * text. Otherwise, [expected] is used directly a [Matcher] to match the type. | 838 * text. Otherwise, [expected] is used directly a [Matcher] to match the type. |
| 836 */ | 839 */ |
| 837 _expectType(DartType type, expected) { | 840 _expectType(DartType type, expected) { |
| 838 if (expected is String) { | 841 if (expected is String) { |
| 839 expect(type.toString(), expected); | 842 expect(type.toString(), expected); |
| 840 } else { | 843 } else { |
| 841 expect(type, expected); | 844 expect(type, expected); |
| 842 } | 845 } |
| 843 } | 846 } |
| 844 } | 847 } |
| OLD | NEW |