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 9bc4a4f4bc8bf7ee168990b0715d659c8711ebdc..c7ed0bb0b0a6a58bd26ca639fc3ef09a6e63fe66 100644 |
--- a/pkg/analysis_server/test/services/correction/fix_test.dart |
+++ b/pkg/analysis_server/test/services/correction/fix_test.dart |
@@ -152,8 +152,10 @@ bool test() { |
* 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); |
+ void _configureMyPkg(Map<String, String> pathToCode) { |
+ pathToCode.forEach((path, code) { |
+ provider.newFile('/packages/my_pkg/lib/$path', code); |
+ }); |
// configure SourceFactory |
Folder myPkgFolder = provider.getResource('/packages/my_pkg/lib'); |
UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
@@ -162,7 +164,11 @@ bool test() { |
context.sourceFactory = new SourceFactory( |
[AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); |
// force 'my_pkg' resolution |
- addSource('/tmp/other.dart', "import 'package:my_pkg/my_lib.dart';"); |
+ addSource( |
+ '/tmp/other.dart', |
+ pathToCode.keys |
+ .map((path) => "import 'package:my_pkg/$path';") |
+ .join('\n')); |
} |
AnalysisError _findErrorToFix() { |
@@ -3082,12 +3088,37 @@ Future main() async { |
'''); |
} |
- test_importLibraryPackage_withClass() async { |
- _configureMyPkg(''' |
-library my_lib; |
-class Test {} |
+ test_importLibraryPackage_preferDirectOverExport() async { |
+ _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); |
+ resolveTestUnit(''' |
+main() { |
+ Test test = null; |
+} |
+'''); |
+ performAllAnalysisTasks(); |
+ await assertHasFix( |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
+ ''' |
+import 'package:my_pkg/b.dart'; |
+ |
+main() { |
+ Test test = null; |
+} |
+'''); |
+ await assertHasFix( |
+ DartFixKind.IMPORT_LIBRARY_PROJECT2, |
+ ''' |
+import 'package:my_pkg/a.dart'; |
+ |
+main() { |
+ Test test = null; |
+} |
'''); |
- // try to find a fix |
+ } |
+ |
+ test_importLibraryPackage_preferPublicOverPrivate() async { |
+ _configureMyPkg( |
+ {'src/a.dart': 'class Test {}', 'b.dart': "export 'src/a.dart';"}); |
resolveTestUnit(''' |
main() { |
Test test = null; |
@@ -3095,9 +3126,18 @@ main() { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT2, |
''' |
-import 'package:my_pkg/my_lib.dart'; |
+import 'package:my_pkg/b.dart'; |
+ |
+main() { |
+ Test test = null; |
+} |
+'''); |
+ await assertHasFix( |
+ DartFixKind.IMPORT_LIBRARY_PROJECT3, |
+ ''' |
+import 'package:my_pkg/src/a.dart'; |
main() { |
Test test = null; |
@@ -3121,7 +3161,7 @@ main() { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
''' |
import 'lib.dart'; |
@@ -3155,7 +3195,7 @@ main () { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
''' |
import 'a.dart'; |
import 'b.dart' show Two; |
@@ -3181,7 +3221,7 @@ main() { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
''' |
import '../lib.dart'; |
@@ -3206,7 +3246,7 @@ main() { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
''' |
import '../lib/sub/folder/lib.dart'; |
@@ -3231,7 +3271,7 @@ main() { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
''' |
import 'lib.dart'; |
@@ -3255,7 +3295,7 @@ main() { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
''' |
import 'lib.dart'; |
@@ -3281,7 +3321,7 @@ class A { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
''' |
import 'lib.dart'; |
@@ -3308,7 +3348,7 @@ main() { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
''' |
import 'lib.dart'; |
@@ -3332,7 +3372,7 @@ main() { |
'''); |
performAllAnalysisTasks(); |
await assertHasFix( |
- DartFixKind.IMPORT_LIBRARY_PROJECT, |
+ DartFixKind.IMPORT_LIBRARY_PROJECT1, |
''' |
import 'lib.dart'; |
@@ -3538,7 +3578,7 @@ main() { |
} |
'''); |
performAllAnalysisTasks(); |
- await assertNoFix(DartFixKind.IMPORT_LIBRARY_PROJECT); |
+ await assertNoFix(DartFixKind.IMPORT_LIBRARY_PROJECT1); |
await assertHasFix( |
DartFixKind.IMPORT_LIBRARY_SHOW, |
''' |
@@ -3924,7 +3964,7 @@ import '../foo/bar/lib.dart'; |
} |
test_replaceImportUri_package() async { |
- _configureMyPkg(''); |
+ _configureMyPkg({'my_lib.dart': ''}); |
resolveTestUnit(''' |
import 'no/matter/my_lib.dart'; |
'''); |