mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:49:17 +00:00
Tests to ensure that hovers work with macro generated code
Change-Id: I745ae1b61e3baf6343cff3eda31dfb8159f67579 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351700 Reviewed-by: Keerti Parthasarathy <keertip@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
47f0541c99
commit
a2574f28d3
|
@ -42,22 +42,25 @@ class A {}
|
|||
|
||||
@reflectiveTest
|
||||
class AnalysisHoverTest extends PubPackageAnalysisServerTest {
|
||||
Future<HoverInformation> prepareHover(String search) async {
|
||||
return (await prepareHoverOrNull(search))!;
|
||||
Future<HoverInformation> prepareHover(String search, {String? inFile}) async {
|
||||
return (await prepareHoverOrNull(search, inFile: inFile))!;
|
||||
}
|
||||
|
||||
Future<HoverInformation?> prepareHoverAt(int offset) async {
|
||||
Future<HoverInformation?> prepareHoverAt(int offset, {String? inFile}) async {
|
||||
await waitForTasksFinished();
|
||||
var request = AnalysisGetHoverParams(testFile.path, offset).toRequest('0');
|
||||
var request =
|
||||
AnalysisGetHoverParams(inFile ?? testFile.path, offset).toRequest('0');
|
||||
var response = await handleSuccessfulRequest(request);
|
||||
var result = AnalysisGetHoverResult.fromResponse(response);
|
||||
var hovers = result.hovers;
|
||||
return hovers.isNotEmpty ? hovers.first : null;
|
||||
}
|
||||
|
||||
Future<HoverInformation?> prepareHoverOrNull(String search) {
|
||||
var offset = findOffset(search);
|
||||
return prepareHoverAt(offset);
|
||||
Future<HoverInformation?> prepareHoverOrNull(String search,
|
||||
{String? inFile}) {
|
||||
var offset =
|
||||
offsetInFile(resourceProvider.getFile(inFile ?? testFile.path), search);
|
||||
return prepareHoverAt(offset, inFile: inFile);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -705,7 +708,7 @@ void f(A a) {
|
|||
''');
|
||||
var hover = await prepareHover('foo = 1');
|
||||
expect(hover.containingClassDescription, 'A');
|
||||
expect(hover.dartdoc, '''setting''');
|
||||
expect(hover.dartdoc, 'setting');
|
||||
expect(hover.elementDescription, 'set foo(int x)');
|
||||
expect(hover.elementKind, 'setter');
|
||||
}
|
||||
|
@ -819,6 +822,86 @@ void f(A a) {
|
|||
expect(hover.propagatedType, isNull);
|
||||
}
|
||||
|
||||
Future<void> test_constructorInvocation_macroGenerated_named() async {
|
||||
addMacros([declareInTypeMacro()]);
|
||||
newFile(testFilePath, '''
|
||||
import 'macros.dart';
|
||||
|
||||
@DeclareInType(' /// named\\n C.named();')
|
||||
class C {}
|
||||
|
||||
C f() => C.named(); //
|
||||
''');
|
||||
var hover = await prepareHover('med(); //');
|
||||
expect(hover.containingLibraryName, 'package:test/test.dart');
|
||||
expect(hover.containingLibraryPath, testFile.path);
|
||||
expect(hover.containingClassDescription, 'C');
|
||||
expect(hover.dartdoc, 'named');
|
||||
expect(hover.elementDescription, '(new) C C.named()');
|
||||
expect(hover.elementKind, 'constructor');
|
||||
expect(hover.staticType, isNull);
|
||||
}
|
||||
|
||||
Future<void>
|
||||
test_constructorInvocation_referenceFromAugmentation_default() async {
|
||||
var filePath = '$testPackageLibPath/a.dart';
|
||||
newFile(filePath, '''
|
||||
library augment 'test.dart';
|
||||
|
||||
augment class C {
|
||||
void m() {
|
||||
C();
|
||||
}
|
||||
}
|
||||
''');
|
||||
newFile(testFilePath, '''
|
||||
import augment 'a.dart';
|
||||
|
||||
class C {
|
||||
/// default
|
||||
C();
|
||||
}
|
||||
''');
|
||||
var hover = await prepareHover('C();', inFile: filePath);
|
||||
expect(hover.containingLibraryName, 'package:test/test.dart');
|
||||
expect(hover.containingLibraryPath, testFile.path);
|
||||
expect(hover.containingClassDescription, 'C');
|
||||
expect(hover.dartdoc, 'default');
|
||||
expect(hover.elementDescription, '(new) C C()');
|
||||
expect(hover.elementKind, 'constructor');
|
||||
expect(hover.staticType, isNull);
|
||||
}
|
||||
|
||||
Future<void>
|
||||
test_constructorInvocation_referenceFromAugmentation_named() async {
|
||||
var filePath = '$testPackageLibPath/a.dart';
|
||||
newFile(filePath, '''
|
||||
library augment 'test.dart';
|
||||
|
||||
augment class C {
|
||||
void m() {
|
||||
C.named();
|
||||
}
|
||||
}
|
||||
''');
|
||||
newFile(testFilePath, '''
|
||||
import augment 'a.dart';
|
||||
|
||||
class C {
|
||||
/// named
|
||||
C.named();
|
||||
}
|
||||
''');
|
||||
var hover = await prepareHover('C.named();', inFile: filePath);
|
||||
expect(hover.containingLibraryName, 'package:test/test.dart');
|
||||
expect(hover.containingLibraryPath, testFile.path);
|
||||
expect(hover.containingClassDescription, 'C');
|
||||
expect(hover.dartdoc, 'named');
|
||||
expect(hover.elementDescription, '(new) C C.named()');
|
||||
expect(hover.elementKind, 'constructor');
|
||||
expect(hover.staticType, isNull);
|
||||
}
|
||||
|
||||
Future<void> test_dartdoc_block() async {
|
||||
newFile(testFilePath, '''
|
||||
/**
|
||||
|
@ -1287,6 +1370,32 @@ void f() {
|
|||
expect(hover.propagatedType, null);
|
||||
}
|
||||
|
||||
Future<void>
|
||||
test_methodInvocation_macroGenerated_referenceToGenerated() async {
|
||||
addMacros([declareInTypeMacro()]);
|
||||
newFile(testFilePath, '''
|
||||
import 'macros.dart';
|
||||
|
||||
@DeclareInType(\'''
|
||||
/// method m
|
||||
void m() {}
|
||||
\''')
|
||||
class C {}
|
||||
|
||||
void f(C c) {
|
||||
c.m();
|
||||
}
|
||||
''');
|
||||
var hover = await prepareHover('m();');
|
||||
expect(hover.containingLibraryName, 'package:test/test.dart');
|
||||
expect(hover.containingLibraryPath, testFile.path);
|
||||
expect(hover.containingClassDescription, 'C');
|
||||
expect(hover.dartdoc, 'method m');
|
||||
expect(hover.elementDescription, 'void m()');
|
||||
expect(hover.elementKind, 'method');
|
||||
expect(hover.staticType, 'void Function()');
|
||||
}
|
||||
|
||||
Future<void> test_methodInvocation_recordType() async {
|
||||
newFile(testFilePath, '''
|
||||
class C {
|
||||
|
@ -1306,6 +1415,35 @@ void f(C c) {
|
|||
expect(hover.staticType, 'List<int> Function(int, (int, String))');
|
||||
}
|
||||
|
||||
Future<void> test_methodInvocation_referenceFromAugmentation() async {
|
||||
var filePath = '$testPackageLibPath/a.dart';
|
||||
newFile(filePath, '''
|
||||
library augment 'test.dart';
|
||||
|
||||
augment class C {
|
||||
void m(C c) {
|
||||
c.n();
|
||||
}
|
||||
}
|
||||
''');
|
||||
newFile(testFilePath, '''
|
||||
import augment 'a.dart';
|
||||
|
||||
class C {
|
||||
/// method n
|
||||
void n() {}
|
||||
}
|
||||
''');
|
||||
var hover = await prepareHover('n();', inFile: filePath);
|
||||
expect(hover.containingLibraryName, 'package:test/test.dart');
|
||||
expect(hover.containingLibraryPath, testFile.path);
|
||||
expect(hover.containingClassDescription, 'C');
|
||||
expect(hover.dartdoc, 'method n');
|
||||
expect(hover.elementDescription, 'void n()');
|
||||
expect(hover.elementKind, 'method');
|
||||
expect(hover.staticType, 'void Function()');
|
||||
}
|
||||
|
||||
Future<void> test_mixin_declaration() async {
|
||||
newFile(testFilePath, '''
|
||||
mixin A on B, C implements D, E {}
|
||||
|
|
Loading…
Reference in a new issue