Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: pkg/analysis_server/test/single_context_manager_test.dart

Issue 1920993002: Support for replacing of the context folder. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/test/context_manager_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 test.analysis_server.src.single_context_manager; 5 library test.analysis_server.src.single_context_manager;
6 6
7 import 'dart:core' hide Resource; 7 import 'dart:core' hide Resource;
8 8
9 import 'package:analysis_server/src/single_context_manager.dart'; 9 import 'package:analysis_server/src/single_context_manager.dart';
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 void setUp() { 70 void setUp() {
71 rootFolder = resourceProvider.newFolder(projPath); 71 rootFolder = resourceProvider.newFolder(projPath);
72 packageResolver = new TestUriResolver(resourceProvider, rootFolder); 72 packageResolver = new TestUriResolver(resourceProvider, rootFolder);
73 73
74 _processRequiredPlugins(); 74 _processRequiredPlugins();
75 DartSdkManager sdkManager = new DartSdkManager((_) { 75 DartSdkManager sdkManager = new DartSdkManager((_) {
76 return new MockSdk(); 76 return new MockSdk();
77 }); 77 });
78 manager = new SingleContextManager(resourceProvider, sdkManager, 78 manager = new SingleContextManager(resourceProvider, sdkManager,
79 _providePackageResolver, analysisFilesGlobs); 79 () => packageResolver, analysisFilesGlobs);
80 callbacks = new TestContextManagerCallbacks(resourceProvider); 80 callbacks = new TestContextManagerCallbacks(resourceProvider);
81 manager.callbacks = callbacks; 81 manager.callbacks = callbacks;
82 resourceProvider.newFolder(projPath); 82 resourceProvider.newFolder(projPath);
83 } 83 }
84 84
85 void test_setRoots_addFolderWithDartFile() { 85 void test_setRoots_addFolderWithDartFile() {
86 String filePath = posix.join(projPath, 'lib', 'foo.dart'); 86 String filePath = posix.join(projPath, 'lib', 'foo.dart');
87 resourceProvider.newFile(filePath, 'contents'); 87 resourceProvider.newFile(filePath, 'contents');
88 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 88 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
89 // verify 89 // verify
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // exclude "bbb/" 240 // exclude "bbb/"
241 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); 241 manager.setRoots(<String>[project], <String>[folderB], <String, String>{});
242 callbacks.assertContextPaths([project]); 242 callbacks.assertContextPaths([project]);
243 callbacks.assertContextFiles(project, [fileA]); 243 callbacks.assertContextFiles(project, [fileA]);
244 // stop excluding "bbb/" 244 // stop excluding "bbb/"
245 manager.setRoots(<String>[project], <String>[], <String, String>{}); 245 manager.setRoots(<String>[project], <String>[], <String, String>{});
246 callbacks.assertContextPaths([project]); 246 callbacks.assertContextPaths([project]);
247 callbacks.assertContextFiles(project, [fileA, fileB]); 247 callbacks.assertContextFiles(project, [fileA, fileB]);
248 } 248 }
249 249
250 void test_setRoots_newContextFolder_replace() {
251 String contextPath1 = '/context1';
252 String root11 = '$contextPath1/root1';
253 String root12 = '$contextPath1/root2';
254 String file11 = '$root11/file1.dart';
255 String file12 = '$root12/file2.dart';
256 String contextPath2 = '/context2';
257 String root21 = '$contextPath2/root1';
258 String root22 = '$contextPath2/root2';
259 String file21 = '$root21/file1.dart';
260 String file22 = '$root22/file2.dart';
261 // create files
262 resourceProvider.newFile(file11, '');
263 resourceProvider.newFile(file12, '');
264 resourceProvider.newFile(file21, '');
265 resourceProvider.newFile(file22, '');
266 // set roots in '/context1'
267 manager.setRoots(<String>[root11, root12], <String>[], <String, String>{});
268 callbacks.assertContextPaths([contextPath1]);
269 callbacks.assertContextFiles(contextPath1, [file11, file12]);
270 // set roots in '/context2'
271 manager.setRoots(<String>[root21, root22], <String>[], <String, String>{});
272 callbacks.assertContextPaths([contextPath2]);
273 callbacks.assertContextFiles(contextPath2, [file21, file22]);
274 }
275
250 void test_setRoots_pathContainsDotFile() { 276 void test_setRoots_pathContainsDotFile() {
251 // If the path to a file (relative to the context root) contains a folder 277 // If the path to a file (relative to the context root) contains a folder
252 // whose name begins with '.', then the file is ignored. 278 // whose name begins with '.', then the file is ignored.
253 String project = '/project'; 279 String project = '/project';
254 String fileA = '$project/foo.dart'; 280 String fileA = '$project/foo.dart';
255 String fileB = '$project/.pub/bar.dart'; 281 String fileB = '$project/.pub/bar.dart';
256 resourceProvider.newFile(fileA, ''); 282 resourceProvider.newFile(fileA, '');
257 resourceProvider.newFile(fileB, ''); 283 resourceProvider.newFile(fileB, '');
258 manager.setRoots(<String>[project], <String>[], <String, String>{}); 284 manager.setRoots(<String>[project], <String>[], <String, String>{});
259 callbacks.assertContextPaths([project]); 285 callbacks.assertContextPaths([project]);
(...skipping 14 matching lines...) Expand all
274 300
275 void _processRequiredPlugins() { 301 void _processRequiredPlugins() {
276 List<Plugin> plugins = <Plugin>[]; 302 List<Plugin> plugins = <Plugin>[];
277 plugins.addAll(AnalysisEngine.instance.requiredPlugins); 303 plugins.addAll(AnalysisEngine.instance.requiredPlugins);
278 plugins.add(AnalysisEngine.instance.commandLinePlugin); 304 plugins.add(AnalysisEngine.instance.commandLinePlugin);
279 plugins.add(AnalysisEngine.instance.optionsPlugin); 305 plugins.add(AnalysisEngine.instance.optionsPlugin);
280 plugins.add(linterPlugin); 306 plugins.add(linterPlugin);
281 ExtensionManager manager = new ExtensionManager(); 307 ExtensionManager manager = new ExtensionManager();
282 manager.processPlugins(plugins); 308 manager.processPlugins(plugins);
283 } 309 }
284
285 UriResolver _providePackageResolver(Folder folder) => packageResolver;
286 } 310 }
287 311
288 class TestUriResolver extends UriResolver { 312 class TestUriResolver extends UriResolver {
289 final ResourceProvider resourceProvider; 313 final ResourceProvider resourceProvider;
290 final Folder rootFolder; 314 final Folder rootFolder;
291 315
292 TestUriResolver(this.resourceProvider, this.rootFolder); 316 TestUriResolver(this.resourceProvider, this.rootFolder);
293 317
294 @override 318 @override
295 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 319 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
296 if (uri.scheme == 'package') { 320 if (uri.scheme == 'package') {
297 List<String> segments = uri.pathSegments; 321 List<String> segments = uri.pathSegments;
298 if (segments.length >= 2) { 322 if (segments.length >= 2) {
299 List<String> relSegments = <String>['lib']..addAll(segments.skip(1)); 323 List<String> relSegments = <String>['lib']..addAll(segments.skip(1));
300 String relPath = resourceProvider.pathContext.joinAll(relSegments); 324 String relPath = resourceProvider.pathContext.joinAll(relSegments);
301 Resource file = rootFolder.getChild(relPath); 325 Resource file = rootFolder.getChild(relPath);
302 if (file is File && file.exists) { 326 if (file is File && file.exists) {
303 return file.createSource(uri); 327 return file.createSource(uri);
304 } 328 }
305 } 329 }
306 } 330 }
307 return null; 331 return null;
308 } 332 }
309 } 333 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/context_manager_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698