Skip to content

Commit 63ccfe8

Browse files
pqCommit Queue
authored and
Commit Queue
committed
[wildcards] hover tests
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]>
1 parent f8471fb commit 63ccfe8

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

pkg/analysis_server/test/lsp/hover_test.dart

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@ class HoverTest extends AbstractLspAnalysisServerTest {
8181
expect(markup.value, matcher);
8282
}
8383

84+
Future<void> assertNullHover(
85+
String content, {
86+
bool waitForAnalysis = false,
87+
bool withOpenFile = true,
88+
}) async {
89+
var code = TestCode.parse(content);
90+
91+
var initialAnalysis = waitForAnalysis ? waitForAnalysisComplete() : null;
92+
await initialize();
93+
if (withOpenFile) {
94+
await openFile(mainFileUri, code.code);
95+
} else {
96+
newFile(mainFilePath, code.code);
97+
}
98+
await initialAnalysis;
99+
var hover = await getHover(mainFileUri, code.position.position);
100+
expect(hover, isNull);
101+
}
102+
84103
Future<void> assertPlainTextContents(String content, Matcher matcher) async {
85104
setHoverContentFormat([MarkupKind.PlainText]);
86105
var code = TestCode.parse(content);
@@ -181,6 +200,23 @@ List<MyEnum> get values
181200
```
182201
Type: `List<MyEnum>`
183202
203+
*package:test/main.dart*''';
204+
await assertStringContents(content, equals(expected));
205+
}
206+
207+
Future<void> test_field_underscore() async {
208+
var content = '''
209+
class A {
210+
int _ = 1;
211+
int f() => [!^_!];
212+
}
213+
''';
214+
var expected = '''
215+
```dart
216+
int _
217+
```
218+
Type: `int`
219+
184220
*package:test/main.dart*''';
185221
await assertStringContents(content, equals(expected));
186222
}
@@ -240,6 +276,20 @@ Type: `String`''';
240276
);
241277
}
242278

279+
Future<void> test_localVariable_wildcard() async {
280+
var content = '''
281+
f() {
282+
int [!^_!] = 0;
283+
}
284+
''';
285+
var expected = '''
286+
```dart
287+
int _
288+
```
289+
Type: `int`''';
290+
await assertStringContents(content, equals(expected));
291+
}
292+
243293
Future<void> test_markdown_isFormattedForDisplay() async {
244294
var content = '''
245295
/// This is a string.
@@ -306,6 +356,23 @@ print();
306356
contains('This is a method.'),
307357
);
308358

359+
Future<void> test_method_underscore() async {
360+
var content = '''
361+
class A {
362+
int _() => 1;
363+
int f() => [!^_!]();
364+
}
365+
''';
366+
var expected = '''
367+
```dart
368+
int _()
369+
```
370+
Type: `int Function()`
371+
372+
*package:test/main.dart*''';
373+
await assertStringContents(content, equals(expected));
374+
}
375+
309376
Future<void> test_noElement() async {
310377
var code = TestCode.parse('''
311378
String? abc;
@@ -346,6 +413,18 @@ Type: `String?`
346413
await assertStringContents(content, equals(expectedHoverContent));
347414
}
348415

416+
Future<void> test_parameter_wildcard() async {
417+
var content = '''
418+
f(int [!^_!]) { }
419+
''';
420+
var expected = '''
421+
```dart
422+
int _
423+
```
424+
Type: `int`''';
425+
await assertStringContents(content, equals(expected));
426+
}
427+
349428
Future<void> test_pattern_assignment_left() => assertStringContents(
350429
'''
351430
void f(String a, String b) {
@@ -807,6 +886,50 @@ This is a string.''';
807886
await assertStringContents(content, equals(expected));
808887
}
809888

889+
Future<void> test_topLevelFunction_underscore() async {
890+
var content = '''
891+
int _() => 1;
892+
int f() => [!^_!]();
893+
''';
894+
var expected = '''
895+
```dart
896+
int _()
897+
```
898+
Type: `int Function()`
899+
900+
*package:test/main.dart*''';
901+
await assertStringContents(content, equals(expected));
902+
}
903+
904+
Future<void> test_topLevelVariable_underscore() async {
905+
var content = '''
906+
int _ = 1;
907+
int f() => [!^_!];
908+
''';
909+
var expected = '''
910+
```dart
911+
int _
912+
```
913+
Type: `int`
914+
915+
*package:test/main.dart*''';
916+
await assertStringContents(content, equals(expected));
917+
}
918+
919+
Future<void> test_typeParameter() async {
920+
var content = '''
921+
class C<[!^T!]> {}
922+
''';
923+
await assertNullHover(content);
924+
}
925+
926+
Future<void> test_typeParameter_wildcard() async {
927+
var content = '''
928+
class C<[!^_!]> {}
929+
''';
930+
await assertNullHover(content);
931+
}
932+
810933
Future<void> test_unnamed_library_directive() async {
811934
var content = '''
812935
/// This is a string.

0 commit comments

Comments
 (0)