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

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

Issue 1759333002: Fix regression for import suggestions (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
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/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 <GeneralAnalysisService>[]; 57 <GeneralAnalysisService>[];
58 final Map<AnalysisService, List<String>> analysisSubscriptions = {}; 58 final Map<AnalysisService, List<String>> analysisSubscriptions = {};
59 59
60 String projectPath = '/project'; 60 String projectPath = '/project';
61 String testFolder = '/project/bin'; 61 String testFolder = '/project/bin';
62 String testFile = '/project/bin/test.dart'; 62 String testFile = '/project/bin/test.dart';
63 String testCode; 63 String testCode;
64 64
65 AbstractAnalysisTest(); 65 AbstractAnalysisTest();
66 66
67 AnalysisDomainHandler get analysisHandler => server.handlers
68 .singleWhere((handler) => handler is AnalysisDomainHandler);
69
67 void addAnalysisSubscription(AnalysisService service, String file) { 70 void addAnalysisSubscription(AnalysisService service, String file) {
68 // add file to subscription 71 // add file to subscription
69 var files = analysisSubscriptions[service]; 72 var files = analysisSubscriptions[service];
70 if (files == null) { 73 if (files == null) {
71 files = <String>[]; 74 files = <String>[];
72 analysisSubscriptions[service] = files; 75 analysisSubscriptions[service] = files;
73 } 76 }
74 files.add(file); 77 files.add(file);
75 // set subscriptions 78 // set subscriptions
76 Request request = new AnalysisSetSubscriptionsParams(analysisSubscriptions) 79 Request request = new AnalysisSetSubscriptionsParams(analysisSubscriptions)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return null; 139 return null;
137 } 140 }
138 141
139 /** 142 /**
140 * Creates a project `/project`. 143 * Creates a project `/project`.
141 */ 144 */
142 void createProject() { 145 void createProject() {
143 resourceProvider.newFolder(projectPath); 146 resourceProvider.newFolder(projectPath);
144 Request request = 147 Request request =
145 new AnalysisSetAnalysisRootsParams([projectPath], []).toRequest('0'); 148 new AnalysisSetAnalysisRootsParams([projectPath], []).toRequest('0');
146 handleSuccessfulRequest(request); 149 handleSuccessfulRequest(request, handler: analysisHandler);
147 } 150 }
148 151
149 /** 152 /**
150 * Returns the offset of [search] in [testCode]. 153 * Returns the offset of [search] in [testCode].
151 * Fails if not found. 154 * Fails if not found.
152 */ 155 */
153 int findFileOffset(String path, String search) { 156 int findFileOffset(String path, String search) {
154 File file = resourceProvider.getResource(path) as File; 157 File file = resourceProvider.getResource(path) as File;
155 String code = file.createSource().contents.data; 158 String code = file.createSource().contents.data;
156 int offset = code.indexOf(search); 159 int offset = code.indexOf(search);
157 expect(offset, isNot(-1), reason: '"$search" in\n$code'); 160 expect(offset, isNot(-1), reason: '"$search" in\n$code');
158 return offset; 161 return offset;
159 } 162 }
160 163
161 /** 164 /**
162 * Returns the offset of [search] in [testCode]. 165 * Returns the offset of [search] in [testCode].
163 * Fails if not found. 166 * Fails if not found.
164 */ 167 */
165 int findOffset(String search) { 168 int findOffset(String search) {
166 int offset = testCode.indexOf(search); 169 int offset = testCode.indexOf(search);
167 expect(offset, isNot(-1)); 170 expect(offset, isNot(-1));
168 return offset; 171 return offset;
169 } 172 }
170 173
171 /** 174 /**
172 * Validates that the given [request] is handled successfully. 175 * Validates that the given [request] is handled successfully.
173 */ 176 */
174 Response handleSuccessfulRequest(Request request) { 177 Response handleSuccessfulRequest(Request request, {RequestHandler handler}) {
178 handler ??= this.handler;
175 Response response = handler.handleRequest(request); 179 Response response = handler.handleRequest(request);
176 expect(response, isResponseSuccess(request.id)); 180 expect(response, isResponseSuccess(request.id));
177 return response; 181 return response;
178 } 182 }
179 183
180 String modifyTestFile(String content) { 184 String modifyTestFile(String content) {
181 addFile(testFile, content); 185 addFile(testFile, content);
182 this.testCode = content; 186 this.testCode = content;
183 return testFile; 187 return testFile;
184 } 188 }
(...skipping 11 matching lines...) Expand all
196 .toRequest('0'); 200 .toRequest('0');
197 handleSuccessfulRequest(request); 201 handleSuccessfulRequest(request);
198 } 202 }
199 203
200 void setUp() { 204 void setUp() {
201 serverChannel = new MockServerChannel(); 205 serverChannel = new MockServerChannel();
202 resourceProvider = new MemoryResourceProvider(); 206 resourceProvider = new MemoryResourceProvider();
203 packageMapProvider = new MockPackageMapProvider(); 207 packageMapProvider = new MockPackageMapProvider();
204 Index index = createIndex(); 208 Index index = createIndex();
205 server = createAnalysisServer(index); 209 server = createAnalysisServer(index);
206 handler = server.handlers 210 handler = analysisHandler;
207 .singleWhere((handler) => handler is AnalysisDomainHandler);
208 // listen for notifications 211 // listen for notifications
209 Stream<Notification> notificationStream = 212 Stream<Notification> notificationStream =
210 serverChannel.notificationController.stream; 213 serverChannel.notificationController.stream;
211 notificationStream.listen((Notification notification) { 214 notificationStream.listen((Notification notification) {
212 processNotification(notification); 215 processNotification(notification);
213 }); 216 });
214 } 217 }
215 218
216 void tearDown() { 219 void tearDown() {
217 server.done(); 220 server.done();
(...skipping 11 matching lines...) Expand all
229 } 232 }
230 233
231 /** 234 /**
232 * Completes with a successful [Response] for the given [request]. 235 * Completes with a successful [Response] for the given [request].
233 * Otherwise fails. 236 * Otherwise fails.
234 */ 237 */
235 Future<Response> waitResponse(Request request) async { 238 Future<Response> waitResponse(Request request) async {
236 return serverChannel.sendRequest(request); 239 return serverChannel.sendRequest(request);
237 } 240 }
238 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698