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

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

Issue 332383006: Trigger re-analysis when a file changes on disk. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 7f27224a4a2c601b6d57287d8060ba181c07962b..0ed9be0340c45c09caa64da41ca649204b36a77e 100644
--- a/pkg/analysis_server/test/context_directory_manager_test.dart
+++ b/pkg/analysis_server/test/context_directory_manager_test.dart
@@ -15,30 +15,42 @@ import 'package:analyzer/src/generated/source.dart';
class TestContextDirectoryManager extends ContextDirectoryManager {
TestContextDirectoryManager(MemoryResourceProvider provider) : super(provider);
+ /**
+ * Source of timestamps stored in [currentContextFilePaths]
Brian Wilkerson 2014/06/17 17:55:02 Missing period?
Paul Berry 2014/06/17 18:07:50 Done.
+ */
+ int now = 0;
+
final Set<String> currentContextPaths = new Set<String>();
final Map<String, String> currentContextPubspecPaths = <String, String>{};
- final Map<String, Set<String>> currentContextFilePaths = <String, Set<String>>{};
+
+ /**
+ * Map from context to (map from file path to timestamp of last event)
+ */
+ final Map<String, Map<String, int>> currentContextFilePaths = <String, Map<String, int>>{};
@override
void addContext(Folder folder, File pubspecFile) {
String path = folder.path;
currentContextPaths.add(path);
currentContextPubspecPaths[path] = pubspecFile != null ? pubspecFile.path : null;
- currentContextFilePaths[path] = new Set<String>();
+ currentContextFilePaths[path] = <String, int>{};
}
@override
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
- Set<String> filePaths = currentContextFilePaths[contextFolder.path];
+ Map<String, int> filePaths = currentContextFilePaths[contextFolder.path];
for (Source source in changeSet.addedSources) {
expect(filePaths, isNot(contains(source.fullName)));
- filePaths.add(source.fullName);
+ filePaths[source.fullName] = now;
}
for (Source source in changeSet.removedSources) {
expect(filePaths, contains(source.fullName));
filePaths.remove(source.fullName);
}
- // TODO(paulberry): handle source.changedSources.
+ for (Source source in changeSet.changedSources) {
+ expect(filePaths, contains(source.fullName));
+ filePaths[source.fullName] = now;
+ }
}
@override
@@ -136,7 +148,7 @@ main() {
String filePath1 = posix.join(projPath, 'packages', 'file1.dart');
provider.newFile(filePath1, 'contents');
manager.setRoots(<String>[projPath], <String>[]);
- Set<String> filePaths = manager.currentContextFilePaths[projPath];
+ Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
expect(filePaths, hasLength(0));
String filePath2 = posix.join(projPath, 'packages', 'file2.dart');
provider.newFile(filePath2, 'contents');
@@ -155,7 +167,7 @@ main() {
test('Add file', () {
manager.setRoots(<String>[projPath], <String>[]);
- Set<String> filePaths = manager.currentContextFilePaths[projPath];
+ Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
expect(filePaths, hasLength(0));
String filePath = posix.join(projPath, 'foo.dart');
provider.newFile(filePath, 'contents');
@@ -167,7 +179,7 @@ main() {
test('Add file in subdirectory', () {
manager.setRoots(<String>[projPath], <String>[]);
- Set<String> filePaths = manager.currentContextFilePaths[projPath];
+ Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
expect(filePaths, hasLength(0));
String filePath = posix.join(projPath, 'foo', 'bar.dart');
provider.newFile(filePath, 'contents');
@@ -181,12 +193,26 @@ main() {
String filePath = posix.join(projPath, 'foo.dart');
provider.newFile(filePath, 'contents');
manager.setRoots(<String>[projPath], <String>[]);
- Set<String> filePaths = manager.currentContextFilePaths[projPath];
+ Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
expect(filePaths, hasLength(1));
expect(filePaths, contains(filePath));
provider.deleteFile(filePath);
return pumpEventQueue().then((_) => expect(filePaths, hasLength(0)));
});
+
+ test('Modify file', () {
+ String filePath = posix.join(projPath, 'foo.dart');
+ provider.newFile(filePath, 'contents');
+ manager.setRoots(<String>[projPath], <String>[]);
+ Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
+ expect(filePaths, hasLength(1));
+ expect(filePaths, contains(filePath));
+ expect(filePaths[filePath], equals(manager.now));
+ manager.now++;
+ provider.modifyFile(filePath, 'new contents');
+ return pumpEventQueue().then((_) => expect(filePaths[filePath], equals(
+ manager.now)));
+ });
});
});
-}
+}
« no previous file with comments | « pkg/analysis_server/lib/src/context_directory_manager.dart ('k') | pkg/analysis_server/test/domain_analysis_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698