| 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 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/context_manager.dart'; | 9 import 'package:analysis_server/src/context_manager.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 test_refresh_folder_with_pubspec() { | 124 test_refresh_folder_with_pubspec() { |
| 125 // create a context with a pubspec.yaml file | 125 // create a context with a pubspec.yaml file |
| 126 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 126 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
| 127 resourceProvider.newFile(pubspecPath, 'pubspec'); | 127 resourceProvider.newFile(pubspecPath, 'pubspec'); |
| 128 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 128 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 129 return pumpEventQueue().then((_) { | 129 return pumpEventQueue().then((_) { |
| 130 expect(manager.currentContextPaths.toList(), [projPath]); | 130 expect(manager.currentContextPaths.toList(), [projPath]); |
| 131 manager.now++; | 131 manager.now++; |
| 132 manager.refresh(); | 132 manager.refresh(null); |
| 133 return pumpEventQueue().then((_) { | 133 return pumpEventQueue().then((_) { |
| 134 expect(manager.currentContextPaths.toList(), [projPath]); | 134 expect(manager.currentContextPaths.toList(), [projPath]); |
| 135 expect(manager.currentContextTimestamps[projPath], manager.now); | 135 expect(manager.currentContextTimestamps[projPath], manager.now); |
| 136 }); | 136 }); |
| 137 }); | 137 }); |
| 138 } | 138 } |
| 139 | 139 |
| 140 test_refresh_folder_with_pubspec_subfolders() { | 140 test_refresh_folder_with_pubspec_subfolders() { |
| 141 // Create a folder with no pubspec.yaml, containing two subfolders with | 141 // Create a folder with no pubspec.yaml, containing two subfolders with |
| 142 // pubspec.yaml files. | 142 // pubspec.yaml files. |
| 143 String subdir1Path = posix.join(projPath, 'subdir1'); | 143 String subdir1Path = posix.join(projPath, 'subdir1'); |
| 144 String subdir2Path = posix.join(projPath, 'subdir2'); | 144 String subdir2Path = posix.join(projPath, 'subdir2'); |
| 145 String pubspec1Path = posix.join(subdir1Path, 'pubspec.yaml'); | 145 String pubspec1Path = posix.join(subdir1Path, 'pubspec.yaml'); |
| 146 String pubspec2Path = posix.join(subdir2Path, 'pubspec.yaml'); | 146 String pubspec2Path = posix.join(subdir2Path, 'pubspec.yaml'); |
| 147 resourceProvider.newFile(pubspec1Path, 'pubspec'); | 147 resourceProvider.newFile(pubspec1Path, 'pubspec'); |
| 148 resourceProvider.newFile(pubspec2Path, 'pubspec'); | 148 resourceProvider.newFile(pubspec2Path, 'pubspec'); |
| 149 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 149 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 150 return pumpEventQueue().then((_) { | 150 return pumpEventQueue().then((_) { |
| 151 expect(manager.currentContextPaths.toSet(), | 151 expect(manager.currentContextPaths.toSet(), |
| 152 [subdir1Path, subdir2Path, projPath].toSet()); | 152 [subdir1Path, subdir2Path, projPath].toSet()); |
| 153 manager.now++; | 153 manager.now++; |
| 154 manager.refresh(); | 154 manager.refresh(null); |
| 155 return pumpEventQueue().then((_) { | 155 return pumpEventQueue().then((_) { |
| 156 expect(manager.currentContextPaths.toSet(), | 156 expect(manager.currentContextPaths.toSet(), |
| 157 [subdir1Path, subdir2Path, projPath].toSet()); | 157 [subdir1Path, subdir2Path, projPath].toSet()); |
| 158 expect(manager.currentContextTimestamps[projPath], manager.now); | 158 expect(manager.currentContextTimestamps[projPath], manager.now); |
| 159 expect(manager.currentContextTimestamps[subdir1Path], manager.now); | 159 expect(manager.currentContextTimestamps[subdir1Path], manager.now); |
| 160 expect(manager.currentContextTimestamps[subdir2Path], manager.now); | 160 expect(manager.currentContextTimestamps[subdir2Path], manager.now); |
| 161 }); | 161 }); |
| 162 }); | 162 }); |
| 163 } | 163 } |
| 164 | 164 |
| 165 test_refresh_oneContext() { |
| 166 // create two contexts with pubspec.yaml files |
| 167 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
| 168 resourceProvider.newFile(pubspecPath, 'pubspec1'); |
| 169 |
| 170 String proj2Path = '/my/proj2'; |
| 171 resourceProvider.newFolder(proj2Path); |
| 172 String pubspec2Path = posix.join(proj2Path, 'pubspec.yaml'); |
| 173 resourceProvider.newFile(pubspec2Path, 'pubspec2'); |
| 174 |
| 175 List<String> roots = <String>[projPath, proj2Path]; |
| 176 manager.setRoots(roots, <String>[], <String, String>{}); |
| 177 return pumpEventQueue().then((_) { |
| 178 expect(manager.currentContextPaths.toList(), unorderedEquals(roots)); |
| 179 int then = manager.now; |
| 180 manager.now++; |
| 181 manager.refresh([resourceProvider.getResource(proj2Path)]); |
| 182 return pumpEventQueue().then((_) { |
| 183 expect(manager.currentContextPaths.toList(), unorderedEquals(roots)); |
| 184 expect(manager.currentContextTimestamps[projPath], then); |
| 185 expect(manager.currentContextTimestamps[proj2Path], manager.now); |
| 186 }); |
| 187 }); |
| 188 } |
| 189 |
| 165 void test_setRoots_addFolderWithDartFile() { | 190 void test_setRoots_addFolderWithDartFile() { |
| 166 String filePath = posix.join(projPath, 'foo.dart'); | 191 String filePath = posix.join(projPath, 'foo.dart'); |
| 167 resourceProvider.newFile(filePath, 'contents'); | 192 resourceProvider.newFile(filePath, 'contents'); |
| 168 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 193 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 169 // verify | 194 // verify |
| 170 var filePaths = manager.currentContextFilePaths[projPath]; | 195 var filePaths = manager.currentContextFilePaths[projPath]; |
| 171 expect(filePaths, hasLength(1)); | 196 expect(filePaths, hasLength(1)); |
| 172 expect(filePaths, contains(filePath)); | 197 expect(filePaths, contains(filePath)); |
| 173 } | 198 } |
| 174 | 199 |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 currentContextSources.remove(path); | 981 currentContextSources.remove(path); |
| 957 currentContextPackageUriResolvers.remove(path); | 982 currentContextPackageUriResolvers.remove(path); |
| 958 } | 983 } |
| 959 | 984 |
| 960 @override | 985 @override |
| 961 void updateContextPackageUriResolver( | 986 void updateContextPackageUriResolver( |
| 962 Folder contextFolder, UriResolver packageUriResolver) { | 987 Folder contextFolder, UriResolver packageUriResolver) { |
| 963 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; | 988 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; |
| 964 } | 989 } |
| 965 } | 990 } |
| OLD | NEW |