| 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.context.directory.manager; | 5 library test.context.directory.manager; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/context_manager.dart'; | 7 import 'package:analysis_server/src/context_manager.dart'; |
| 8 import 'reflective_tests.dart'; | 8 import 'reflective_tests.dart'; |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 void test_isInAnalysisRoot_inRoot() { | 71 void test_isInAnalysisRoot_inRoot() { |
| 72 manager.setRoots(<String>[projPath], <String>[]); | 72 manager.setRoots(<String>[projPath], <String>[]); |
| 73 expect(manager.isInAnalysisRoot('$projPath/test.dart'), isTrue); | 73 expect(manager.isInAnalysisRoot('$projPath/test.dart'), isTrue); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void test_isInAnalysisRoot_notInRoot() { | 76 void test_isInAnalysisRoot_notInRoot() { |
| 77 manager.setRoots(<String>[projPath], <String>[]); | 77 manager.setRoots(<String>[projPath], <String>[]); |
| 78 expect(manager.isInAnalysisRoot('/test.dart'), isFalse); | 78 expect(manager.isInAnalysisRoot('/test.dart'), isFalse); |
| 79 } | 79 } |
| 80 | 80 |
| 81 test_refresh_folder_with_pubspec() { |
| 82 // create a context with a pubspec.yaml file |
| 83 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
| 84 resourceProvider.newFile(pubspecPath, 'pubspec'); |
| 85 manager.setRoots(<String>[projPath], <String>[]); |
| 86 return pumpEventQueue().then((_) { |
| 87 expect(manager.currentContextPaths.toList(), [projPath]); |
| 88 manager.now++; |
| 89 manager.refresh(); |
| 90 return pumpEventQueue().then((_) { |
| 91 expect(manager.currentContextPaths.toList(), [projPath]); |
| 92 expect(manager.currentContextTimestamps[projPath], manager.now); |
| 93 }); |
| 94 }); |
| 95 } |
| 96 |
| 97 test_refresh_folder_with_pubspec_subfolders() { |
| 98 // Create a folder with no pubspec.yaml, containing two subfolders with |
| 99 // pubspec.yaml files. |
| 100 String subdir1Path = posix.join(projPath, 'subdir1'); |
| 101 String subdir2Path = posix.join(projPath, 'subdir2'); |
| 102 String pubspec1Path = posix.join(subdir1Path, 'pubspec.yaml'); |
| 103 String pubspec2Path = posix.join(subdir2Path, 'pubspec.yaml'); |
| 104 resourceProvider.newFile(pubspec1Path, 'pubspec'); |
| 105 resourceProvider.newFile(pubspec2Path, 'pubspec'); |
| 106 manager.setRoots(<String>[projPath], <String>[]); |
| 107 return pumpEventQueue().then((_) { |
| 108 expect(manager.currentContextPaths.toSet(), |
| 109 [projPath, subdir1Path, subdir2Path].toSet()); |
| 110 manager.now++; |
| 111 manager.refresh(); |
| 112 return pumpEventQueue().then((_) { |
| 113 expect(manager.currentContextPaths.toSet(), |
| 114 [projPath, subdir1Path, subdir2Path].toSet()); |
| 115 expect(manager.currentContextTimestamps[projPath], manager.now); |
| 116 expect(manager.currentContextTimestamps[subdir1Path], manager.now); |
| 117 expect(manager.currentContextTimestamps[subdir2Path], manager.now); |
| 118 }); |
| 119 }); |
| 120 } |
| 121 |
| 81 void test_setRoots_addFolderWithDartFile() { | 122 void test_setRoots_addFolderWithDartFile() { |
| 82 String filePath = posix.join(projPath, 'foo.dart'); | 123 String filePath = posix.join(projPath, 'foo.dart'); |
| 83 resourceProvider.newFile(filePath, 'contents'); | 124 resourceProvider.newFile(filePath, 'contents'); |
| 84 manager.setRoots(<String>[projPath], <String>[]); | 125 manager.setRoots(<String>[projPath], <String>[]); |
| 85 // verify | 126 // verify |
| 86 var filePaths = manager.currentContextFilePaths[projPath]; | 127 var filePaths = manager.currentContextFilePaths[projPath]; |
| 87 expect(filePaths, hasLength(1)); | 128 expect(filePaths, hasLength(1)); |
| 88 expect(filePaths, contains(filePath)); | 129 expect(filePaths, contains(filePath)); |
| 89 } | 130 } |
| 90 | 131 |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 } | 672 } |
| 632 } | 673 } |
| 633 | 674 |
| 634 | 675 |
| 635 class TestContextManager extends ContextManager { | 676 class TestContextManager extends ContextManager { |
| 636 /** | 677 /** |
| 637 * Source of timestamps stored in [currentContextFilePaths]. | 678 * Source of timestamps stored in [currentContextFilePaths]. |
| 638 */ | 679 */ |
| 639 int now = 0; | 680 int now = 0; |
| 640 | 681 |
| 641 final Set<String> currentContextPaths = new Set<String>(); | 682 /** |
| 683 * Map from context to the timestamp when the context was created. |
| 684 */ |
| 685 Map<String, int> currentContextTimestamps = <String, int>{}; |
| 686 |
| 687 /** |
| 688 * Iterable of the paths to contexts that currently exist. |
| 689 */ |
| 690 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; |
| 642 | 691 |
| 643 /** | 692 /** |
| 644 * Map from context to (map from file path to timestamp of last event). | 693 * Map from context to (map from file path to timestamp of last event). |
| 645 */ | 694 */ |
| 646 final Map<String, Map<String, int>> currentContextFilePaths = <String, | 695 final Map<String, Map<String, int>> currentContextFilePaths = <String, |
| 647 Map<String, int>>{}; | 696 Map<String, int>>{}; |
| 648 | 697 |
| 649 /** | 698 /** |
| 650 * Map from context to package map. | 699 * Map from context to package map. |
| 651 */ | 700 */ |
| 652 final Map<String, Map<String, List<Folder>>> currentContextPackageMaps = | 701 final Map<String, Map<String, List<Folder>>> currentContextPackageMaps = |
| 653 <String, Map<String, List<Folder>>>{}; | 702 <String, Map<String, List<Folder>>>{}; |
| 654 | 703 |
| 655 TestContextManager(MemoryResourceProvider resourceProvider, | 704 TestContextManager(MemoryResourceProvider resourceProvider, |
| 656 PackageMapProvider packageMapProvider) | 705 PackageMapProvider packageMapProvider) |
| 657 : super(resourceProvider, packageMapProvider); | 706 : super(resourceProvider, packageMapProvider); |
| 658 | 707 |
| 659 @override | 708 @override |
| 660 void addContext(Folder folder, Map<String, List<Folder>> packageMap) { | 709 void addContext(Folder folder, Map<String, List<Folder>> packageMap) { |
| 661 String path = folder.path; | 710 String path = folder.path; |
| 662 currentContextPaths.add(path); | 711 expect(currentContextPaths, isNot(contains(path))); |
| 712 currentContextTimestamps[path] = now; |
| 663 currentContextFilePaths[path] = <String, int>{}; | 713 currentContextFilePaths[path] = <String, int>{}; |
| 664 currentContextPackageMaps[path] = packageMap; | 714 currentContextPackageMaps[path] = packageMap; |
| 665 } | 715 } |
| 666 | 716 |
| 667 @override | 717 @override |
| 668 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 718 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
| 669 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; | 719 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; |
| 670 for (Source source in changeSet.addedSources) { | 720 for (Source source in changeSet.addedSources) { |
| 671 expect(filePaths, isNot(contains(source.fullName))); | 721 expect(filePaths, isNot(contains(source.fullName))); |
| 672 filePaths[source.fullName] = now; | 722 filePaths[source.fullName] = now; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 686 expect(actualFiles, unorderedEquals(expectedFiles)); | 736 expect(actualFiles, unorderedEquals(expectedFiles)); |
| 687 } | 737 } |
| 688 | 738 |
| 689 void assertContextPaths(List<String> expected) { | 739 void assertContextPaths(List<String> expected) { |
| 690 expect(currentContextPaths, unorderedEquals(expected)); | 740 expect(currentContextPaths, unorderedEquals(expected)); |
| 691 } | 741 } |
| 692 | 742 |
| 693 @override | 743 @override |
| 694 void removeContext(Folder folder) { | 744 void removeContext(Folder folder) { |
| 695 String path = folder.path; | 745 String path = folder.path; |
| 696 currentContextPaths.remove(path); | 746 expect(currentContextPaths, contains(path)); |
| 747 currentContextTimestamps.remove(path); |
| 697 currentContextFilePaths.remove(path); | 748 currentContextFilePaths.remove(path); |
| 698 currentContextPackageMaps.remove(path); | 749 currentContextPackageMaps.remove(path); |
| 699 } | 750 } |
| 700 | 751 |
| 701 @override | 752 @override |
| 702 void updateContextPackageMap(Folder contextFolder, Map<String, | 753 void updateContextPackageMap(Folder contextFolder, Map<String, |
| 703 List<Folder>> packageMap) { | 754 List<Folder>> packageMap) { |
| 704 currentContextPackageMaps[contextFolder.path] = packageMap; | 755 currentContextPackageMaps[contextFolder.path] = packageMap; |
| 705 } | 756 } |
| 706 } | 757 } |
| OLD | NEW |