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 test.context.directory.manager; | 5 library test.context.directory.manager; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analysis_server/src/context_manager.dart'; | 9 import 'package:analysis_server/src/context_manager.dart'; |
10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 callbacks = new TestContextManagerCallbacks(); | 89 callbacks = new TestContextManagerCallbacks(); |
90 manager.callbacks = callbacks; | 90 manager.callbacks = callbacks; |
91 resourceProvider.newFolder(projPath); | 91 resourceProvider.newFolder(projPath); |
92 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = true; | 92 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = true; |
93 } | 93 } |
94 | 94 |
95 void tearDown() { | 95 void tearDown() { |
96 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = false; | 96 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = false; |
97 } | 97 } |
98 | 98 |
| 99 void test_contextsInAnalysisRoot_nestedContext() { |
| 100 String subProjPath = join(projPath, 'subproj'); |
| 101 Folder subProjFolder = resourceProvider.newFolder(subProjPath); |
| 102 resourceProvider.newFile(join(subProjPath, 'pubspec.yaml'), 'contents'); |
| 103 String subProjFilePath = join(subProjPath, 'file.dart'); |
| 104 resourceProvider.newFile(subProjFilePath, 'contents'); |
| 105 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 106 // Make sure that there really are contexts for both the main project and |
| 107 // the subproject. |
| 108 Folder projFolder = resourceProvider.getFolder(projPath); |
| 109 ContextInfo projContextInfo = manager.getContextInfoFor(projFolder); |
| 110 expect(projContextInfo, isNotNull); |
| 111 expect(projContextInfo.folder, projFolder); |
| 112 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); |
| 113 expect(subProjContextInfo, isNotNull); |
| 114 expect(subProjContextInfo.folder, subProjFolder); |
| 115 expect(projContextInfo.context != subProjContextInfo.context, isTrue); |
| 116 // Check that contextsInAnalysisRoot() works. |
| 117 List<AnalysisContext> contexts = manager.contextsInAnalysisRoot(projFolder); |
| 118 expect(contexts.length, 2); |
| 119 expect(contexts, contains(projContextInfo.context)); |
| 120 expect(contexts, contains(subProjContextInfo.context)); |
| 121 } |
| 122 |
99 test_ignoreFilesInPackagesFolder() { | 123 test_ignoreFilesInPackagesFolder() { |
100 // create a context with a pubspec.yaml file | 124 // create a context with a pubspec.yaml file |
101 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 125 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
102 resourceProvider.newFile(pubspecPath, 'pubspec'); | 126 resourceProvider.newFile(pubspecPath, 'pubspec'); |
103 // create a file in the "packages" folder | 127 // create a file in the "packages" folder |
104 String filePath1 = posix.join(projPath, 'packages', 'file1.dart'); | 128 String filePath1 = posix.join(projPath, 'packages', 'file1.dart'); |
105 resourceProvider.newFile(filePath1, 'contents'); | 129 resourceProvider.newFile(filePath1, 'contents'); |
106 // "packages" files are ignored initially | 130 // "packages" files are ignored initially |
107 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 131 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
108 expect(callbacks.currentContextFilePaths[projPath], isEmpty); | 132 expect(callbacks.currentContextFilePaths[projPath], isEmpty); |
(...skipping 11 matching lines...) Expand all Loading... |
120 String excludedFolder = '$project/excluded'; | 144 String excludedFolder = '$project/excluded'; |
121 // set roots | 145 // set roots |
122 resourceProvider.newFolder(project); | 146 resourceProvider.newFolder(project); |
123 resourceProvider.newFolder(excludedFolder); | 147 resourceProvider.newFolder(excludedFolder); |
124 manager.setRoots( | 148 manager.setRoots( |
125 <String>[project], <String>[excludedFolder], <String, String>{}); | 149 <String>[project], <String>[excludedFolder], <String, String>{}); |
126 // verify | 150 // verify |
127 expect(manager.isInAnalysisRoot('$excludedFolder/test.dart'), isFalse); | 151 expect(manager.isInAnalysisRoot('$excludedFolder/test.dart'), isFalse); |
128 } | 152 } |
129 | 153 |
| 154 void test_isInAnalysisRoot_inNestedContext() { |
| 155 String subProjPath = join(projPath, 'subproj'); |
| 156 Folder subProjFolder = resourceProvider.newFolder(subProjPath); |
| 157 resourceProvider.newFile(join(subProjPath, 'pubspec.yaml'), 'contents'); |
| 158 String subProjFilePath = join(subProjPath, 'file.dart'); |
| 159 resourceProvider.newFile(subProjFilePath, 'contents'); |
| 160 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 161 // Make sure that there really is a context for the subproject. |
| 162 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); |
| 163 expect(subProjContextInfo, isNotNull); |
| 164 expect(subProjContextInfo.folder, subProjFolder); |
| 165 // Check that isInAnalysisRoot() works. |
| 166 expect(manager.isInAnalysisRoot(subProjFilePath), isTrue); |
| 167 } |
| 168 |
130 void test_isInAnalysisRoot_inRoot() { | 169 void test_isInAnalysisRoot_inRoot() { |
131 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 170 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
132 expect(manager.isInAnalysisRoot('$projPath/test.dart'), isTrue); | 171 expect(manager.isInAnalysisRoot('$projPath/test.dart'), isTrue); |
133 } | 172 } |
134 | 173 |
135 void test_isInAnalysisRoot_notInRoot() { | 174 void test_isInAnalysisRoot_notInRoot() { |
136 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 175 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
137 expect(manager.isInAnalysisRoot('/test.dart'), isFalse); | 176 expect(manager.isInAnalysisRoot('/test.dart'), isFalse); |
138 } | 177 } |
139 | 178 |
(...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 class TestUriResolver extends UriResolver { | 1601 class TestUriResolver extends UriResolver { |
1563 Map<Uri, Source> uriMap; | 1602 Map<Uri, Source> uriMap; |
1564 | 1603 |
1565 TestUriResolver(this.uriMap); | 1604 TestUriResolver(this.uriMap); |
1566 | 1605 |
1567 @override | 1606 @override |
1568 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 1607 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
1569 return uriMap[uri]; | 1608 return uriMap[uri]; |
1570 } | 1609 } |
1571 } | 1610 } |
OLD | NEW |