Skip to content

Commit 76bfec1

Browse files
committed
Issue 47842. Add a test for extension from other package.
Bug: #47842 Change-Id: Ib6c4d6791f823191ef39998a6e350c48915d52fa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222243 Reviewed-by: Phil Quitslund <[email protected]>
1 parent df48d2f commit 76bfec1

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ abstract class FixProcessorTest extends BaseFixProcessorTest {
264264

265265
Future<void> addUnimportedFile(String filePath, String content) async {
266266
addSource(filePath, content);
267-
var result = await session.getResolvedUnit(convertPath(filePath));
268-
extensionCache.cacheFromResult(result as ResolvedUnitResult);
267+
await cacheExtensionsForFile(filePath);
269268
}
270269

271270
Future<void> assertHasFix(String expected,
@@ -378,6 +377,11 @@ abstract class FixProcessorTest extends BaseFixProcessorTest {
378377
await _assertNoFixAllFix(error);
379378
}
380379

380+
Future<void> cacheExtensionsForFile(String path) async {
381+
var result = await session.getResolvedUnit(convertPath(path));
382+
extensionCache.cacheFromResult(result as ResolvedUnitResult);
383+
}
384+
381385
List<LinkedEditSuggestion> expectedSuggestions(
382386
LinkedEditSuggestionKind kind, List<String> values) {
383387
return values.map((value) {

pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,48 @@ void f(String s) {
234234
''');
235235
}
236236

237+
@FailingTest(reason: 'We suggest importing src/b.dart')
238+
Future<void> test_extension_otherPackage_exported_fromSrc() async {
239+
var pkgRootPath = '/.pub-cache/aaa';
240+
241+
var a = newFile('$pkgRootPath/lib/a.dart', content: r'''
242+
export 'src/b.dart';
243+
''');
244+
245+
var b = newFile('$pkgRootPath/lib/src/b.dart', content: r'''
246+
extension IntExtension on int {
247+
int get foo => 0;
248+
}
249+
''');
250+
251+
writeTestPackageConfig(
252+
config: PackageConfigFileBuilder()
253+
..add(name: 'aaa', rootPath: pkgRootPath),
254+
);
255+
256+
updateTestPubspecFile('''
257+
dependencies:
258+
aaa: any
259+
''');
260+
261+
await cacheExtensionsForFile(a.path);
262+
await cacheExtensionsForFile(b.path);
263+
264+
await resolveTestCode('''
265+
void f() {
266+
0.foo;
267+
}
268+
''');
269+
270+
await assertHasFix('''
271+
import 'package:aaa/a.dart';
272+
273+
void f() {
274+
0.foo;
275+
}
276+
''');
277+
}
278+
237279
Future<void> test_invalidUri_interpolation() async {
238280
addSource('$testPackageLibPath/lib.dart', r'''
239281
class Test {

0 commit comments

Comments
 (0)