Issue 47842. Add a test for extension from other package.
Bug: https://github.com/dart-lang/sdk/issues/47842
Change-Id: Ib6c4d6791f823191ef39998a6e350c48915d52fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222243
Reviewed-by: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart b/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart
index 50411cb..a929b5e 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart
@@ -264,8 +264,7 @@
Future<void> addUnimportedFile(String filePath, String content) async {
addSource(filePath, content);
- var result = await session.getResolvedUnit(convertPath(filePath));
- extensionCache.cacheFromResult(result as ResolvedUnitResult);
+ await cacheExtensionsForFile(filePath);
}
Future<void> assertHasFix(String expected,
@@ -378,6 +377,11 @@
await _assertNoFixAllFix(error);
}
+ Future<void> cacheExtensionsForFile(String path) async {
+ var result = await session.getResolvedUnit(convertPath(path));
+ extensionCache.cacheFromResult(result as ResolvedUnitResult);
+ }
+
List<LinkedEditSuggestion> expectedSuggestions(
LinkedEditSuggestionKind kind, List<String> values) {
return values.map((value) {
diff --git a/pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart b/pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart
index a677f3a..be2de8f 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart
@@ -234,6 +234,48 @@
''');
}
+ @FailingTest(reason: 'We suggest importing src/b.dart')
+ Future<void> test_extension_otherPackage_exported_fromSrc() async {
+ var pkgRootPath = '/.pub-cache/aaa';
+
+ var a = newFile('$pkgRootPath/lib/a.dart', content: r'''
+export 'src/b.dart';
+''');
+
+ var b = newFile('$pkgRootPath/lib/src/b.dart', content: r'''
+extension IntExtension on int {
+ int get foo => 0;
+}
+''');
+
+ writeTestPackageConfig(
+ config: PackageConfigFileBuilder()
+ ..add(name: 'aaa', rootPath: pkgRootPath),
+ );
+
+ updateTestPubspecFile('''
+dependencies:
+ aaa: any
+''');
+
+ await cacheExtensionsForFile(a.path);
+ await cacheExtensionsForFile(b.path);
+
+ await resolveTestCode('''
+void f() {
+ 0.foo;
+}
+''');
+
+ await assertHasFix('''
+import 'package:aaa/a.dart';
+
+void f() {
+ 0.foo;
+}
+''');
+ }
+
Future<void> test_invalidUri_interpolation() async {
addSource('$testPackageLibPath/lib.dart', r'''
class Test {