Index: pkg/analysis_server/test/services/correction/fix_test.dart |
diff --git a/pkg/analysis_server/test/services/correction/fix_test.dart b/pkg/analysis_server/test/services/correction/fix_test.dart |
index f50c8866516f27a5554b7d8fdd7dce69b7790f0b..ebfa13f5385662d6b4cb76e1f197f9b56bbeecc1 100644 |
--- a/pkg/analysis_server/test/services/correction/fix_test.dart |
+++ b/pkg/analysis_server/test/services/correction/fix_test.dart |
@@ -856,20 +856,10 @@ main() { |
} |
void test_importLibraryPackage_withType() { |
- provider.newFile('/packages/my_pkg/lib/my_lib.dart', ''' |
+ _configureMyPkg(''' |
library my_lib; |
class Test {} |
'''); |
- { |
- Folder myPkgFolder = provider.getResource('/packages/my_pkg/lib'); |
- UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
- 'my_pkg': [myPkgFolder] |
- }); |
- context.sourceFactory = new SourceFactory( |
- [AbstractContextTest.SDK_RESOLVER, resourceResolver, pkgResolver]); |
- } |
- // force 'my_pkg' resolution |
- addSource('/tmp/other.dart', "import 'package:my_pkg/my_lib.dart';"); |
// try to find a fix |
_indexTestUnit(''' |
main() { |
@@ -1286,6 +1276,29 @@ main() { |
'''); |
} |
+ void test_replaceImportUri_inProject() { |
+ testFile = '/project/bin/test.dart'; |
+ addSource('/project/foo/bar/lib.dart', ''); |
+ _indexTestUnit(''' |
+import 'no/matter/lib.dart'; |
+'''); |
+ performAllAnalysisTasks(); |
+ assertHasFix(FixKind.REPLACE_IMPORT_URI, ''' |
+import '../foo/bar/lib.dart'; |
+'''); |
+ } |
+ |
+ void test_replaceImportUri_package() { |
+ _configureMyPkg(''); |
+ _indexTestUnit(''' |
+import 'no/matter/my_lib.dart'; |
+'''); |
+ performAllAnalysisTasks(); |
+ assertHasFix(FixKind.REPLACE_IMPORT_URI, ''' |
+import 'package:my_pkg/my_lib.dart'; |
+'''); |
+ } |
+ |
void test_replaceWithConstInstanceCreation() { |
_indexTestUnit(''' |
class A { |
@@ -1847,6 +1860,23 @@ main() { |
} |
} |
+ /** |
+ * Configures the [SourceFactory] to have the `my_pkg` package in |
+ * `/packages/my_pkg/lib` folder. |
+ */ |
+ void _configureMyPkg(String myLibCode) { |
+ provider.newFile('/packages/my_pkg/lib/my_lib.dart', myLibCode); |
+ // configure SourceFactory |
+ Folder myPkgFolder = provider.getResource('/packages/my_pkg/lib'); |
+ UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
+ 'my_pkg': [myPkgFolder] |
+ }); |
+ context.sourceFactory = new SourceFactory( |
+ [AbstractContextTest.SDK_RESOLVER, resourceResolver, pkgResolver]); |
+ // force 'my_pkg' resolution |
+ addSource('/tmp/other.dart', "import 'package:my_pkg/my_lib.dart';"); |
+ } |
+ |
AnalysisError _findErrorToFix() { |
List<AnalysisError> errors = context.computeErrors(testSource); |
expect( |