| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 TestContextManagerCallbacks callbacks; | 58 TestContextManagerCallbacks callbacks; |
| 59 | 59 |
| 60 MemoryResourceProvider resourceProvider; | 60 MemoryResourceProvider resourceProvider; |
| 61 | 61 |
| 62 MockPackageMapProvider packageMapProvider; | 62 MockPackageMapProvider packageMapProvider; |
| 63 | 63 |
| 64 UriResolver packageResolver = null; | 64 UriResolver packageResolver = null; |
| 65 | 65 |
| 66 String projPath = '/my/proj'; | 66 String projPath = '/my/proj'; |
| 67 | 67 |
| 68 void fail_test_setRoots_addPackageRoot() { |
| 69 // TODO(paulberry): failing due to dartbug.com/23909. |
| 70 String packagePathFoo = '/package1/foo'; |
| 71 String packageRootPath = '/package2/foo'; |
| 72 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
| 73 packageMapProvider.packageMap = {'foo': [packageFolder]}; |
| 74 List<String> includedPaths = <String>[projPath]; |
| 75 List<String> excludedPaths = <String>[]; |
| 76 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
| 77 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
| 78 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 79 projPath: packageRootPath |
| 80 }); |
| 81 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 82 } |
| 83 |
| 84 void fail_test_setRoots_changePackageRoot() { |
| 85 // TODO(paulberry): failing due to dartbug.com/23909. |
| 86 String packageRootPath1 = '/package1'; |
| 87 String packageRootPath2 = '/package2'; |
| 88 List<String> includedPaths = <String>[projPath]; |
| 89 List<String> excludedPaths = <String>[]; |
| 90 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 91 projPath: packageRootPath1 |
| 92 }); |
| 93 _checkPackageRoot(projPath, equals(packageRootPath1)); |
| 94 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 95 projPath: packageRootPath2 |
| 96 }); |
| 97 _checkPackageRoot(projPath, equals(packageRootPath2)); |
| 98 } |
| 99 |
| 100 void fail_test_setRoots_newFolderWithPackageRoot() { |
| 101 // TODO(paulberry): failing due to dartbug.com/23909. |
| 102 String packageRootPath = '/package'; |
| 103 manager.setRoots(<String>[projPath], <String>[], <String, String>{ |
| 104 projPath: packageRootPath |
| 105 }); |
| 106 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 107 } |
| 108 |
| 109 void fail_test_setRoots_removePackageRoot() { |
| 110 // TODO(paulberry): failing due to dartbug.com/23909. |
| 111 String packagePathFoo = '/package1/foo'; |
| 112 String packageRootPath = '/package2/foo'; |
| 113 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
| 114 packageMapProvider.packageMap = {'foo': [packageFolder]}; |
| 115 List<String> includedPaths = <String>[projPath]; |
| 116 List<String> excludedPaths = <String>[]; |
| 117 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 118 projPath: packageRootPath |
| 119 }); |
| 120 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 121 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
| 122 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
| 123 } |
| 124 |
| 68 String newFile(List<String> pathComponents, [String content = '']) { | 125 String newFile(List<String> pathComponents, [String content = '']) { |
| 69 String filePath = posix.joinAll(pathComponents); | 126 String filePath = posix.joinAll(pathComponents); |
| 70 resourceProvider.newFile(filePath, content); | 127 resourceProvider.newFile(filePath, content); |
| 71 return filePath; | 128 return filePath; |
| 72 } | 129 } |
| 73 | 130 |
| 74 String newFolder(List<String> pathComponents) { | 131 String newFolder(List<String> pathComponents) { |
| 75 String folderPath = posix.joinAll(pathComponents); | 132 String folderPath = posix.joinAll(pathComponents); |
| 76 resourceProvider.newFolder(folderPath); | 133 resourceProvider.newFolder(folderPath); |
| 77 return folderPath; | 134 return folderPath; |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 626 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
| 570 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); | 627 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); |
| 571 // verify package maps | 628 // verify package maps |
| 572 _checkPackageMap(root, isNull); | 629 _checkPackageMap(root, isNull); |
| 573 _checkPackageMap( | 630 _checkPackageMap( |
| 574 subProjectA, equals(packageMapProvider.packageMaps[subProjectA])); | 631 subProjectA, equals(packageMapProvider.packageMaps[subProjectA])); |
| 575 _checkPackageMap( | 632 _checkPackageMap( |
| 576 subProjectB, equals(packageMapProvider.packageMaps[subProjectB])); | 633 subProjectB, equals(packageMapProvider.packageMaps[subProjectB])); |
| 577 } | 634 } |
| 578 | 635 |
| 579 void test_setRoots_addPackageRoot() { | |
| 580 String packagePathFoo = '/package1/foo'; | |
| 581 String packageRootPath = '/package2/foo'; | |
| 582 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | |
| 583 packageMapProvider.packageMap = {'foo': [packageFolder]}; | |
| 584 List<String> includedPaths = <String>[projPath]; | |
| 585 List<String> excludedPaths = <String>[]; | |
| 586 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | |
| 587 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | |
| 588 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | |
| 589 projPath: packageRootPath | |
| 590 }); | |
| 591 _checkPackageRoot(projPath, equals(packageRootPath)); | |
| 592 } | |
| 593 | |
| 594 void test_setRoots_changePackageRoot() { | |
| 595 String packageRootPath1 = '/package1'; | |
| 596 String packageRootPath2 = '/package2'; | |
| 597 List<String> includedPaths = <String>[projPath]; | |
| 598 List<String> excludedPaths = <String>[]; | |
| 599 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | |
| 600 projPath: packageRootPath1 | |
| 601 }); | |
| 602 _checkPackageRoot(projPath, equals(packageRootPath1)); | |
| 603 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | |
| 604 projPath: packageRootPath2 | |
| 605 }); | |
| 606 _checkPackageRoot(projPath, equals(packageRootPath2)); | |
| 607 } | |
| 608 | |
| 609 void test_setRoots_exclude_newRoot_withExcludedFile() { | 636 void test_setRoots_exclude_newRoot_withExcludedFile() { |
| 610 // prepare paths | 637 // prepare paths |
| 611 String project = '/project'; | 638 String project = '/project'; |
| 612 String file1 = '$project/file1.dart'; | 639 String file1 = '$project/file1.dart'; |
| 613 String file2 = '$project/file2.dart'; | 640 String file2 = '$project/file2.dart'; |
| 614 // create files | 641 // create files |
| 615 resourceProvider.newFile(file1, '// 1'); | 642 resourceProvider.newFile(file1, '// 1'); |
| 616 resourceProvider.newFile(file2, '// 2'); | 643 resourceProvider.newFile(file2, '// 2'); |
| 617 // set roots | 644 // set roots |
| 618 manager.setRoots(<String>[project], <String>[file1], <String, String>{}); | 645 manager.setRoots(<String>[project], <String>[file1], <String, String>{}); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 // exclude "bbb/" | 750 // exclude "bbb/" |
| 724 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); | 751 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); |
| 725 callbacks.assertContextPaths([project]); | 752 callbacks.assertContextPaths([project]); |
| 726 callbacks.assertContextFiles(project, [fileA]); | 753 callbacks.assertContextFiles(project, [fileA]); |
| 727 // stop excluding "bbb/" | 754 // stop excluding "bbb/" |
| 728 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 755 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| 729 callbacks.assertContextPaths([project]); | 756 callbacks.assertContextPaths([project]); |
| 730 callbacks.assertContextFiles(project, [fileA, fileB]); | 757 callbacks.assertContextFiles(project, [fileA, fileB]); |
| 731 } | 758 } |
| 732 | 759 |
| 733 void test_setRoots_newFolderWithPackageRoot() { | |
| 734 String packageRootPath = '/package'; | |
| 735 manager.setRoots(<String>[projPath], <String>[], <String, String>{ | |
| 736 projPath: packageRootPath | |
| 737 }); | |
| 738 _checkPackageRoot(projPath, equals(packageRootPath)); | |
| 739 } | |
| 740 | |
| 741 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { | 760 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { |
| 742 String packagePath = '/package/foo'; | 761 String packagePath = '/package/foo'; |
| 743 Folder packageFolder = resourceProvider.newFolder(packagePath); | 762 Folder packageFolder = resourceProvider.newFolder(packagePath); |
| 744 packageMapProvider.packageMap = {'foo': [packageFolder]}; | 763 packageMapProvider.packageMap = {'foo': [packageFolder]}; |
| 745 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 764 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 746 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 765 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
| 747 } | 766 } |
| 748 | 767 |
| 749 void test_setRoots_packageResolver() { | 768 void test_setRoots_packageResolver() { |
| 750 Uri uri = Uri.parse('package:foo/foo.dart'); | 769 Uri uri = Uri.parse('package:foo/foo.dart'); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 callbacks.assertContextFiles(projectB, [projectB_file]); | 882 callbacks.assertContextFiles(projectB, [projectB_file]); |
| 864 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 883 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
| 865 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); | 884 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); |
| 866 // remove "projectB" | 885 // remove "projectB" |
| 867 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); | 886 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); |
| 868 callbacks.assertContextPaths([projectA, subProjectA]); | 887 callbacks.assertContextPaths([projectA, subProjectA]); |
| 869 callbacks.assertContextFiles(projectA, [projectA_file]); | 888 callbacks.assertContextFiles(projectA, [projectA_file]); |
| 870 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 889 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
| 871 } | 890 } |
| 872 | 891 |
| 873 void test_setRoots_removePackageRoot() { | |
| 874 String packagePathFoo = '/package1/foo'; | |
| 875 String packageRootPath = '/package2/foo'; | |
| 876 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | |
| 877 packageMapProvider.packageMap = {'foo': [packageFolder]}; | |
| 878 List<String> includedPaths = <String>[projPath]; | |
| 879 List<String> excludedPaths = <String>[]; | |
| 880 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | |
| 881 projPath: packageRootPath | |
| 882 }); | |
| 883 _checkPackageRoot(projPath, equals(packageRootPath)); | |
| 884 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | |
| 885 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | |
| 886 } | |
| 887 | |
| 888 test_watch_addDummyLink() { | 892 test_watch_addDummyLink() { |
| 889 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 893 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 890 // empty folder initially | 894 // empty folder initially |
| 891 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 895 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
| 892 expect(filePaths, isEmpty); | 896 expect(filePaths, isEmpty); |
| 893 // add link | 897 // add link |
| 894 String filePath = posix.join(projPath, 'foo.dart'); | 898 String filePath = posix.join(projPath, 'foo.dart'); |
| 895 resourceProvider.newDummyLink(filePath); | 899 resourceProvider.newDummyLink(filePath); |
| 896 // the link was ignored | 900 // the link was ignored |
| 897 return pumpEventQueue().then((_) { | 901 return pumpEventQueue().then((_) { |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1601 class TestUriResolver extends UriResolver { | 1605 class TestUriResolver extends UriResolver { |
| 1602 Map<Uri, Source> uriMap; | 1606 Map<Uri, Source> uriMap; |
| 1603 | 1607 |
| 1604 TestUriResolver(this.uriMap); | 1608 TestUriResolver(this.uriMap); |
| 1605 | 1609 |
| 1606 @override | 1610 @override |
| 1607 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 1611 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 1608 return uriMap[uri]; | 1612 return uriMap[uri]; |
| 1609 } | 1613 } |
| 1610 } | 1614 } |
| OLD | NEW |