OLD | NEW |
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.analysis_server; | 5 library test.analysis_server; |
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/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 184 |
185 Future test_echo() { | 185 Future test_echo() { |
186 server.handlers = [new EchoHandler()]; | 186 server.handlers = [new EchoHandler()]; |
187 var request = new Request('my22', 'echo'); | 187 var request = new Request('my22', 'echo'); |
188 return channel.sendRequest(request).then((Response response) { | 188 return channel.sendRequest(request).then((Response response) { |
189 expect(response.id, equals('my22')); | 189 expect(response.id, equals('my22')); |
190 expect(response.error, isNull); | 190 expect(response.error, isNull); |
191 }); | 191 }); |
192 } | 192 } |
193 | 193 |
| 194 test_getAnalysisContext_nested() { |
| 195 String dir1Path = '/dir1'; |
| 196 String dir2Path = dir1Path + '/dir2'; |
| 197 String filePath = dir2Path + '/file.dart'; |
| 198 Folder dir1 = resourceProvider.newFolder(dir1Path); |
| 199 Folder dir2 = resourceProvider.newFolder(dir2Path); |
| 200 resourceProvider.newFile(filePath, 'library lib;'); |
| 201 |
| 202 AnalysisContext context1 = AnalysisEngine.instance.createAnalysisContext(); |
| 203 AnalysisContext context2 = AnalysisEngine.instance.createAnalysisContext(); |
| 204 server.folderMap[dir1] = context1; |
| 205 server.folderMap[dir2] = context2; |
| 206 |
| 207 expect(server.getAnalysisContext(filePath), context2); |
| 208 } |
| 209 |
| 210 test_getAnalysisContext_simple() { |
| 211 String dirPath = '/dir'; |
| 212 String filePath = dirPath + '/file.dart'; |
| 213 Folder dir = resourceProvider.newFolder(dirPath); |
| 214 resourceProvider.newFile(filePath, 'library lib;'); |
| 215 |
| 216 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 217 server.folderMap[dir] = context; |
| 218 |
| 219 expect(server.getAnalysisContext(filePath), context); |
| 220 } |
| 221 |
194 Future test_getAnalysisContextForSource() { | 222 Future test_getAnalysisContextForSource() { |
195 // Subscribe to STATUS so we'll know when analysis is done. | 223 // Subscribe to STATUS so we'll know when analysis is done. |
196 server.serverServices = [ServerService.STATUS].toSet(); | 224 server.serverServices = [ServerService.STATUS].toSet(); |
197 // Analyze project foo containing foo.dart and project bar containing | 225 // Analyze project foo containing foo.dart and project bar containing |
198 // bar.dart. | 226 // bar.dart. |
199 resourceProvider.newFolder('/foo'); | 227 resourceProvider.newFolder('/foo'); |
200 resourceProvider.newFolder('/bar'); | 228 resourceProvider.newFolder('/bar'); |
201 File foo = resourceProvider.newFile('/foo/foo.dart', 'library lib;'); | 229 File foo = resourceProvider.newFile('/foo/foo.dart', 'library lib;'); |
202 Source fooSource = foo.createSource(); | 230 Source fooSource = foo.createSource(); |
203 File bar = resourceProvider.newFile('/bar/bar.dart', 'library lib;'); | 231 File bar = resourceProvider.newFile('/bar/bar.dart', 'library lib;'); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 server.folderMap[dir] = context; | 304 server.folderMap[dir] = context; |
277 | 305 |
278 ContextSourcePair pair = server.getContextSourcePair(filePath); | 306 ContextSourcePair pair = server.getContextSourcePair(filePath); |
279 Source source = pair.source; | 307 Source source = pair.source; |
280 expect(pair.context, same(context)); | 308 expect(pair.context, same(context)); |
281 expect(source, isNotNull); | 309 expect(source, isNotNull); |
282 expect(source.uri.scheme, 'file'); | 310 expect(source.uri.scheme, 'file'); |
283 expect(source.fullName, filePath); | 311 expect(source.fullName, filePath); |
284 } | 312 } |
285 | 313 |
| 314 test_operationsRemovedOnContextDisposal() async { |
| 315 resourceProvider.newFolder('/foo'); |
| 316 resourceProvider.newFile('/foo/baz.dart', 'library lib;'); |
| 317 resourceProvider.newFolder('/bar'); |
| 318 resourceProvider.newFile('/bar/baz.dart', 'library lib;'); |
| 319 server.setAnalysisRoots('0', ['/foo', '/bar'], [], {}); |
| 320 await pumpEventQueue(); |
| 321 AnalysisContext contextFoo = server.getAnalysisContext('/foo/baz.dart'); |
| 322 AnalysisContext contextBar = server.getAnalysisContext('/bar/baz.dart'); |
| 323 _MockServerOperation operationFoo = new _MockServerOperation(contextFoo); |
| 324 _MockServerOperation operationBar = new _MockServerOperation(contextBar); |
| 325 server.scheduleOperation(operationFoo); |
| 326 server.scheduleOperation(operationBar); |
| 327 server.setAnalysisRoots('1', ['/foo'], [], {}); |
| 328 await pumpEventQueue(); |
| 329 expect(operationFoo.isComplete, isTrue); |
| 330 expect(operationBar.isComplete, isFalse); |
| 331 } |
| 332 |
286 Future test_prioritySourcesChangedEvent() { | 333 Future test_prioritySourcesChangedEvent() { |
287 resourceProvider.newFolder('/foo'); | 334 resourceProvider.newFolder('/foo'); |
288 | 335 |
289 int eventCount = 0; | 336 int eventCount = 0; |
290 Source firstSource = null; | 337 Source firstSource = null; |
291 server.onPriorityChange.listen((PriorityChangeEvent event) { | 338 server.onPriorityChange.listen((PriorityChangeEvent event) { |
292 ++eventCount; | 339 ++eventCount; |
293 firstSource = event.firstSource; | 340 firstSource = event.firstSource; |
294 }); | 341 }); |
295 | 342 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 443 |
397 class EchoHandler implements RequestHandler { | 444 class EchoHandler implements RequestHandler { |
398 @override | 445 @override |
399 Response handleRequest(Request request) { | 446 Response handleRequest(Request request) { |
400 if (request.method == 'echo') { | 447 if (request.method == 'echo') { |
401 return new Response(request.id, result: {'echo': true}); | 448 return new Response(request.id, result: {'echo': true}); |
402 } | 449 } |
403 return null; | 450 return null; |
404 } | 451 } |
405 } | 452 } |
| 453 |
| 454 /** |
| 455 * A [ServerOperation] that does nothing but keep track of whether or not it |
| 456 * has been performed. |
| 457 */ |
| 458 class _MockServerOperation implements ServerOperation { |
| 459 final AnalysisContext context; |
| 460 bool isComplete = false; |
| 461 |
| 462 _MockServerOperation(this.context); |
| 463 |
| 464 @override |
| 465 ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS; |
| 466 |
| 467 @override |
| 468 void perform(AnalysisServer server) { |
| 469 isComplete = true; |
| 470 } |
| 471 } |
OLD | NEW |