Skip to content

Commit 5f9c5da

Browse files
kallentuCommit Queue
authored andcommitted
[analysis_server] Dot shorthands: Find element references tests.
Tests for Find References (Element) for dot shorthands. Bug: #59836 Change-Id: I7eee219022b974a8ab8a804e60a30964493a0a8f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432124 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Kallen Tu <[email protected]>
1 parent 4580a03 commit 5f9c5da

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

pkg/analysis_server/test/integration/search/find_element_references_test.dart

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,130 @@ foo(String str) {}
5959
expect(result.path.first.name, 'f');
6060
}
6161

62+
Future<void> test_findReferences_dotShorthand_invocation_class() async {
63+
var text = r'''
64+
class A {
65+
A.foo /* target */();
66+
}
67+
68+
void f() {
69+
A a = .foo();
70+
}
71+
''';
72+
73+
pathname = sourcePath('foo.dart');
74+
writeFile(pathname, text);
75+
await standardAnalysisSetup();
76+
await analysisFinished;
77+
78+
var results = (await _findElementReferences(text))!;
79+
expect(results, hasLength(1));
80+
var result = results.first;
81+
expect(result.location.file, pathname);
82+
expect(result.isPotential, isFalse);
83+
expect(result.kind.name, SearchResultKind.INVOCATION.name);
84+
expect(result.path.first.name, 'f');
85+
}
86+
87+
Future<void>
88+
test_findReferences_dotShorthand_invocation_extensionType() async {
89+
var text = r'''
90+
extension type A(int x) {
91+
static A foo /* target */() => A(1);
92+
}
93+
94+
void f() {
95+
A a = .foo();
96+
}
97+
''';
98+
99+
pathname = sourcePath('foo.dart');
100+
writeFile(pathname, text);
101+
await standardAnalysisSetup();
102+
await analysisFinished;
103+
104+
var results = (await _findElementReferences(text))!;
105+
expect(results, hasLength(1));
106+
var result = results.first;
107+
expect(result.location.file, pathname);
108+
expect(result.isPotential, isFalse);
109+
expect(result.kind.name, SearchResultKind.INVOCATION.name);
110+
expect(result.path.first.name, 'f');
111+
}
112+
113+
Future<void> test_findReferences_dotShorthand_read_class() async {
114+
var text = r'''
115+
class A {
116+
static A get getter /* target */ => A();
117+
}
118+
119+
void f() {
120+
A a = .getter;
121+
}
122+
''';
123+
124+
pathname = sourcePath('foo.dart');
125+
writeFile(pathname, text);
126+
await standardAnalysisSetup();
127+
await analysisFinished;
128+
129+
var results = (await _findElementReferences(text))!;
130+
expect(results, hasLength(1));
131+
var result = results.first;
132+
expect(result.location.file, pathname);
133+
expect(result.isPotential, isFalse);
134+
expect(result.kind.name, SearchResultKind.READ.name);
135+
expect(result.path.first.name, 'f');
136+
}
137+
138+
Future<void> test_findReferences_dotShorthand_read_enum() async {
139+
var text = r'''
140+
enum A { a /* target */ }
141+
142+
void f() {
143+
A a = .a;
144+
}
145+
''';
146+
147+
pathname = sourcePath('foo.dart');
148+
writeFile(pathname, text);
149+
await standardAnalysisSetup();
150+
await analysisFinished;
151+
152+
var results = (await _findElementReferences(text))!;
153+
expect(results, hasLength(1));
154+
var result = results.first;
155+
expect(result.location.file, pathname);
156+
expect(result.isPotential, isFalse);
157+
expect(result.kind.name, SearchResultKind.READ.name);
158+
expect(result.path.first.name, 'f');
159+
}
160+
161+
Future<void> test_findReferences_dotShorthand_read_extensionType() async {
162+
var text = r'''
163+
extension type A(int x) {
164+
static A get getter /* target */ => A(1);
165+
}
166+
167+
void f() {
168+
A a = .getter;
169+
}
170+
''';
171+
172+
pathname = sourcePath('foo.dart');
173+
writeFile(pathname, text);
174+
await standardAnalysisSetup();
175+
await analysisFinished;
176+
177+
var results = (await _findElementReferences(text))!;
178+
expect(results, hasLength(1));
179+
var result = results.first;
180+
expect(result.location.file, pathname);
181+
expect(result.isPotential, isFalse);
182+
expect(result.kind.name, SearchResultKind.READ.name);
183+
expect(result.path.first.name, 'f');
184+
}
185+
62186
Future<void> test_findReferences_inNullAware_listElement() async {
63187
var text = r'''
64188
List<int> f(int? foo) {

0 commit comments

Comments
 (0)