| 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 library analyzer.test.generated.all_the_rest_test; | 5 library analyzer.test.generated.all_the_rest_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
| 10 import 'package:analyzer/file_system/physical_file_system.dart'; | 10 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 11 import 'package:analyzer/src/dart/ast/utilities.dart' hide ConstantEvaluator; | 11 import 'package:analyzer/src/dart/ast/utilities.dart' hide ConstantEvaluator; |
| 12 import 'package:analyzer/src/dart/element/element.dart'; | 12 import 'package:analyzer/src/dart/element/element.dart'; |
| 13 import 'package:analyzer/src/generated/constant.dart'; | 13 import 'package:analyzer/src/generated/constant.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
| 16 import 'package:analyzer/src/generated/java_core.dart'; | 16 import 'package:analyzer/src/generated/java_core.dart'; |
| 17 import 'package:analyzer/src/generated/java_engine_io.dart'; | 17 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 18 import 'package:analyzer/src/generated/java_io.dart'; | 18 import 'package:analyzer/src/generated/java_io.dart'; |
| 19 import 'package:analyzer/src/generated/resolver.dart'; | 19 import 'package:analyzer/src/generated/resolver.dart'; |
| 20 import 'package:analyzer/src/generated/scanner.dart'; | 20 import 'package:analyzer/src/generated/scanner.dart'; |
| 21 import 'package:analyzer/src/generated/sdk.dart'; | 21 import 'package:analyzer/src/generated/sdk.dart'; |
| 22 import 'package:analyzer/src/generated/sdk_io.dart'; | 22 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 23 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
| 24 import 'package:analyzer/src/generated/source_io.dart'; | 24 import 'package:analyzer/src/generated/source_io.dart'; |
| 25 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 25 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 26 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 26 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 27 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | 27 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
| 28 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 28 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
| 29 import 'package:analyzer/src/generated/utilities_collection.dart'; | |
| 30 import 'package:analyzer/src/generated/utilities_dart.dart'; | 29 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 31 import 'package:analyzer/src/task/dart.dart'; | |
| 32 import 'package:path/path.dart'; | 30 import 'package:path/path.dart'; |
| 33 import 'package:source_span/source_span.dart'; | 31 import 'package:source_span/source_span.dart'; |
| 34 import 'package:unittest/unittest.dart'; | 32 import 'package:unittest/unittest.dart'; |
| 35 | 33 |
| 36 import '../reflective_tests.dart'; | 34 import '../reflective_tests.dart'; |
| 37 import '../utils.dart'; | 35 import '../utils.dart'; |
| 38 import 'parser_test.dart'; | 36 import 'parser_test.dart'; |
| 39 import 'resolver_test.dart'; | 37 import 'resolver_test.dart'; |
| 40 import 'test_support.dart'; | 38 import 'test_support.dart'; |
| 41 | 39 |
| 42 main() { | 40 main() { |
| 43 initializeTestEnvironment(); | 41 initializeTestEnvironment(); |
| 44 runReflectiveTests(ContentCacheTest); | 42 runReflectiveTests(ContentCacheTest); |
| 45 runReflectiveTests(CustomUriResolverTest); | 43 runReflectiveTests(CustomUriResolverTest); |
| 46 runReflectiveTests(DartObjectImplTest); | 44 runReflectiveTests(DartObjectImplTest); |
| 47 runReflectiveTests(DartUriResolverTest); | 45 runReflectiveTests(DartUriResolverTest); |
| 48 runReflectiveTests(DeclaredVariablesTest); | 46 runReflectiveTests(DeclaredVariablesTest); |
| 49 runReflectiveTests(DirectoryBasedDartSdkTest); | 47 runReflectiveTests(DirectoryBasedDartSdkTest); |
| 50 runReflectiveTests(DirectoryBasedSourceContainerTest); | 48 runReflectiveTests(DirectoryBasedSourceContainerTest); |
| 51 runReflectiveTests(ElementBuilderTest); | 49 runReflectiveTests(ElementBuilderTest); |
| 52 runReflectiveTests(ElementLocatorTest); | 50 runReflectiveTests(ElementLocatorTest); |
| 53 runReflectiveTests(EnumMemberBuilderTest); | 51 runReflectiveTests(EnumMemberBuilderTest); |
| 54 runReflectiveTests(ErrorReporterTest); | 52 runReflectiveTests(ErrorReporterTest); |
| 55 runReflectiveTests(ErrorSeverityTest); | 53 runReflectiveTests(ErrorSeverityTest); |
| 56 runReflectiveTests(ExitDetectorTest); | 54 runReflectiveTests(ExitDetectorTest); |
| 57 runReflectiveTests(ExitDetectorTest2); | 55 runReflectiveTests(ExitDetectorTest2); |
| 58 runReflectiveTests(FileBasedSourceTest); | 56 runReflectiveTests(FileBasedSourceTest); |
| 59 runReflectiveTests(FileUriResolverTest); | 57 runReflectiveTests(FileUriResolverTest); |
| 60 runReflectiveTests(ReferenceFinderTest); | |
| 61 runReflectiveTests(SDKLibrariesReaderTest); | 58 runReflectiveTests(SDKLibrariesReaderTest); |
| 62 runReflectiveTests(UriKindTest); | 59 runReflectiveTests(UriKindTest); |
| 63 } | 60 } |
| 64 | 61 |
| 65 @reflectiveTest | 62 @reflectiveTest |
| 66 class ContentCacheTest { | 63 class ContentCacheTest { |
| 67 void test_setContents() { | 64 void test_setContents() { |
| 68 Source source = new TestSource(); | 65 Source source = new TestSource(); |
| 69 ContentCache cache = new ContentCache(); | 66 ContentCache cache = new ContentCache(); |
| 70 expect(cache.getContents(source), isNull); | 67 expect(cache.getContents(source), isNull); |
| (...skipping 5863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5934 Source fromFileUri(Uri uri) => null; | 5931 Source fromFileUri(Uri uri) => null; |
| 5935 | 5932 |
| 5936 @override | 5933 @override |
| 5937 SdkLibrary getSdkLibrary(String dartUri) => null; | 5934 SdkLibrary getSdkLibrary(String dartUri) => null; |
| 5938 | 5935 |
| 5939 @override | 5936 @override |
| 5940 Source mapDartUri(String dartUri) => null; | 5937 Source mapDartUri(String dartUri) => null; |
| 5941 } | 5938 } |
| 5942 | 5939 |
| 5943 @reflectiveTest | 5940 @reflectiveTest |
| 5944 class ReferenceFinderTest { | |
| 5945 DirectedGraph<ConstantEvaluationTarget> _referenceGraph; | |
| 5946 VariableElement _head; | |
| 5947 Element _tail; | |
| 5948 | |
| 5949 void setUp() { | |
| 5950 _referenceGraph = new DirectedGraph<ConstantEvaluationTarget>(); | |
| 5951 _head = ElementFactory.topLevelVariableElement2("v1"); | |
| 5952 } | |
| 5953 | |
| 5954 void test_visitSimpleIdentifier_const() { | |
| 5955 _visitNode(_makeTailVariable("v2", true)); | |
| 5956 _assertOneArc(_tail); | |
| 5957 } | |
| 5958 | |
| 5959 void test_visitSimpleIdentifier_nonConst() { | |
| 5960 _visitNode(_makeTailVariable("v2", false)); | |
| 5961 _assertOneArc(_tail); | |
| 5962 } | |
| 5963 | |
| 5964 void test_visitSuperConstructorInvocation_const() { | |
| 5965 _visitNode(_makeTailSuperConstructorInvocation("A", true)); | |
| 5966 _assertOneArc(_tail); | |
| 5967 } | |
| 5968 | |
| 5969 void test_visitSuperConstructorInvocation_nonConst() { | |
| 5970 _visitNode(_makeTailSuperConstructorInvocation("A", false)); | |
| 5971 _assertOneArc(_tail); | |
| 5972 } | |
| 5973 | |
| 5974 void test_visitSuperConstructorInvocation_unresolved() { | |
| 5975 SuperConstructorInvocation superConstructorInvocation = | |
| 5976 AstFactory.superConstructorInvocation(); | |
| 5977 _visitNode(superConstructorInvocation); | |
| 5978 _assertNoArcs(); | |
| 5979 } | |
| 5980 | |
| 5981 void _assertNoArcs() { | |
| 5982 Set<ConstantEvaluationTarget> tails = _referenceGraph.getTails(_head); | |
| 5983 expect(tails, hasLength(0)); | |
| 5984 } | |
| 5985 | |
| 5986 void _assertOneArc(Element tail) { | |
| 5987 Set<ConstantEvaluationTarget> tails = _referenceGraph.getTails(_head); | |
| 5988 expect(tails, hasLength(1)); | |
| 5989 expect(tails.first, same(tail)); | |
| 5990 } | |
| 5991 | |
| 5992 ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) => | |
| 5993 new ReferenceFinder((ConstantEvaluationTarget dependency) { | |
| 5994 _referenceGraph.addEdge(source, dependency); | |
| 5995 }); | |
| 5996 SuperConstructorInvocation _makeTailSuperConstructorInvocation( | |
| 5997 String name, bool isConst) { | |
| 5998 List<ConstructorInitializer> initializers = | |
| 5999 new List<ConstructorInitializer>(); | |
| 6000 ConstructorDeclaration constructorDeclaration = | |
| 6001 AstFactory.constructorDeclaration(AstFactory.identifier3(name), null, | |
| 6002 AstFactory.formalParameterList(), initializers); | |
| 6003 if (isConst) { | |
| 6004 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); | |
| 6005 } | |
| 6006 ClassElementImpl classElement = ElementFactory.classElement2(name); | |
| 6007 SuperConstructorInvocation superConstructorInvocation = | |
| 6008 AstFactory.superConstructorInvocation(); | |
| 6009 ConstructorElementImpl constructorElement = | |
| 6010 ElementFactory.constructorElement(classElement, name, isConst); | |
| 6011 _tail = constructorElement; | |
| 6012 superConstructorInvocation.staticElement = constructorElement; | |
| 6013 return superConstructorInvocation; | |
| 6014 } | |
| 6015 | |
| 6016 SimpleIdentifier _makeTailVariable(String name, bool isConst) { | |
| 6017 VariableDeclaration variableDeclaration = | |
| 6018 AstFactory.variableDeclaration(name); | |
| 6019 ConstLocalVariableElementImpl variableElement = | |
| 6020 ElementFactory.constLocalVariableElement(name); | |
| 6021 _tail = variableElement; | |
| 6022 variableElement.const3 = isConst; | |
| 6023 AstFactory.variableDeclarationList2( | |
| 6024 isConst ? Keyword.CONST : Keyword.VAR, [variableDeclaration]); | |
| 6025 SimpleIdentifier identifier = AstFactory.identifier3(name); | |
| 6026 identifier.staticElement = variableElement; | |
| 6027 return identifier; | |
| 6028 } | |
| 6029 | |
| 6030 void _visitNode(AstNode node) { | |
| 6031 node.accept(_createReferenceFinder(_head)); | |
| 6032 } | |
| 6033 } | |
| 6034 | |
| 6035 @reflectiveTest | |
| 6036 class SDKLibrariesReaderTest extends EngineTestCase { | 5941 class SDKLibrariesReaderTest extends EngineTestCase { |
| 6037 void test_readFrom_dart2js() { | 5942 void test_readFrom_dart2js() { |
| 6038 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile( | 5943 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile( |
| 6039 FileUtilities2.createFile("/libs.dart"), | 5944 FileUtilities2.createFile("/libs.dart"), |
| 6040 r''' | 5945 r''' |
| 6041 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 5946 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
| 6042 'first' : const LibraryInfo( | 5947 'first' : const LibraryInfo( |
| 6043 'first/first.dart', | 5948 'first/first.dart', |
| 6044 categories: 'Client', | 5949 categories: 'Client', |
| 6045 documented: true, | 5950 documented: true, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6115 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); | 6020 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); |
| 6116 expect(UriKind.fromEncoding(0x58), same(null)); | 6021 expect(UriKind.fromEncoding(0x58), same(null)); |
| 6117 } | 6022 } |
| 6118 | 6023 |
| 6119 void test_getEncoding() { | 6024 void test_getEncoding() { |
| 6120 expect(UriKind.DART_URI.encoding, 0x64); | 6025 expect(UriKind.DART_URI.encoding, 0x64); |
| 6121 expect(UriKind.FILE_URI.encoding, 0x66); | 6026 expect(UriKind.FILE_URI.encoding, 0x66); |
| 6122 expect(UriKind.PACKAGE_URI.encoding, 0x70); | 6027 expect(UriKind.PACKAGE_URI.encoding, 0x70); |
| 6123 } | 6028 } |
| 6124 } | 6029 } |
| OLD | NEW |