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

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

Issue 894323003: Wait for analysis in search domain. Rewrite with async/await. (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.domain.analysis.abstract; 5 library test.domain.analysis.abstract;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/domain_analysis.dart'; 10 import 'package:analysis_server/src/domain_analysis.dart';
(...skipping 16 matching lines...) Expand all
27 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) || 27 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) ||
28 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) { 28 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) {
29 break; 29 break;
30 } 30 }
31 length++; 31 length++;
32 } 32 }
33 return length; 33 return length;
34 } 34 }
35 35
36 36
37
38 /** 37 /**
39 * An abstract base for all 'analysis' domain tests. 38 * An abstract base for all 'analysis' domain tests.
40 */ 39 */
41 class AbstractAnalysisTest { 40 class AbstractAnalysisTest {
42 MockServerChannel serverChannel; 41 MockServerChannel serverChannel;
43 MemoryResourceProvider resourceProvider; 42 MemoryResourceProvider resourceProvider;
44 MockPackageMapProvider packageMapProvider; 43 MockPackageMapProvider packageMapProvider;
45 AnalysisServer server; 44 AnalysisServer server;
46 RequestHandler handler; 45 RequestHandler handler;
47 46
48 Map<AnalysisService, List<String>> analysisSubscriptions = {}; 47 Map<AnalysisService, List<String>> analysisSubscriptions = {};
49 48
50 String projectPath = '/project'; 49 String projectPath = '/project';
51 String testFolder = '/project/bin/'; 50 String testFolder = '/project/bin/';
52 String testFile = '/project/bin/test.dart'; 51 String testFile = '/project/bin/test.dart';
53 String testCode; 52 String testCode;
54 53
55 // Map<String, List<AnalysisError>> filesErrors = {}; 54 AbstractAnalysisTest();
56 // Map<String, List<Map<String, Object>>> filesHighlights = {};
57 // Map<String, List<Map<String, Object>>> filesNavigation = {};
58 55
59
60 AbstractAnalysisTest();
61 void addAnalysisSubscription(AnalysisService service, String file) { 56 void addAnalysisSubscription(AnalysisService service, String file) {
62 // add file to subscription 57 // add file to subscription
63 var files = analysisSubscriptions[service]; 58 var files = analysisSubscriptions[service];
64 if (files == null) { 59 if (files == null) {
65 files = <String>[]; 60 files = <String>[];
66 analysisSubscriptions[service] = files; 61 analysisSubscriptions[service] = files;
67 } 62 }
68 files.add(file); 63 files.add(file);
69 // set subscriptions 64 // set subscriptions
70 Request request = 65 Request request =
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 expect(response, isResponseSuccess('0')); 133 expect(response, isResponseSuccess('0'));
139 return response; 134 return response;
140 } 135 }
141 136
142 String modifyTestFile(String content) { 137 String modifyTestFile(String content) {
143 addFile(testFile, content); 138 addFile(testFile, content);
144 this.testCode = content; 139 this.testCode = content;
145 return testFile; 140 return testFile;
146 } 141 }
147 142
148 // /**
149 // * Returns [AnalysisError]s recorded for the given [file].
150 // * May be empty, but not `null`.
151 // */
152 // List<AnalysisError> getErrors(String file) {
153 // List<AnalysisError> errors = filesErrors[file];
154 // if (errors != null) {
155 // return errors;
156 // }
157 // return <AnalysisError>[];
158 // }
159 //
160 // /**
161 // * Returns highlights recorded for the given [file].
162 // * May be empty, but not `null`.
163 // */
164 // List<Map<String, Object>> getHighlights(String file) {
165 // List<Map<String, Object>> highlights = filesHighlights[file];
166 // if (highlights != null) {
167 // return highlights;
168 // }
169 // return [];
170 // }
171 //
172 // /**
173 // * Returns navigation regions recorded for the given [file].
174 // * May be empty, but not `null`.
175 // */
176 // List<Map<String, Object>> getNavigation(String file) {
177 // List<Map<String, Object>> navigation = filesNavigation[file];
178 // if (navigation != null) {
179 // return navigation;
180 // }
181 // return [];
182 // }
183 //
184 // /**
185 // * Returns [AnalysisError]s recorded for the [testFile].
186 // * May be empty, but not `null`.
187 // */
188 // List<AnalysisError> getTestErrors() {
189 // return getErrors(testFile);
190 // }
191 //
192 // /**
193 // * Returns highlights recorded for the given [testFile].
194 // * May be empty, but not `null`.
195 // */
196 // List<Map<String, Object>> getTestHighlights() {
197 // return getHighlights(testFile);
198 // }
199 //
200 // /**
201 // * Returns navigation information recorded for the given [testFile].
202 // * May be empty, but not `null`.
203 // */
204 // List<Map<String, Object>> getTestNavigation() {
205 // return getNavigation(testFile);
206 // }
207
208 void processNotification(Notification notification) { 143 void processNotification(Notification notification) {
209 // if (notification.event == NOTIFICATION_ERRORS) {
210 // String file = notification.getParameter(FILE);
211 // List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS);
212 // filesErrors[file] = errorMaps.map(jsonToAnalysisError).toList();
213 // }
214 // if (notification.event == NOTIFICATION_HIGHLIGHTS) {
215 // String file = notification.getParameter(FILE);
216 // filesHighlights[file] = notification.getParameter(REGIONS);
217 // }
218 // if (notification.event == NOTIFICATION_NAVIGATION) {
219 // String file = notification.getParameter(FILE);
220 // filesNavigation[file] = notification.getParameter(REGIONS);
221 // }
222 } 144 }
223 145
224 // /**
225 // * Creates a project with a single Dart file `/project/bin/test.dart` with
226 // * the given [code].
227 // */
228 // void createSingleFileProject(code) {
229 // this.testCode = _getCodeString(code);
230 // resourceProvider.newFolder('/project');
231 // resourceProvider.newFile(testFile, testCode);
232 // Request request = new AnalysisSetAnalysisRootsParams(['/project'],
233 // []).toRequest('0');
234 // handleSuccessfulRequest(request);
235 // }
236
237 void setUp() { 146 void setUp() {
238 serverChannel = new MockServerChannel(); 147 serverChannel = new MockServerChannel();
239 resourceProvider = new MemoryResourceProvider(); 148 resourceProvider = new MemoryResourceProvider();
240 packageMapProvider = new MockPackageMapProvider(); 149 packageMapProvider = new MockPackageMapProvider();
241 Index index = createIndex(); 150 Index index = createIndex();
242 server = createAnalysisServer(index); 151 server = createAnalysisServer(index);
243 handler = new AnalysisDomainHandler(server); 152 handler = new AnalysisDomainHandler(server);
244 // listen for notifications 153 // listen for notifications
245 Stream<Notification> notificationStream = 154 Stream<Notification> notificationStream =
246 serverChannel.notificationController.stream; 155 serverChannel.notificationController.stream;
247 notificationStream.listen((Notification notification) { 156 notificationStream.listen((Notification notification) {
248 processNotification(notification); 157 processNotification(notification);
249 }); 158 });
250 } 159 }
251 160
252 void tearDown() { 161 void tearDown() {
253 server.done(); 162 server.done();
254 handler = null; 163 handler = null;
255 server = null; 164 server = null;
256 resourceProvider = null; 165 resourceProvider = null;
257 serverChannel = null; 166 serverChannel = null;
258 } 167 }
259 168
260 /** 169 /**
261 * Returns a [Future] that completes when the server's analysis is complete. 170 * Returns a [Future] that completes when the server's analysis is complete.
262 */ 171 */
263 Future waitForTasksFinished() { 172 Future waitForTasksFinished() {
264 return server.onAnalysisComplete; 173 return server.onAnalysisComplete;
265 } 174 }
175
176 /**
177 * Completes with a successful [Response] for the given [request].
178 * Otherwise fails.
179 */
180 Future<Response> waitResponse(Request request) async {
181 return serverChannel.sendRequest(request);
182 }
266 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698