| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.src.single_context_manager; | 5 library test.analysis_server.src.single_context_manager; |
| 6 | 6 |
| 7 import 'dart:core'; | 7 import 'dart:core'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/single_context_manager.dart'; | 9 import 'package:analysis_server/src/single_context_manager.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 DartSdkManager sdkManager = | 67 DartSdkManager sdkManager = |
| 68 new DartSdkManager('', false, (_) => new MockSdk()); | 68 new DartSdkManager('', false, (_) => new MockSdk()); |
| 69 manager = new SingleContextManager(resourceProvider, sdkManager, | 69 manager = new SingleContextManager(resourceProvider, sdkManager, |
| 70 (_) => packageResolver, analysisFilesGlobs, new AnalysisOptionsImpl()); | 70 (_) => packageResolver, analysisFilesGlobs, new AnalysisOptionsImpl()); |
| 71 callbacks = new TestContextManagerCallbacks(resourceProvider); | 71 callbacks = new TestContextManagerCallbacks(resourceProvider); |
| 72 manager.callbacks = callbacks; | 72 manager.callbacks = callbacks; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void test_isIgnored_false() { | 75 void test_isIgnored_false() { |
| 76 String project = '/project'; | 76 String project = '/project'; |
| 77 resourceProvider.newFolder(project); |
| 77 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 78 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| 78 expect(manager.isIgnored('$project/file.dart'), isFalse); | 79 expect(manager.isIgnored('$project/file.dart'), isFalse); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void test_isIgnored_true_inDotFolder() { | 82 void test_isIgnored_true_inDotFolder() { |
| 82 String project = '/project'; | 83 String project = '/project'; |
| 84 resourceProvider.newFolder(project); |
| 83 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 85 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| 84 expect(manager.isIgnored('$project/foo/.bar/file.dart'), isTrue); | 86 expect(manager.isIgnored('$project/foo/.bar/file.dart'), isTrue); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void test_isIgnored_true_inExcludedPath() { | 89 void test_isIgnored_true_inExcludedPath() { |
| 88 String project = '/project'; | 90 String project = '/project'; |
| 89 String excludedPath = '/project/excluded'; | 91 String excludedPath = '/project/excluded'; |
| 92 resourceProvider.newFolder(project); |
| 90 manager.setRoots( | 93 manager.setRoots( |
| 91 <String>[project], <String>[excludedPath], <String, String>{}); | 94 <String>[project], <String>[excludedPath], <String, String>{}); |
| 92 expect(manager.isIgnored('$excludedPath/file.dart'), isTrue); | 95 expect(manager.isIgnored('$excludedPath/file.dart'), isTrue); |
| 93 } | 96 } |
| 94 | 97 |
| 95 void test_isIgnored_true_notInRoot() { | 98 void test_isIgnored_true_notInRoot() { |
| 96 String root1 = '/context/root1'; | 99 String root1 = '/context/root1'; |
| 97 String root2 = '/context/root2'; | 100 String root2 = '/context/root2'; |
| 101 resourceProvider.newFolder(root1); |
| 102 resourceProvider.newFolder(root2); |
| 98 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{}); | 103 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{}); |
| 99 expect(manager.isIgnored('$context/root3/file.dart'), isTrue); | 104 expect(manager.isIgnored('$context/root3/file.dart'), isTrue); |
| 100 } | 105 } |
| 101 | 106 |
| 102 void test_isInAnalysisRoot_false_inExcludedPath() { | 107 void test_isInAnalysisRoot_false_inExcludedPath() { |
| 103 String project = '/project'; | 108 String project = '/project'; |
| 104 String excludedPath = '/project/excluded'; | 109 String excludedPath = '/project/excluded'; |
| 110 resourceProvider.newFolder(project); |
| 105 manager.setRoots( | 111 manager.setRoots( |
| 106 <String>[project], <String>[excludedPath], <String, String>{}); | 112 <String>[project], <String>[excludedPath], <String, String>{}); |
| 107 expect(manager.isInAnalysisRoot('$excludedPath/file.dart'), isFalse); | 113 expect(manager.isInAnalysisRoot('$excludedPath/file.dart'), isFalse); |
| 108 } | 114 } |
| 109 | 115 |
| 110 void test_isInAnalysisRoot_false_notInRoot() { | 116 void test_isInAnalysisRoot_false_notInRoot() { |
| 111 String root1 = '/context/root1'; | 117 String root1 = '/context/root1'; |
| 112 String root2 = '/context/root2'; | 118 String root2 = '/context/root2'; |
| 119 resourceProvider.newFolder(root1); |
| 120 resourceProvider.newFolder(root2); |
| 113 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{}); | 121 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{}); |
| 114 expect(manager.isInAnalysisRoot('$context/root3/file.dart'), isFalse); | 122 expect(manager.isInAnalysisRoot('$context/root3/file.dart'), isFalse); |
| 115 } | 123 } |
| 116 | 124 |
| 117 void test_isInAnalysisRoot_true() { | 125 void test_isInAnalysisRoot_true() { |
| 118 String project = '/project'; | 126 String project = '/project'; |
| 127 resourceProvider.newFolder(project); |
| 119 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 128 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| 120 expect(manager.isInAnalysisRoot('$project/file.dart'), isTrue); | 129 expect(manager.isInAnalysisRoot('$project/file.dart'), isTrue); |
| 121 } | 130 } |
| 122 | 131 |
| 123 void test_refresh() { | 132 void test_refresh() { |
| 124 String project = '/project'; | 133 String project = '/project'; |
| 125 String file1 = '$project/file1.dart'; | 134 String file1 = '$project/file1.dart'; |
| 126 String file2 = '$project/file2.dart'; | 135 String file2 = '$project/file2.dart'; |
| 127 // create files | 136 // create files |
| 128 resourceProvider.newFile(file1, ''); | 137 resourceProvider.newFile(file1, ''); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 String project = '/.pub/project'; | 373 String project = '/.pub/project'; |
| 365 String fileA = '$project/foo.dart'; | 374 String fileA = '$project/foo.dart'; |
| 366 resourceProvider.newFile(fileA, ''); | 375 resourceProvider.newFile(fileA, ''); |
| 367 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 376 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| 368 callbacks.assertContextPaths([project]); | 377 callbacks.assertContextPaths([project]); |
| 369 callbacks.assertContextFiles(project, [fileA]); | 378 callbacks.assertContextFiles(project, [fileA]); |
| 370 } | 379 } |
| 371 | 380 |
| 372 test_watch_addFile() async { | 381 test_watch_addFile() async { |
| 373 String project = '/project'; | 382 String project = '/project'; |
| 383 resourceProvider.newFolder(project); |
| 374 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 384 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| 375 // empty folder initially | 385 // empty folder initially |
| 376 callbacks.assertContextFiles(project, []); | 386 callbacks.assertContextFiles(project, []); |
| 377 // add file | 387 // add file |
| 378 String file = '$project/foo.dart'; | 388 String file = '$project/foo.dart'; |
| 379 resourceProvider.newFile(file, 'contents'); | 389 resourceProvider.newFile(file, 'contents'); |
| 380 // the file was added | 390 // the file was added |
| 381 await pumpEventQueue(); | 391 await pumpEventQueue(); |
| 382 callbacks.assertContextFiles(project, [file]); | 392 callbacks.assertContextFiles(project, [file]); |
| 383 } | 393 } |
| 384 | 394 |
| 385 test_watch_addFile_afterChangingRoots() async { | 395 test_watch_addFile_afterChangingRoots() async { |
| 386 String contextPath = '/context'; | 396 String contextPath = '/context'; |
| 387 String root1 = '$contextPath/root1'; | 397 String root1 = '$contextPath/root1'; |
| 388 String root2 = '$contextPath/root2'; | 398 String root2 = '$contextPath/root2'; |
| 389 String file1 = '$root1/file1.dart'; | 399 String file1 = '$root1/file1.dart'; |
| 390 String file2 = '$root2/file2.dart'; | 400 String file2 = '$root2/file2.dart'; |
| 401 resourceProvider.newFolder(root1); |
| 402 resourceProvider.newFolder(root2); |
| 391 manager.setRoots(<String>[root1], <String>[], <String, String>{}); | 403 manager.setRoots(<String>[root1], <String>[], <String, String>{}); |
| 392 manager.setRoots(<String>[root2], <String>[], <String, String>{}); | 404 manager.setRoots(<String>[root2], <String>[], <String, String>{}); |
| 393 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{}); | 405 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{}); |
| 394 manager.setRoots(<String>[root2], <String>[], <String, String>{}); | 406 manager.setRoots(<String>[root2], <String>[], <String, String>{}); |
| 395 // empty folder initially | 407 // empty folder initially |
| 396 callbacks.assertContextFiles(root2, []); | 408 callbacks.assertContextFiles(root2, []); |
| 397 // add files | 409 // add files |
| 398 resourceProvider.newFile(file1, ''); | 410 resourceProvider.newFile(file1, ''); |
| 399 resourceProvider.newFile(file2, ''); | 411 resourceProvider.newFile(file2, ''); |
| 400 // the file was added | 412 // the file was added |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 resourceProvider.newFile(fileA, ''); | 464 resourceProvider.newFile(fileA, ''); |
| 453 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 465 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| 454 callbacks.assertContextPaths([project]); | 466 callbacks.assertContextPaths([project]); |
| 455 callbacks.assertContextFiles(project, [fileA]); | 467 callbacks.assertContextFiles(project, [fileA]); |
| 456 resourceProvider.newFile(fileB, ''); | 468 resourceProvider.newFile(fileB, ''); |
| 457 await pumpEventQueue(); | 469 await pumpEventQueue(); |
| 458 callbacks.assertContextPaths([project]); | 470 callbacks.assertContextPaths([project]); |
| 459 callbacks.assertContextFiles(project, [fileA]); | 471 callbacks.assertContextFiles(project, [fileA]); |
| 460 } | 472 } |
| 461 | 473 |
| 462 test_watch_addFileInSubfolder() async { | 474 test_watch_addFileInSubFolder() async { |
| 463 String project = '/project'; | 475 String project = '/project'; |
| 476 resourceProvider.newFolder(project); |
| 464 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 477 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| 465 // empty folder initially | 478 // empty folder initially |
| 466 callbacks.assertContextFiles(project, []); | 479 callbacks.assertContextFiles(project, []); |
| 467 // add file in subfolder | 480 // add file in subfolder |
| 468 String file = '$project/foo/bar.dart'; | 481 String file = '$project/foo/bar.dart'; |
| 469 resourceProvider.newFile(file, 'contents'); | 482 resourceProvider.newFile(file, 'contents'); |
| 470 // the file was added | 483 // the file was added |
| 471 await pumpEventQueue(); | 484 await pumpEventQueue(); |
| 472 callbacks.assertContextFiles(project, [file]); | 485 callbacks.assertContextFiles(project, [file]); |
| 473 } | 486 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 manager.processPlugins(plugins); | 541 manager.processPlugins(plugins); |
| 529 } | 542 } |
| 530 } | 543 } |
| 531 | 544 |
| 532 class TestUriResolver extends UriResolver { | 545 class TestUriResolver extends UriResolver { |
| 533 @override | 546 @override |
| 534 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 547 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 535 return null; | 548 return null; |
| 536 } | 549 } |
| 537 } | 550 } |
| OLD | NEW |