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

Unified Diff: pkg/analysis_server/test/context_directory_manager_test.dart

Issue 308713002: Handle file additions/removals in ContextDirectoryManager. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address Konstantin's comments Created 6 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/context_directory_manager_test.dart
diff --git a/pkg/analysis_server/test/context_directory_manager_test.dart b/pkg/analysis_server/test/context_directory_manager_test.dart
index 08a3c94d0b2423d9598dc35c50dbd074cf0fdef6..f9d359e5fa62fe89760ce6bf0b55026c506c655f 100644
--- a/pkg/analysis_server/test/context_directory_manager_test.dart
+++ b/pkg/analysis_server/test/context_directory_manager_test.dart
@@ -4,6 +4,7 @@
library test.context.directory.manager;
+import 'mocks.dart';
import 'package:analysis_server/src/context_directory_manager.dart';
import 'package:analysis_server/src/resource.dart';
import 'package:path/path.dart';
@@ -20,18 +21,23 @@ class TestContextDirectoryManager extends ContextDirectoryManager {
@override
void addContext(Folder folder, File pubspecFile) {
- currentContextPaths.add(folder.fullName);
- currentContextPubspecPaths[folder.fullName] = pubspecFile != null ? pubspecFile.fullName : null;
- currentContextFilePaths[folder.fullName] = new Set<String>();
+ currentContextPaths.add(folder.path);
+ currentContextPubspecPaths[folder.path] = pubspecFile != null ? pubspecFile.path : null;
+ currentContextFilePaths[folder.path] = new Set<String>();
}
@override
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
- Set<String> filePaths = currentContextFilePaths[contextFolder.fullName];
+ Set<String> filePaths = currentContextFilePaths[contextFolder.path];
for (Source source in changeSet.addedSources) {
+ expect(filePaths, isNot(contains(source.fullName)));
filePaths.add(source.fullName);
}
- // TODO(paulberry): handle source.changedSources and source.removedSources.
+ for (Source source in changeSet.removedSources) {
+ expect(filePaths, contains(source.fullName));
+ filePaths.remove(source.fullName);
+ }
+ // TODO(paulberry): handle source.changedSources.
}
}
@@ -90,5 +96,49 @@ main() {
expect(filePaths, hasLength(1));
expect(filePaths, contains(filePath));
});
+
+ group('detect context modifications', () {
+ String projPath;
+
+ setUp(() {
+ projPath = '/my/proj';
+ provider.newFolder(projPath);
+ });
+
+ test('Add file', () {
+ manager.setRoots(<String>[projPath], <String>[]);
+ Set<String> filePaths = manager.currentContextFilePaths[projPath];
+ expect(filePaths, hasLength(0));
+ String filePath = posix.join(projPath, 'foo.dart');
+ provider.newFile(filePath, 'contents');
+ return pumpEventQueue().then((_) {
+ expect(filePaths, hasLength(1));
+ expect(filePaths, contains(filePath));
+ });
+ });
+
+ test('Add file in subdirectory', () {
+ manager.setRoots(<String>[projPath], <String>[]);
+ Set<String> filePaths = manager.currentContextFilePaths[projPath];
+ expect(filePaths, hasLength(0));
+ String filePath = posix.join(projPath, 'foo', 'bar.dart');
+ provider.newFile(filePath, 'contents');
+ return pumpEventQueue().then((_) {
+ expect(filePaths, hasLength(1));
+ expect(filePaths, contains(filePath));
+ });
+ });
+
+ test('Delete file', () {
+ String filePath = posix.join(projPath, 'foo.dart');
+ provider.newFile(filePath, 'contents');
+ manager.setRoots(<String>[projPath], <String>[]);
+ Set<String> filePaths = manager.currentContextFilePaths[projPath];
+ expect(filePaths, hasLength(1));
+ expect(filePaths, contains(filePath));
+ provider.deleteFile(filePath);
+ return pumpEventQueue().then((_) => expect(filePaths, hasLength(0)));
+ });
+ });
});
}

Powered by Google App Engine
This is Rietveld 408576698