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

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

Issue 353453004: Remove dead code for tracking pubspec.yaml files. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/context_directory_manager.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) 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 'mocks.dart'; 7 import 'mocks.dart';
8 import 'package:analysis_server/src/context_directory_manager.dart'; 8 import 'package:analysis_server/src/context_directory_manager.dart';
9 import 'package:analysis_server/src/resource.dart'; 9 import 'package:analysis_server/src/resource.dart';
10 import 'package:path/path.dart'; 10 import 'package:path/path.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
14 14
15 class TestContextDirectoryManager extends ContextDirectoryManager { 15 class TestContextDirectoryManager extends ContextDirectoryManager {
16 TestContextDirectoryManager(MemoryResourceProvider provider) : super(provider) ; 16 TestContextDirectoryManager(MemoryResourceProvider provider) : super(provider) ;
17 17
18 /** 18 /**
19 * Source of timestamps stored in [currentContextFilePaths]. 19 * Source of timestamps stored in [currentContextFilePaths].
20 */ 20 */
21 int now = 0; 21 int now = 0;
22 22
23 final Set<String> currentContextPaths = new Set<String>(); 23 final Set<String> currentContextPaths = new Set<String>();
24 final Map<String, String> currentContextPubspecPaths = <String, String>{};
25 24
26 /** 25 /**
27 * Map from context to (map from file path to timestamp of last event) 26 * Map from context to (map from file path to timestamp of last event)
28 */ 27 */
29 final Map<String, Map<String, int>> currentContextFilePaths = <String, Map<Str ing, int>>{}; 28 final Map<String, Map<String, int>> currentContextFilePaths = <String, Map<Str ing, int>>{};
30 29
31 @override 30 @override
32 void addContext(Folder folder, File pubspecFile) { 31 void addContext(Folder folder) {
33 String path = folder.path; 32 String path = folder.path;
34 currentContextPaths.add(path); 33 currentContextPaths.add(path);
35 currentContextPubspecPaths[path] = pubspecFile != null ? pubspecFile.path : null;
36 currentContextFilePaths[path] = <String, int>{}; 34 currentContextFilePaths[path] = <String, int>{};
37 } 35 }
38 36
39 @override 37 @override
40 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { 38 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
41 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; 39 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path];
42 for (Source source in changeSet.addedSources) { 40 for (Source source in changeSet.addedSources) {
43 expect(filePaths, isNot(contains(source.fullName))); 41 expect(filePaths, isNot(contains(source.fullName)));
44 filePaths[source.fullName] = now; 42 filePaths[source.fullName] = now;
45 } 43 }
46 for (Source source in changeSet.removedSources) { 44 for (Source source in changeSet.removedSources) {
47 expect(filePaths, contains(source.fullName)); 45 expect(filePaths, contains(source.fullName));
48 filePaths.remove(source.fullName); 46 filePaths.remove(source.fullName);
49 } 47 }
50 for (Source source in changeSet.changedSources) { 48 for (Source source in changeSet.changedSources) {
51 expect(filePaths, contains(source.fullName)); 49 expect(filePaths, contains(source.fullName));
52 filePaths[source.fullName] = now; 50 filePaths[source.fullName] = now;
53 } 51 }
54 } 52 }
55 53
56 @override 54 @override
57 void removeContext(Folder folder) { 55 void removeContext(Folder folder) {
58 String path = folder.path; 56 String path = folder.path;
59 currentContextPaths.remove(path); 57 currentContextPaths.remove(path);
60 currentContextPubspecPaths.remove(path);
61 currentContextFilePaths.remove(path); 58 currentContextFilePaths.remove(path);
62 } 59 }
63 } 60 }
64 61
65 main() { 62 main() {
66 groupSep = ' | '; 63 groupSep = ' | ';
67 64
68 group('ContextDirectoryManager', () { 65 group('ContextDirectoryManager', () {
69 TestContextDirectoryManager manager; 66 TestContextDirectoryManager manager;
70 MemoryResourceProvider provider; 67 MemoryResourceProvider provider;
71 68
72 setUp(() { 69 setUp(() {
73 provider = new MemoryResourceProvider(); 70 provider = new MemoryResourceProvider();
74 manager = new TestContextDirectoryManager(provider); 71 manager = new TestContextDirectoryManager(provider);
75 }); 72 });
76 73
77 test('add folder with pubspec', () { 74 test('add folder with pubspec', () {
78 String projPath = '/my/proj'; 75 String projPath = '/my/proj';
79 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); 76 String pubspecPath = posix.join(projPath, 'pubspec.yaml');
80 provider.newFolder(projPath); 77 provider.newFolder(projPath);
81 provider.newFile(pubspecPath, 'pubspec'); 78 provider.newFile(pubspecPath, 'pubspec');
82 manager.setRoots(<String>[projPath], <String>[]); 79 manager.setRoots(<String>[projPath], <String>[]);
83 expect(manager.currentContextPaths, hasLength(1)); 80 expect(manager.currentContextPaths, hasLength(1));
84 expect(manager.currentContextPaths, contains(projPath)); 81 expect(manager.currentContextPaths, contains(projPath));
85 expect(manager.currentContextPubspecPaths[projPath], equals(pubspecPath));
86 expect(manager.currentContextFilePaths[projPath], hasLength(0)); 82 expect(manager.currentContextFilePaths[projPath], hasLength(0));
87 }); 83 });
88 84
89 test('add folder without pubspec', () { 85 test('add folder without pubspec', () {
90 String projPath = '/my/proj'; 86 String projPath = '/my/proj';
91 provider.newFolder(projPath); 87 provider.newFolder(projPath);
92 manager.setRoots(<String>[projPath], <String>[]); 88 manager.setRoots(<String>[projPath], <String>[]);
93 expect(manager.currentContextPaths, hasLength(1)); 89 expect(manager.currentContextPaths, hasLength(1));
94 expect(manager.currentContextPaths, contains(projPath)); 90 expect(manager.currentContextPaths, contains(projPath));
95 expect(manager.currentContextPubspecPaths[projPath], isNull);
96 expect(manager.currentContextFilePaths[projPath], hasLength(0)); 91 expect(manager.currentContextFilePaths[projPath], hasLength(0));
97 }); 92 });
98 93
99 test('add folder with dart file', () { 94 test('add folder with dart file', () {
100 String projPath = '/my/proj'; 95 String projPath = '/my/proj';
101 provider.newFolder(projPath); 96 provider.newFolder(projPath);
102 String filePath = posix.join(projPath, 'foo.dart'); 97 String filePath = posix.join(projPath, 'foo.dart');
103 provider.newFile(filePath, 'contents'); 98 provider.newFile(filePath, 'contents');
104 manager.setRoots(<String>[projPath], <String>[]); 99 manager.setRoots(<String>[projPath], <String>[]);
105 var filePaths = manager.currentContextFilePaths[projPath]; 100 var filePaths = manager.currentContextFilePaths[projPath];
(...skipping 13 matching lines...) Expand all
119 }); 114 });
120 115
121 test('remove folder with pubspec', () { 116 test('remove folder with pubspec', () {
122 String projPath = '/my/proj'; 117 String projPath = '/my/proj';
123 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); 118 String pubspecPath = posix.join(projPath, 'pubspec.yaml');
124 provider.newFolder(projPath); 119 provider.newFolder(projPath);
125 provider.newFile(pubspecPath, 'pubspec'); 120 provider.newFile(pubspecPath, 'pubspec');
126 manager.setRoots(<String>[projPath], <String>[]); 121 manager.setRoots(<String>[projPath], <String>[]);
127 manager.setRoots(<String>[], <String>[]); 122 manager.setRoots(<String>[], <String>[]);
128 expect(manager.currentContextPaths, hasLength(0)); 123 expect(manager.currentContextPaths, hasLength(0));
129 expect(manager.currentContextPubspecPaths, hasLength(0));
130 expect(manager.currentContextFilePaths, hasLength(0)); 124 expect(manager.currentContextFilePaths, hasLength(0));
131 }); 125 });
132 126
133 test('remove folder without pubspec', () { 127 test('remove folder without pubspec', () {
134 String projPath = '/my/proj'; 128 String projPath = '/my/proj';
135 provider.newFolder(projPath); 129 provider.newFolder(projPath);
136 manager.setRoots(<String>[projPath], <String>[]); 130 manager.setRoots(<String>[projPath], <String>[]);
137 manager.setRoots(<String>[], <String>[]); 131 manager.setRoots(<String>[], <String>[]);
138 expect(manager.currentContextPaths, hasLength(0)); 132 expect(manager.currentContextPaths, hasLength(0));
139 expect(manager.currentContextPubspecPaths, hasLength(0));
140 expect(manager.currentContextFilePaths, hasLength(0)); 133 expect(manager.currentContextFilePaths, hasLength(0));
141 }); 134 });
142 135
143 test('ignore files in packages dir', () { 136 test('ignore files in packages dir', () {
144 String projPath = '/my/proj'; 137 String projPath = '/my/proj';
145 provider.newFolder(projPath); 138 provider.newFolder(projPath);
146 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); 139 String pubspecPath = posix.join(projPath, 'pubspec.yaml');
147 provider.newFile(pubspecPath, 'pubspec'); 140 provider.newFile(pubspecPath, 'pubspec');
148 String filePath1 = posix.join(projPath, 'packages', 'file1.dart'); 141 String filePath1 = posix.join(projPath, 'packages', 'file1.dart');
149 provider.newFile(filePath1, 'contents'); 142 provider.newFile(filePath1, 'contents');
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; 175 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
183 expect(filePaths, hasLength(0)); 176 expect(filePaths, hasLength(0));
184 String filePath = posix.join(projPath, 'foo', 'bar.dart'); 177 String filePath = posix.join(projPath, 'foo', 'bar.dart');
185 provider.newFile(filePath, 'contents'); 178 provider.newFile(filePath, 'contents');
186 return pumpEventQueue().then((_) { 179 return pumpEventQueue().then((_) {
187 expect(filePaths, hasLength(1)); 180 expect(filePaths, hasLength(1));
188 expect(filePaths, contains(filePath)); 181 expect(filePaths, contains(filePath));
189 }); 182 });
190 }); 183 });
191 184
192 test('Add pubspec file', () {
193 manager.setRoots(<String>[projPath], <String>[]);
194 String pubspecPath = posix.join(projPath, 'pubspec.yaml');
195 expect(manager.currentContextPubspecPaths[projPath], isNull);
196 provider.newFile(pubspecPath, 'pubspec');
197 return pumpEventQueue().then((_) {
198 expect(manager.currentContextPubspecPaths[projPath], equals(pubspecPat h));
199 });
200 });
201
202 test('Delete file', () { 185 test('Delete file', () {
203 String filePath = posix.join(projPath, 'foo.dart'); 186 String filePath = posix.join(projPath, 'foo.dart');
204 provider.newFile(filePath, 'contents'); 187 provider.newFile(filePath, 'contents');
205 manager.setRoots(<String>[projPath], <String>[]); 188 manager.setRoots(<String>[projPath], <String>[]);
206 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; 189 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
207 expect(filePaths, hasLength(1)); 190 expect(filePaths, hasLength(1));
208 expect(filePaths, contains(filePath)); 191 expect(filePaths, contains(filePath));
209 provider.deleteFile(filePath); 192 provider.deleteFile(filePath);
210 return pumpEventQueue().then((_) => expect(filePaths, hasLength(0))); 193 return pumpEventQueue().then((_) => expect(filePaths, hasLength(0)));
211 }); 194 });
212 195
213 test('Delete pubspec file', () {
214 String pubspecPath = posix.join(projPath, 'pubspec.yaml');
215 provider.newFile(pubspecPath, 'pubspec');
216 manager.setRoots(<String>[projPath], <String>[]);
217 expect(manager.currentContextPubspecPaths[projPath], equals(pubspecPath) );
218 provider.deleteFile(pubspecPath);
219 return pumpEventQueue().then((_) {
220 expect(manager.currentContextPubspecPaths[projPath], isNull);
221 });
222 });
223
224 test('Modify file', () { 196 test('Modify file', () {
225 String filePath = posix.join(projPath, 'foo.dart'); 197 String filePath = posix.join(projPath, 'foo.dart');
226 provider.newFile(filePath, 'contents'); 198 provider.newFile(filePath, 'contents');
227 manager.setRoots(<String>[projPath], <String>[]); 199 manager.setRoots(<String>[projPath], <String>[]);
228 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; 200 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
229 expect(filePaths, hasLength(1)); 201 expect(filePaths, hasLength(1));
230 expect(filePaths, contains(filePath)); 202 expect(filePaths, contains(filePath));
231 expect(filePaths[filePath], equals(manager.now)); 203 expect(filePaths[filePath], equals(manager.now));
232 manager.now++; 204 manager.now++;
233 provider.modifyFile(filePath, 'new contents'); 205 provider.modifyFile(filePath, 'new contents');
234 return pumpEventQueue().then((_) => expect(filePaths[filePath], equals( 206 return pumpEventQueue().then((_) => expect(filePaths[filePath], equals(
235 manager.now))); 207 manager.now)));
236 }); 208 });
237 }); 209 });
238 }); 210 });
239 } 211 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/context_directory_manager.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698