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

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

Issue 946803002: Create package: URIs everywhere (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
OLDNEW
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 void test_setRoots_addFolderWithDummyLink() { 183 void test_setRoots_addFolderWithDummyLink() {
184 String filePath = posix.join(projPath, 'foo.dart'); 184 String filePath = posix.join(projPath, 'foo.dart');
185 resourceProvider.newDummyLink(filePath); 185 resourceProvider.newDummyLink(filePath);
186 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 186 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
187 // verify 187 // verify
188 var filePaths = manager.currentContextFilePaths[projPath]; 188 var filePaths = manager.currentContextFilePaths[projPath];
189 expect(filePaths, isEmpty); 189 expect(filePaths, isEmpty);
190 } 190 }
191 191
192 void test_setRoots_addFolderWithoutPubspec() {
193 packageMapProvider.packageMap = null;
194 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
195 // verify
196 expect(manager.currentContextPaths, hasLength(1));
197 expect(manager.currentContextPaths, contains(projPath));
198 expect(manager.currentContextFilePaths[projPath], hasLength(0));
199 }
200
201 void test_setRoots_addFolderWithPubspec() { 192 void test_setRoots_addFolderWithPubspec() {
202 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); 193 String pubspecPath = posix.join(projPath, 'pubspec.yaml');
203 resourceProvider.newFile(pubspecPath, 'pubspec'); 194 resourceProvider.newFile(pubspecPath, 'pubspec');
204 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 195 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
205 // verify 196 // verify
206 expect(manager.currentContextPaths, hasLength(1)); 197 expect(manager.currentContextPaths, hasLength(1));
207 expect(manager.currentContextPaths, contains(projPath)); 198 expect(manager.currentContextPaths, contains(projPath));
208 expect(manager.currentContextFilePaths[projPath], hasLength(0)); 199 expect(manager.currentContextFilePaths[projPath], hasLength(0));
209 } 200 }
210 201
211 void test_setRoots_addFolderWithPubspecAndLib() { 202 void test_setRoots_addFolderWithPubspecAndLib() {
212 String binPath = newFolder([projPath, BIN_NAME]); 203 String binPath = newFolder([projPath, BIN_NAME]);
213 String libPath = newFolder([projPath, LIB_NAME]); 204 String libPath = newFolder([projPath, LIB_NAME]);
214 String srcPath = newFolder([libPath, SRC_NAME]); 205 String srcPath = newFolder([libPath, SRC_NAME]);
215 String testPath = newFolder([projPath, TEST_NAME]); 206 String testPath = newFolder([projPath, TEST_NAME]);
216 207
217 newFile([projPath, PUBSPEC_NAME]); 208 newFile([projPath, PUBSPEC_NAME]);
218 String appPath = newFile([binPath, 'app.dart']); 209 String appPath = newFile([binPath, 'app.dart']);
219 newFile([libPath, 'main.dart']); 210 newFile([libPath, 'main.dart']);
220 newFile([srcPath, 'internal.dart']); 211 newFile([srcPath, 'internal.dart']);
221 String testFilePath = newFile([testPath, 'main_test.dart']); 212 String testFilePath = newFile([testPath, 'main_test.dart']);
222 213
214 packageMapProvider.packageMap['proj'] =
215 [resourceProvider.getResource(libPath)];
216
223 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 217 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
224 Set<Source> sources = manager.currentContextSources[projPath]; 218 Set<Source> sources = manager.currentContextSources[projPath];
225 219
226 expect(manager.currentContextPaths, hasLength(1)); 220 expect(manager.currentContextPaths, hasLength(1));
227 expect(manager.currentContextPaths, contains(projPath)); 221 expect(manager.currentContextPaths, contains(projPath));
228 expect(sources, hasLength(4)); 222 expect(sources, hasLength(4));
229 List<String> uris = 223 List<String> uris =
230 sources.map((Source source) => source.uri.toString()).toList(); 224 sources.map((Source source) => source.uri.toString()).toList();
231 expect(uris, contains('file://$appPath')); 225 expect(uris, contains('file://$appPath'));
232 expect(uris, contains('package:proj/main.dart')); 226 expect(uris, contains('package:proj/main.dart'));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // verify package maps 261 // verify package maps
268 _checkPackageMap(root, isNull); 262 _checkPackageMap(root, isNull);
269 _checkPackageMap( 263 _checkPackageMap(
270 subProjectA, 264 subProjectA,
271 equals(packageMapProvider.packageMaps[subProjectA])); 265 equals(packageMapProvider.packageMaps[subProjectA]));
272 _checkPackageMap( 266 _checkPackageMap(
273 subProjectB, 267 subProjectB,
274 equals(packageMapProvider.packageMaps[subProjectB])); 268 equals(packageMapProvider.packageMaps[subProjectB]));
275 } 269 }
276 270
271 void test_setRoots_addFolderWithoutPubspec() {
272 packageMapProvider.packageMap = null;
273 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
274 // verify
275 expect(manager.currentContextPaths, hasLength(1));
276 expect(manager.currentContextPaths, contains(projPath));
277 expect(manager.currentContextFilePaths[projPath], hasLength(0));
278 }
279
277 void test_setRoots_addPackageRoot() { 280 void test_setRoots_addPackageRoot() {
278 String packagePathFoo = '/package1/foo'; 281 String packagePathFoo = '/package1/foo';
279 String packageRootPath = '/package2/foo'; 282 String packageRootPath = '/package2/foo';
280 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); 283 Folder packageFolder = resourceProvider.newFolder(packagePathFoo);
281 packageMapProvider.packageMap = { 284 packageMapProvider.packageMap = {
282 'foo': [packageFolder] 285 'foo': [packageFolder]
283 }; 286 };
284 List<String> includedPaths = <String>[projPath]; 287 List<String> includedPaths = <String>[projPath];
285 List<String> excludedPaths = <String>[]; 288 List<String> excludedPaths = <String>[];
286 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); 289 manager.setRoots(includedPaths, excludedPaths, <String, String>{});
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { 464 void test_setRoots_newlyAddedFoldersGetProperPackageMap() {
462 String packagePath = '/package/foo'; 465 String packagePath = '/package/foo';
463 Folder packageFolder = resourceProvider.newFolder(packagePath); 466 Folder packageFolder = resourceProvider.newFolder(packagePath);
464 packageMapProvider.packageMap = { 467 packageMapProvider.packageMap = {
465 'foo': [packageFolder] 468 'foo': [packageFolder]
466 }; 469 };
467 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 470 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
468 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); 471 _checkPackageMap(projPath, equals(packageMapProvider.packageMap));
469 } 472 }
470 473
471 void test_setRoots_removeFolderWithoutPubspec() {
472 packageMapProvider.packageMap = null;
473 // add one root - there is a context
474 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
475 expect(manager.currentContextPaths, hasLength(1));
476 // set empty roots - no contexts
477 manager.setRoots(<String>[], <String>[], <String, String>{});
478 expect(manager.currentContextPaths, hasLength(0));
479 expect(manager.currentContextFilePaths, hasLength(0));
480 }
481
482 void test_setRoots_removeFolderWithPubspec() { 474 void test_setRoots_removeFolderWithPubspec() {
483 // create a pubspec 475 // create a pubspec
484 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); 476 String pubspecPath = posix.join(projPath, 'pubspec.yaml');
485 resourceProvider.newFile(pubspecPath, 'pubspec'); 477 resourceProvider.newFile(pubspecPath, 'pubspec');
486 // add one root - there is a context 478 // add one root - there is a context
487 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 479 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
488 expect(manager.currentContextPaths, hasLength(1)); 480 expect(manager.currentContextPaths, hasLength(1));
489 // set empty roots - no contexts 481 // set empty roots - no contexts
490 manager.setRoots(<String>[], <String>[], <String, String>{}); 482 manager.setRoots(<String>[], <String>[], <String, String>{});
491 expect(manager.currentContextPaths, hasLength(0)); 483 expect(manager.currentContextPaths, hasLength(0));
(...skipping 29 matching lines...) Expand all
521 manager.assertContextFiles(projectB, [projectB_file]); 513 manager.assertContextFiles(projectB, [projectB_file]);
522 manager.assertContextFiles(subProjectA, [subProjectA_file]); 514 manager.assertContextFiles(subProjectA, [subProjectA_file]);
523 manager.assertContextFiles(subProjectB, [subProjectB_file]); 515 manager.assertContextFiles(subProjectB, [subProjectB_file]);
524 // remove "projectB" 516 // remove "projectB"
525 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); 517 manager.setRoots(<String>[projectA], <String>[], <String, String>{});
526 manager.assertContextPaths([projectA, subProjectA]); 518 manager.assertContextPaths([projectA, subProjectA]);
527 manager.assertContextFiles(projectA, [projectA_file]); 519 manager.assertContextFiles(projectA, [projectA_file]);
528 manager.assertContextFiles(subProjectA, [subProjectA_file]); 520 manager.assertContextFiles(subProjectA, [subProjectA_file]);
529 } 521 }
530 522
523 void test_setRoots_removeFolderWithoutPubspec() {
524 packageMapProvider.packageMap = null;
525 // add one root - there is a context
526 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
527 expect(manager.currentContextPaths, hasLength(1));
528 // set empty roots - no contexts
529 manager.setRoots(<String>[], <String>[], <String, String>{});
530 expect(manager.currentContextPaths, hasLength(0));
531 expect(manager.currentContextFilePaths, hasLength(0));
532 }
533
531 void test_setRoots_removePackageRoot() { 534 void test_setRoots_removePackageRoot() {
532 String packagePathFoo = '/package1/foo'; 535 String packagePathFoo = '/package1/foo';
533 String packageRootPath = '/package2/foo'; 536 String packageRootPath = '/package2/foo';
534 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); 537 Folder packageFolder = resourceProvider.newFolder(packagePathFoo);
535 packageMapProvider.packageMap = { 538 packageMapProvider.packageMap = {
536 'foo': [packageFolder] 539 'foo': [packageFolder]
537 }; 540 };
538 List<String> includedPaths = <String>[projPath]; 541 List<String> includedPaths = <String>[projPath];
539 List<String> excludedPaths = <String>[]; 542 List<String> excludedPaths = <String>[];
540 manager.setRoots(includedPaths, excludedPaths, <String, String>{ 543 manager.setRoots(includedPaths, excludedPaths, <String, String>{
(...skipping 26 matching lines...) Expand all
567 // add file 570 // add file
568 String filePath = posix.join(projPath, 'foo.dart'); 571 String filePath = posix.join(projPath, 'foo.dart');
569 resourceProvider.newFile(filePath, 'contents'); 572 resourceProvider.newFile(filePath, 'contents');
570 // the file was added 573 // the file was added
571 return pumpEventQueue().then((_) { 574 return pumpEventQueue().then((_) {
572 expect(filePaths, hasLength(1)); 575 expect(filePaths, hasLength(1));
573 expect(filePaths, contains(filePath)); 576 expect(filePaths, contains(filePath));
574 }); 577 });
575 } 578 }
576 579
580 test_watch_addFileInSubfolder() {
581 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
582 // empty folder initially
583 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
584 expect(filePaths, hasLength(0));
585 // add file in subfolder
586 String filePath = posix.join(projPath, 'foo', 'bar.dart');
587 resourceProvider.newFile(filePath, 'contents');
588 // the file was added
589 return pumpEventQueue().then((_) {
590 expect(filePaths, hasLength(1));
591 expect(filePaths, contains(filePath));
592 });
593 }
594
577 test_watch_addFile_excluded() { 595 test_watch_addFile_excluded() {
578 // prepare paths 596 // prepare paths
579 String project = '/project'; 597 String project = '/project';
580 String folderA = '$project/aaa'; 598 String folderA = '$project/aaa';
581 String folderB = '$project/bbb'; 599 String folderB = '$project/bbb';
582 String fileA = '$folderA/a.dart'; 600 String fileA = '$folderA/a.dart';
583 String fileB = '$folderB/b.dart'; 601 String fileB = '$folderB/b.dart';
584 // create files 602 // create files
585 resourceProvider.newFile(fileA, 'library a;'); 603 resourceProvider.newFile(fileA, 'library a;');
586 // set roots 604 // set roots
587 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); 605 manager.setRoots(<String>[project], <String>[folderB], <String, String>{});
588 manager.assertContextPaths([project]); 606 manager.assertContextPaths([project]);
589 manager.assertContextFiles(project, [fileA]); 607 manager.assertContextFiles(project, [fileA]);
590 // add a file, ignored as excluded 608 // add a file, ignored as excluded
591 resourceProvider.newFile(fileB, 'library b;'); 609 resourceProvider.newFile(fileB, 'library b;');
592 return pumpEventQueue().then((_) { 610 return pumpEventQueue().then((_) {
593 manager.assertContextPaths([project]); 611 manager.assertContextPaths([project]);
594 manager.assertContextFiles(project, [fileA]); 612 manager.assertContextFiles(project, [fileA]);
595 }); 613 });
596 } 614 }
597 615
598 test_watch_addFileInSubfolder() {
599 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
600 // empty folder initially
601 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
602 expect(filePaths, hasLength(0));
603 // add file in subfolder
604 String filePath = posix.join(projPath, 'foo', 'bar.dart');
605 resourceProvider.newFile(filePath, 'contents');
606 // the file was added
607 return pumpEventQueue().then((_) {
608 expect(filePaths, hasLength(1));
609 expect(filePaths, contains(filePath));
610 });
611 }
612
613 test_watch_addPubspec_toRoot() { 616 test_watch_addPubspec_toRoot() {
614 // prepare paths 617 // prepare paths
615 String root = '/root'; 618 String root = '/root';
616 String rootFile = '$root/root.dart'; 619 String rootFile = '$root/root.dart';
617 String rootPubspec = '$root/pubspec.yaml'; 620 String rootPubspec = '$root/pubspec.yaml';
618 // create files 621 // create files
619 resourceProvider.newFile(rootFile, 'library root;'); 622 resourceProvider.newFile(rootFile, 'library root;');
620 // set roots 623 // set roots
621 manager.setRoots(<String>[root], <String>[], <String, String>{}); 624 manager.setRoots(<String>[root], <String>[], <String, String>{});
622 manager.assertContextPaths([root]); 625 manager.assertContextPaths([root]);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; 877 Iterable<String> get currentContextPaths => currentContextTimestamps.keys;
875 878
876 @override 879 @override
877 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver) { 880 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver) {
878 String path = folder.path; 881 String path = folder.path;
879 expect(currentContextPaths, isNot(contains(path))); 882 expect(currentContextPaths, isNot(contains(path)));
880 currentContextTimestamps[path] = now; 883 currentContextTimestamps[path] = now;
881 currentContextFilePaths[path] = <String, int>{}; 884 currentContextFilePaths[path] = <String, int>{};
882 currentContextSources[path] = new HashSet<Source>(); 885 currentContextSources[path] = new HashSet<Source>();
883 currentContextPackageUriResolvers[path] = packageUriResolver; 886 currentContextPackageUriResolvers[path] = packageUriResolver;
884 return null; 887 AnalysisContextImpl context = new AnalysisContextImpl();
888 context.sourceFactory =
889 new SourceFactory(packageUriResolver == null ? [] : [packageUriResolver] );
890 return context;
885 } 891 }
886 892
887 @override 893 @override
888 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { 894 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
889 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; 895 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path];
890 Set<Source> sources = currentContextSources[contextFolder.path]; 896 Set<Source> sources = currentContextSources[contextFolder.path];
891 897
892 for (Source source in changeSet.addedSources) { 898 for (Source source in changeSet.addedSources) {
893 expect(filePaths, isNot(contains(source.fullName))); 899 expect(filePaths, isNot(contains(source.fullName)));
894 filePaths[source.fullName] = now; 900 filePaths[source.fullName] = now;
(...skipping 28 matching lines...) Expand all
923 currentContextSources.remove(path); 929 currentContextSources.remove(path);
924 currentContextPackageUriResolvers.remove(path); 930 currentContextPackageUriResolvers.remove(path);
925 } 931 }
926 932
927 @override 933 @override
928 void updateContextPackageUriResolver(Folder contextFolder, 934 void updateContextPackageUriResolver(Folder contextFolder,
929 UriResolver packageUriResolver) { 935 UriResolver packageUriResolver) {
930 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; 936 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver;
931 } 937 }
932 } 938 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/context_manager.dart ('k') | pkg/analysis_server/test/domain_completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698