Skip to content

Commit 60c0933

Browse files
pqCommit Queue
authored and
Commit Queue
committed
[wildcards] completion tests
See: #56361 Change-Id: Ib69a64b17a890c6cec0e1bddfd25f6fa7834b1cb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378620 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent cbac320 commit 60c0933

File tree

2 files changed

+198
-0
lines changed

2 files changed

+198
-0
lines changed

pkg/analysis_server/test/services/completion/dart/declaration/test_all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'record_type_test.dart' as record_type;
2323
import 'type_member_test.dart' as type_member;
2424
import 'uri_test.dart' as uri;
2525
import 'variable_name_test.dart' as variable_name;
26+
import 'wildcard_variables_test.dart' as wildcard_variables;
2627

2728
/// Tests suggestions produced for various kinds of declarations.
2829
void main() {
@@ -46,5 +47,6 @@ void main() {
4647
type_member.main();
4748
uri.main();
4849
variable_name.main();
50+
wildcard_variables.main();
4951
});
5052
}
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:test_reflective_loader/test_reflective_loader.dart';
6+
7+
import '../../../../client/completion_driver_test.dart';
8+
9+
void main() {
10+
defineReflectiveSuite(() {
11+
defineReflectiveTests(WildcardFieldTest);
12+
defineReflectiveTests(WildcardImportPrefixTest);
13+
defineReflectiveTests(WildcardLocalVariableTest);
14+
defineReflectiveTests(WildcardParameterTest);
15+
defineReflectiveTests(WildcardTopLevelVariableTest);
16+
});
17+
}
18+
19+
/// Fields are binding so not technically wildcards but look just like them.
20+
@reflectiveTest
21+
class WildcardFieldTest extends AbstractCompletionDriverTest {
22+
@override
23+
Set<String> allowedIdentifiers = {'_'};
24+
25+
@override
26+
bool get includeKeywords => false;
27+
28+
Future<void> test_argumentList() async {
29+
await computeSuggestions('''
30+
void p(Object o) {}
31+
32+
class C {
33+
int _ = 0;
34+
void f() {
35+
p(^);
36+
}
37+
''');
38+
assertResponse(r'''
39+
suggestions
40+
_
41+
kind: field
42+
''');
43+
}
44+
45+
@FailingTest(reason: "the local '_' is shadowing the field")
46+
Future<void> test_argumentList_withLocal() async {
47+
await computeSuggestions('''
48+
void p(Object o) {}
49+
50+
class C {
51+
int _ = 0;
52+
void f() {
53+
var _ = 0;
54+
p(^);
55+
}
56+
''');
57+
assertResponse(r'''
58+
suggestions
59+
_
60+
kind: field
61+
''');
62+
}
63+
}
64+
65+
@reflectiveTest
66+
class WildcardImportPrefixTest extends AbstractCompletionDriverTest {
67+
@override
68+
Set<String> allowedIdentifiers = {'_', 'isBlank'};
69+
70+
@override
71+
bool get includeKeywords => false;
72+
73+
@FailingTest(reason: "'_' shouldn't be suggested")
74+
Future<void> test_argumentList() async {
75+
newFile('$testPackageLibPath/ext.dart', '''
76+
extension ES on String {
77+
bool get isBlank => false;
78+
}
79+
''');
80+
81+
await computeSuggestions('''
82+
import 'ext.dart' as _;
83+
84+
void p(Object o) {}
85+
86+
void f() {
87+
p(^);
88+
}
89+
''');
90+
// `_` should not appear.
91+
assertResponse('''
92+
suggestions
93+
''');
94+
}
95+
96+
Future<void> test_stringExtension_argumentList() async {
97+
newFile('$testPackageLibPath/ext.dart', '''
98+
extension ES on String {
99+
bool get isBlank => false;
100+
}
101+
''');
102+
103+
await computeSuggestions('''
104+
import 'ext.dart' as _;
105+
106+
void p(Object o) {}
107+
108+
void f() {
109+
p(''.^);
110+
}
111+
''');
112+
assertResponse('''
113+
suggestions
114+
isBlank
115+
kind: getter
116+
''');
117+
}
118+
}
119+
120+
@reflectiveTest
121+
class WildcardLocalVariableTest extends AbstractCompletionDriverTest {
122+
@override
123+
Set<String> allowedIdentifiers = {'_', 'b'};
124+
125+
@override
126+
bool get includeKeywords => false;
127+
128+
@FailingTest(reason: "'_' shouldn't be suggested")
129+
Future<void> test_argumentList() async {
130+
await computeSuggestions('''
131+
void p(Object o) {}
132+
133+
void f() {
134+
var _, b = 0;
135+
p(^);
136+
}
137+
''');
138+
assertResponse(r'''
139+
suggestions
140+
b
141+
kind: localVariable
142+
''');
143+
}
144+
}
145+
146+
@reflectiveTest
147+
class WildcardParameterTest extends AbstractCompletionDriverTest {
148+
@override
149+
Set<String> allowedIdentifiers = {'_', 'b'};
150+
151+
@override
152+
bool get includeKeywords => false;
153+
154+
Future<void> test_argumentList() async {
155+
await computeSuggestions('''
156+
void p(Object o) {}
157+
158+
void f(int _, int b) {
159+
p(^);
160+
}
161+
''');
162+
assertResponse('''
163+
suggestions
164+
b
165+
kind: parameter
166+
''');
167+
}
168+
}
169+
170+
/// Top level variables are binding so not technically wildcards but look just
171+
/// like them.
172+
@reflectiveTest
173+
class WildcardTopLevelVariableTest extends AbstractCompletionDriverTest {
174+
@override
175+
Set<String> allowedIdentifiers = {'_'};
176+
177+
@override
178+
bool get includeKeywords => false;
179+
180+
Future<void> test_argumentList() async {
181+
await computeSuggestions('''
182+
int _ = 0;
183+
184+
void p(Object o) {}
185+
186+
void f() {
187+
p(^);
188+
}
189+
''');
190+
assertResponse(r'''
191+
suggestions
192+
_
193+
kind: topLevelVariable
194+
''');
195+
}
196+
}

0 commit comments

Comments
 (0)