| 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 'package:analysis_server/src/package_map_provider.dart'; | 8 import 'package:analysis_server/src/package_map_provider.dart'; |
| 9 import 'package:analysis_testing/reflective_tests.dart'; | 9 import 'package:analysis_testing/reflective_tests.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 void test_setRoots_addFolderWithoutPubspec() { | 150 void test_setRoots_addFolderWithoutPubspec() { |
| 151 packageMapProvider.packageMap = null; | 151 packageMapProvider.packageMap = null; |
| 152 manager.setRoots(<String>[projPath], <String>[]); | 152 manager.setRoots(<String>[projPath], <String>[]); |
| 153 // verify | 153 // verify |
| 154 expect(manager.currentContextPaths, hasLength(1)); | 154 expect(manager.currentContextPaths, hasLength(1)); |
| 155 expect(manager.currentContextPaths, contains(projPath)); | 155 expect(manager.currentContextPaths, contains(projPath)); |
| 156 expect(manager.currentContextFilePaths[projPath], hasLength(0)); | 156 expect(manager.currentContextFilePaths[projPath], hasLength(0)); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void test_setRoots_ignoreSubContext_ofSubContext() { |
| 160 // prepare paths |
| 161 String root = '/root'; |
| 162 String rootFile = '$root/root.dart'; |
| 163 String subProject = '$root/sub'; |
| 164 String subPubspec = '$subProject/pubspec.yaml'; |
| 165 String subFile = '$subProject/bin/sub.dart'; |
| 166 String subSubPubspec = '$subProject/subsub/pubspec.yaml'; |
| 167 // create files |
| 168 resourceProvider.newFile(rootFile, 'library root;'); |
| 169 resourceProvider.newFile(subPubspec, 'pubspec'); |
| 170 resourceProvider.newFile(subFile, 'library sub;'); |
| 171 resourceProvider.newFile(subSubPubspec, 'pubspec'); |
| 172 // set roots |
| 173 manager.setRoots(<String>[root], <String>[]); |
| 174 manager.assertContextPaths([root, subProject]); |
| 175 manager.assertContextFiles(root, [rootFile]); |
| 176 manager.assertContextFiles(subProject, [subFile]); |
| 177 } |
| 178 |
| 159 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { | 179 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { |
| 160 String packagePath = '/package/foo'; | 180 String packagePath = '/package/foo'; |
| 161 Folder packageFolder = resourceProvider.newFolder(packagePath); | 181 Folder packageFolder = resourceProvider.newFolder(packagePath); |
| 162 packageMapProvider.packageMap = { | 182 packageMapProvider.packageMap = { |
| 163 'foo': [packageFolder] | 183 'foo': [packageFolder] |
| 164 }; | 184 }; |
| 165 manager.setRoots(<String>[projPath], <String>[]); | 185 manager.setRoots(<String>[projPath], <String>[]); |
| 166 expect( | 186 expect( |
| 167 manager.currentContextPackageMaps[projPath], | 187 manager.currentContextPackageMaps[projPath], |
| 168 equals(packageMapProvider.packageMap)); | 188 equals(packageMapProvider.packageMap)); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 // add file in subfolder | 282 // add file in subfolder |
| 263 String filePath = posix.join(projPath, 'foo', 'bar.dart'); | 283 String filePath = posix.join(projPath, 'foo', 'bar.dart'); |
| 264 resourceProvider.newFile(filePath, 'contents'); | 284 resourceProvider.newFile(filePath, 'contents'); |
| 265 // the file was added | 285 // the file was added |
| 266 return pumpEventQueue().then((_) { | 286 return pumpEventQueue().then((_) { |
| 267 expect(filePaths, hasLength(1)); | 287 expect(filePaths, hasLength(1)); |
| 268 expect(filePaths, contains(filePath)); | 288 expect(filePaths, contains(filePath)); |
| 269 }); | 289 }); |
| 270 } | 290 } |
| 271 | 291 |
| 272 test_watch_addPubspec() { | 292 test_watch_addPubspec_toRoot() { |
| 273 // prepare paths | 293 // prepare paths |
| 274 String root = '/root'; | 294 String root = '/root'; |
| 275 String rootFile = '$root/root.dart'; | 295 String rootFile = '$root/root.dart'; |
| 296 String rootPubspec = '$root/pubspec.yaml'; |
| 297 // create files |
| 298 resourceProvider.newFile(rootFile, 'library root;'); |
| 299 // set roots |
| 300 manager.setRoots(<String>[root], <String>[]); |
| 301 manager.assertContextPaths([root]); |
| 302 // verify files |
| 303 manager.assertContextFiles(root, [rootFile]); |
| 304 // add pubspec - still just one root |
| 305 resourceProvider.newFile(rootPubspec, 'pubspec'); |
| 306 return pumpEventQueue().then((_) { |
| 307 manager.assertContextPaths([root]); |
| 308 manager.assertContextFiles(root, [rootFile]); |
| 309 }); |
| 310 } |
| 311 |
| 312 test_watch_addPubspec_toSubFolder() { |
| 313 // prepare paths |
| 314 String root = '/root'; |
| 315 String rootFile = '$root/root.dart'; |
| 276 String subProject = '$root/sub/aaa'; | 316 String subProject = '$root/sub/aaa'; |
| 277 String subPubspec = '$subProject/pubspec.yaml'; | 317 String subPubspec = '$subProject/pubspec.yaml'; |
| 278 String subFile = '$subProject/bin/a.dart'; | 318 String subFile = '$subProject/bin/a.dart'; |
| 279 // create files | 319 // create files |
| 280 resourceProvider.newFile(rootFile, 'library root;'); | 320 resourceProvider.newFile(rootFile, 'library root;'); |
| 281 resourceProvider.newFile(subFile, 'library a;'); | 321 resourceProvider.newFile(subFile, 'library a;'); |
| 282 // set roots | 322 // set roots |
| 283 manager.setRoots(<String>[root], <String>[]); | 323 manager.setRoots(<String>[root], <String>[]); |
| 284 manager.assertContextPaths([root]); | 324 manager.assertContextPaths([root]); |
| 285 // verify files | 325 // verify files |
| 286 manager.assertContextFiles(root, [rootFile, subFile]); | 326 manager.assertContextFiles(root, [rootFile, subFile]); |
| 287 // add pubspec | 327 // add pubspec |
| 288 resourceProvider.newFile(subPubspec, 'pubspec'); | 328 resourceProvider.newFile(subPubspec, 'pubspec'); |
| 289 return pumpEventQueue().then((_) { | 329 return pumpEventQueue().then((_) { |
| 290 manager.assertContextPaths([root, subProject]); | 330 manager.assertContextPaths([root, subProject]); |
| 291 manager.assertContextFiles(root, [rootFile]); | 331 manager.assertContextFiles(root, [rootFile]); |
| 292 manager.assertContextFiles(subProject, [subFile]); | 332 manager.assertContextFiles(subProject, [subFile]); |
| 293 }); | 333 }); |
| 294 } | 334 } |
| 295 | 335 |
| 336 test_watch_addPubspec_toSubFolder_ofSubFolder() { |
| 337 // prepare paths |
| 338 String root = '/root'; |
| 339 String rootFile = '$root/root.dart'; |
| 340 String subProject = '$root/sub'; |
| 341 String subPubspec = '$subProject/pubspec.yaml'; |
| 342 String subFile = '$subProject/bin/sub.dart'; |
| 343 String subSubPubspec = '$subProject/subsub/pubspec.yaml'; |
| 344 // create files |
| 345 resourceProvider.newFile(rootFile, 'library root;'); |
| 346 resourceProvider.newFile(subPubspec, 'pubspec'); |
| 347 resourceProvider.newFile(subFile, 'library sub;'); |
| 348 // set roots |
| 349 manager.setRoots(<String>[root], <String>[]); |
| 350 manager.assertContextPaths([root, subProject]); |
| 351 manager.assertContextFiles(root, [rootFile]); |
| 352 manager.assertContextFiles(subProject, [subFile]); |
| 353 // add pubspec - ignore, because is already in a pubspec-based context |
| 354 resourceProvider.newFile(subSubPubspec, 'pubspec'); |
| 355 return pumpEventQueue().then((_) { |
| 356 manager.assertContextPaths([root, subProject]); |
| 357 manager.assertContextFiles(root, [rootFile]); |
| 358 manager.assertContextFiles(subProject, [subFile]); |
| 359 }); |
| 360 } |
| 361 |
| 296 test_watch_deleteFile() { | 362 test_watch_deleteFile() { |
| 297 String filePath = posix.join(projPath, 'foo.dart'); | 363 String filePath = posix.join(projPath, 'foo.dart'); |
| 298 // add root with a file | 364 // add root with a file |
| 299 resourceProvider.newFile(filePath, 'contents'); | 365 resourceProvider.newFile(filePath, 'contents'); |
| 300 manager.setRoots(<String>[projPath], <String>[]); | 366 manager.setRoots(<String>[projPath], <String>[]); |
| 301 // the file was added | 367 // the file was added |
| 302 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; | 368 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; |
| 303 expect(filePaths, hasLength(1)); | 369 expect(filePaths, hasLength(1)); |
| 304 expect(filePaths, contains(filePath)); | 370 expect(filePaths, contains(filePath)); |
| 305 // delete the file | 371 // delete the file |
| 306 resourceProvider.deleteFile(filePath); | 372 resourceProvider.deleteFile(filePath); |
| 307 return pumpEventQueue().then((_) { | 373 return pumpEventQueue().then((_) { |
| 308 return expect(filePaths, hasLength(0)); | 374 return expect(filePaths, hasLength(0)); |
| 309 }); | 375 }); |
| 310 } | 376 } |
| 311 | 377 |
| 312 test_watch_deletePubspec() { | 378 test_watch_deletePubspec_fromRoot() { |
| 379 // prepare paths |
| 380 String root = '/root'; |
| 381 String rootPubspec = '$root/pubspec.yaml'; |
| 382 String rootFile = '$root/root.dart'; |
| 383 // create files |
| 384 resourceProvider.newFile(rootPubspec, 'pubspec'); |
| 385 resourceProvider.newFile(rootFile, 'library root;'); |
| 386 // set roots |
| 387 manager.setRoots(<String>[root], <String>[]); |
| 388 manager.assertContextPaths([root]); |
| 389 manager.assertContextFiles(root, [rootFile]); |
| 390 // delete the pubspec |
| 391 resourceProvider.deleteFile(rootPubspec); |
| 392 return pumpEventQueue().then((_) { |
| 393 manager.assertContextPaths([root]); |
| 394 manager.assertContextFiles(root, [rootFile]); |
| 395 }); |
| 396 } |
| 397 |
| 398 test_watch_deletePubspec_fromSubFolder() { |
| 313 // prepare paths | 399 // prepare paths |
| 314 String root = '/root'; | 400 String root = '/root'; |
| 315 String rootFile = '$root/root.dart'; | 401 String rootFile = '$root/root.dart'; |
| 316 String subProject = '$root/sub/aaa'; | 402 String subProject = '$root/sub/aaa'; |
| 317 String subPubspec = '$subProject/pubspec.yaml'; | 403 String subPubspec = '$subProject/pubspec.yaml'; |
| 318 String subFile = '$subProject/bin/a.dart'; | 404 String subFile = '$subProject/bin/a.dart'; |
| 319 // create files | 405 // create files |
| 320 resourceProvider.newFile(subPubspec, 'pubspec'); | 406 resourceProvider.newFile(subPubspec, 'pubspec'); |
| 321 resourceProvider.newFile(rootFile, 'library root;'); | 407 resourceProvider.newFile(rootFile, 'library root;'); |
| 322 resourceProvider.newFile(subFile, 'library a;'); | 408 resourceProvider.newFile(subFile, 'library a;'); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 currentContextFilePaths.remove(path); | 558 currentContextFilePaths.remove(path); |
| 473 currentContextPackageMaps.remove(path); | 559 currentContextPackageMaps.remove(path); |
| 474 } | 560 } |
| 475 | 561 |
| 476 @override | 562 @override |
| 477 void updateContextPackageMap(Folder contextFolder, Map<String, | 563 void updateContextPackageMap(Folder contextFolder, Map<String, |
| 478 List<Folder>> packageMap) { | 564 List<Folder>> packageMap) { |
| 479 currentContextPackageMaps[contextFolder.path] = packageMap; | 565 currentContextPackageMaps[contextFolder.path] = packageMap; |
| 480 } | 566 } |
| 481 } | 567 } |
| OLD | NEW |