Skip to content

Commit

Permalink
[wildcards] hover tests
Browse files Browse the repository at this point in the history
See: #55681

Change-Id: I58630feb6e8b35b00d90d20c305a2f0ca9b37e4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382042
Commit-Queue: Phil Quitslund <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
pq authored and Commit Queue committed Aug 23, 2024
1 parent f8471fb commit 63ccfe8
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions pkg/analysis_server/test/lsp/hover_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ class HoverTest extends AbstractLspAnalysisServerTest {
expect(markup.value, matcher);
}

Future<void> assertNullHover(
String content, {
bool waitForAnalysis = false,
bool withOpenFile = true,
}) async {
var code = TestCode.parse(content);

var initialAnalysis = waitForAnalysis ? waitForAnalysisComplete() : null;
await initialize();
if (withOpenFile) {
await openFile(mainFileUri, code.code);
} else {
newFile(mainFilePath, code.code);
}
await initialAnalysis;
var hover = await getHover(mainFileUri, code.position.position);
expect(hover, isNull);
}

Future<void> assertPlainTextContents(String content, Matcher matcher) async {
setHoverContentFormat([MarkupKind.PlainText]);
var code = TestCode.parse(content);
Expand Down Expand Up @@ -181,6 +200,23 @@ List<MyEnum> get values
```
Type: `List<MyEnum>`
*package:test/main.dart*''';
await assertStringContents(content, equals(expected));
}

Future<void> test_field_underscore() async {
var content = '''
class A {
int _ = 1;
int f() => [!^_!];
}
''';
var expected = '''
```dart
int _
```
Type: `int`
*package:test/main.dart*''';
await assertStringContents(content, equals(expected));
}
Expand Down Expand Up @@ -240,6 +276,20 @@ Type: `String`''';
);
}

Future<void> test_localVariable_wildcard() async {
var content = '''
f() {
int [!^_!] = 0;
}
''';
var expected = '''
```dart
int _
```
Type: `int`''';
await assertStringContents(content, equals(expected));
}

Future<void> test_markdown_isFormattedForDisplay() async {
var content = '''
/// This is a string.
Expand Down Expand Up @@ -306,6 +356,23 @@ print();
contains('This is a method.'),
);

Future<void> test_method_underscore() async {
var content = '''
class A {
int _() => 1;
int f() => [!^_!]();
}
''';
var expected = '''
```dart
int _()
```
Type: `int Function()`
*package:test/main.dart*''';
await assertStringContents(content, equals(expected));
}

Future<void> test_noElement() async {
var code = TestCode.parse('''
String? abc;
Expand Down Expand Up @@ -346,6 +413,18 @@ Type: `String?`
await assertStringContents(content, equals(expectedHoverContent));
}

Future<void> test_parameter_wildcard() async {
var content = '''
f(int [!^_!]) { }
''';
var expected = '''
```dart
int _
```
Type: `int`''';
await assertStringContents(content, equals(expected));
}

Future<void> test_pattern_assignment_left() => assertStringContents(
'''
void f(String a, String b) {
Expand Down Expand Up @@ -807,6 +886,50 @@ This is a string.''';
await assertStringContents(content, equals(expected));
}

Future<void> test_topLevelFunction_underscore() async {
var content = '''
int _() => 1;
int f() => [!^_!]();
''';
var expected = '''
```dart
int _()
```
Type: `int Function()`
*package:test/main.dart*''';
await assertStringContents(content, equals(expected));
}

Future<void> test_topLevelVariable_underscore() async {
var content = '''
int _ = 1;
int f() => [!^_!];
''';
var expected = '''
```dart
int _
```
Type: `int`
*package:test/main.dart*''';
await assertStringContents(content, equals(expected));
}

Future<void> test_typeParameter() async {
var content = '''
class C<[!^T!]> {}
''';
await assertNullHover(content);
}

Future<void> test_typeParameter_wildcard() async {
var content = '''
class C<[!^_!]> {}
''';
await assertNullHover(content);
}

Future<void> test_unnamed_library_directive() async {
var content = '''
/// This is a string.
Expand Down

0 comments on commit 63ccfe8

Please sign in to comment.