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

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

Issue 1455163005: Implement AnalysisServer.getContainingContext() using ContextManager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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.analysis_server; 5 library test.analysis_server;
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 expect(fooContext.getKindOf(barSource), SourceKind.UNKNOWN); 235 expect(fooContext.getKindOf(barSource), SourceKind.UNKNOWN);
236 expect(barContext.getKindOf(fooSource), SourceKind.UNKNOWN); 236 expect(barContext.getKindOf(fooSource), SourceKind.UNKNOWN);
237 expect(barContext.getKindOf(barSource), SourceKind.LIBRARY); 237 expect(barContext.getKindOf(barSource), SourceKind.LIBRARY);
238 }); 238 });
239 } 239 }
240 240
241 test_getContextSourcePair_nested() { 241 test_getContextSourcePair_nested() {
242 String dir1Path = '/dir1'; 242 String dir1Path = '/dir1';
243 String dir2Path = dir1Path + '/dir2'; 243 String dir2Path = dir1Path + '/dir2';
244 String filePath = dir2Path + '/file.dart'; 244 String filePath = dir2Path + '/file.dart';
245 Folder dir1 = resourceProvider.newFolder(dir1Path); 245 resourceProvider.newFile('$dir1Path/.packages', '');
246 Folder dir2 = resourceProvider.newFolder(dir2Path); 246 resourceProvider.newFile('$dir2Path/.packages', '');
247 resourceProvider.newFile(filePath, 'library lib;'); 247 resourceProvider.newFile(filePath, 'library lib;');
248 248 // create contexts
249 AnalysisContext context1 = AnalysisEngine.instance.createAnalysisContext(); 249 server.setAnalysisRoots('0', [dir1Path], [], {});
250 AnalysisContext context2 = AnalysisEngine.instance.createAnalysisContext(); 250 // get pair
251 _configureSourceFactory(context1);
252 _configureSourceFactory(context2);
253 server.folderMap[dir1] = context1;
254 server.folderMap[dir2] = context2;
255
256 ContextSourcePair pair = server.getContextSourcePair(filePath); 251 ContextSourcePair pair = server.getContextSourcePair(filePath);
257 Source source = pair.source; 252 Source source = pair.source;
258 expect(pair.context, same(context2)); 253 _assertContextOfFolder(pair.context, dir2Path);
259 expect(source, isNotNull); 254 expect(source, isNotNull);
260 expect(source.uri.scheme, 'file'); 255 expect(source.uri.scheme, 'file');
261 expect(source.fullName, filePath); 256 expect(source.fullName, filePath);
262 } 257 }
263 258
264 test_getContextSourcePair_nonFile() { 259 test_getContextSourcePair_nonFile() {
265 String dirPath = '/dir'; 260 String dirPath = '/dir';
266 Folder dir = resourceProvider.newFolder(dirPath); 261 Folder dir = resourceProvider.newFolder(dirPath);
267 262
268 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); 263 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
269 _configureSourceFactory(context); 264 _configureSourceFactory(context);
270 server.folderMap[dir] = context; 265 server.folderMap[dir] = context;
271 266
272 ContextSourcePair pair = server.getContextSourcePair(dirPath); 267 ContextSourcePair pair = server.getContextSourcePair(dirPath);
273 expect(pair, isNotNull); 268 expect(pair, isNotNull);
274 expect(pair.context, isNull); 269 expect(pair.context, isNull);
275 expect(pair.source, isNull); 270 expect(pair.source, isNull);
276 } 271 }
277 272
278 test_getContextSourcePair_package_inRoot() { 273 test_getContextSourcePair_package_inRoot() {
279 String rootPath = '/my_package'; 274 String rootPath = '/my_package';
280 String filePath = rootPath + '/lib/file.dart'; 275 String filePath = rootPath + '/lib/file.dart';
281 Folder rootFolder = resourceProvider.newFolder(rootPath); 276 Folder rootFolder = resourceProvider.newFolder(rootPath);
282 resourceProvider.newFile(filePath, 'library lib;'); 277 resourceProvider.newFile(filePath, 'library lib;');
283 278
284 packageMapProvider.packageMap = <String, List<Folder>>{ 279 packageMapProvider.packageMap = <String, List<Folder>>{
285 'my_package': <Folder>[rootFolder] 280 'my_package': <Folder>[rootFolder]
286 }; 281 };
287 282 // create contexts
288 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); 283 server.setAnalysisRoots('0', [rootPath], [], {});
289 _configureSourceFactory(context); 284 // get pair
290 server.folderMap[rootFolder] = context;
291
292 ContextSourcePair pair = server.getContextSourcePair(filePath); 285 ContextSourcePair pair = server.getContextSourcePair(filePath);
293 Source source = pair.source; 286 Source source = pair.source;
294 expect(pair.context, same(context)); 287 _assertContextOfFolder(pair.context, rootPath);
295 expect(source, isNotNull); 288 expect(source, isNotNull);
296 expect(source.uri.scheme, 'package'); 289 expect(source.uri.scheme, 'package');
297 expect(source.fullName, filePath); 290 expect(source.fullName, filePath);
298 } 291 }
299 292
300 test_getContextSourcePair_simple() { 293 test_getContextSourcePair_simple() {
301 String dirPath = '/dir'; 294 String dirPath = '/dir';
302 String filePath = dirPath + '/file.dart'; 295 String filePath = dirPath + '/file.dart';
303 Folder dir = resourceProvider.newFolder(dirPath);
304 resourceProvider.newFile(filePath, 'library lib;'); 296 resourceProvider.newFile(filePath, 'library lib;');
305 297 // create contexts
306 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); 298 server.setAnalysisRoots('0', [dirPath], [], {});
307 _configureSourceFactory(context); 299 // get pair
308 server.folderMap[dir] = context;
309
310 ContextSourcePair pair = server.getContextSourcePair(filePath); 300 ContextSourcePair pair = server.getContextSourcePair(filePath);
311 Source source = pair.source; 301 Source source = pair.source;
312 expect(pair.context, same(context)); 302 _assertContextOfFolder(pair.context, dirPath);
313 expect(source, isNotNull); 303 expect(source, isNotNull);
314 expect(source.uri.scheme, 'file'); 304 expect(source.uri.scheme, 'file');
315 expect(source.fullName, filePath); 305 expect(source.fullName, filePath);
316 } 306 }
317 307
318 /** 308 /**
319 * Test that having multiple analysis contexts analyze the same file doesn't 309 * Test that having multiple analysis contexts analyze the same file doesn't
320 * cause that file to receive duplicate notifications when it's modified. 310 * cause that file to receive duplicate notifications when it's modified.
321 */ 311 */
322 Future test_no_duplicate_notifications() async { 312 Future test_no_duplicate_notifications() async {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 // update the file 489 // update the file
500 channel.notificationsReceived.clear(); 490 channel.notificationsReceived.clear();
501 resourceProvider.modifyFile(filePath, '// 333'); 491 resourceProvider.modifyFile(filePath, '// 333');
502 await pumpEventQueue(); 492 await pumpEventQueue();
503 // the file has an overlay, so the file-system change was ignored 493 // the file has an overlay, so the file-system change was ignored
504 expect(channel.notificationsReceived.any((notification) { 494 expect(channel.notificationsReceived.any((notification) {
505 return notification.event == SERVER_STATUS; 495 return notification.event == SERVER_STATUS;
506 }), isFalse); 496 }), isFalse);
507 } 497 }
508 498
499 void _assertContextOfFolder(
500 AnalysisContext context, String expectedFolderPath) {
501 Folder expectedFolder = resourceProvider.newFolder(expectedFolderPath);
502 ContextInfo expectedContextInfo = (server.contextManager
503 as ContextManagerImpl).getContextInfoFor(expectedFolder);
504 expect(expectedContextInfo, isNotNull);
505 expect(context, same(expectedContextInfo.context));
506 }
507
509 void _configureSourceFactory(AnalysisContext context) { 508 void _configureSourceFactory(AnalysisContext context) {
510 var resourceUriResolver = new ResourceUriResolver(resourceProvider); 509 var resourceUriResolver = new ResourceUriResolver(resourceProvider);
511 var packageUriResolver = new PackageMapUriResolver( 510 var packageUriResolver = new PackageMapUriResolver(
512 resourceProvider, packageMapProvider.packageMap); 511 resourceProvider, packageMapProvider.packageMap);
513 context.sourceFactory = 512 context.sourceFactory =
514 new SourceFactory([packageUriResolver, resourceUriResolver]); 513 new SourceFactory([packageUriResolver, resourceUriResolver]);
515 } 514 }
516 } 515 }
517 516
518 class EchoHandler implements RequestHandler { 517 class EchoHandler implements RequestHandler {
(...skipping 17 matching lines...) Expand all
536 _MockServerOperation(this.context); 535 _MockServerOperation(this.context);
537 536
538 @override 537 @override
539 ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS; 538 ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS;
540 539
541 @override 540 @override
542 void perform(AnalysisServer server) { 541 void perform(AnalysisServer server) {
543 isComplete = true; 542 isComplete = true;
544 } 543 }
545 } 544 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/analysis/get_errors_test.dart ('k') | pkg/analysis_server/test/domain_execution_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698