Skip to content

Commit d2135e7

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[analyzer] Add tests for null-aware elements and navigation to definition
Part of #56989 Change-Id: I0249fb24540736934ebf4e536f5424b8b1e14ded Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398880 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]>
1 parent e7a7f44 commit d2135e7

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

pkg/analysis_server/test/analysis/get_navigation_test.dart

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,82 @@ final b = new Foo.named(); // 0
134134
expect(target.length, 5);
135135
}
136136

137+
Future<void> test_constructorInvocation_insideNullAwareElement_inList() async {
138+
addTestFile('''
139+
class Foo {
140+
Foo() {}
141+
}
142+
143+
final foo = [?Foo()];
144+
''');
145+
await waitForTasksFinished();
146+
147+
await _getNavigation(search: 'Foo()];');
148+
expect(regions, hasLength(1));
149+
expect(regions.first.targets, hasLength(1));
150+
var target = targets[regions.first.targets.first];
151+
expect(target.kind, ElementKind.CONSTRUCTOR);
152+
expect(target.offset, findOffset('Foo() {'));
153+
expect(target.length, 3);
154+
}
155+
156+
Future<void> test_constructorInvocation_insideNullAwareElement_inSet() async {
157+
addTestFile('''
158+
class Foo {
159+
Foo() {}
160+
}
161+
162+
final foo = {?Foo()};
163+
''');
164+
await waitForTasksFinished();
165+
166+
await _getNavigation(search: 'Foo()};');
167+
expect(regions, hasLength(1));
168+
expect(regions.first.targets, hasLength(1));
169+
var target = targets[regions.first.targets.first];
170+
expect(target.kind, ElementKind.CONSTRUCTOR);
171+
expect(target.offset, findOffset('Foo() {'));
172+
expect(target.length, 3);
173+
}
174+
175+
Future<void> test_constructorInvocation_insideNullAwareKey_inMap() async {
176+
addTestFile('''
177+
class Foo {
178+
Foo() {}
179+
}
180+
181+
final foo = {?Foo(): "value"};
182+
''');
183+
await waitForTasksFinished();
184+
185+
await _getNavigation(search: 'Foo():');
186+
expect(regions, hasLength(1));
187+
expect(regions.first.targets, hasLength(1));
188+
var target = targets[regions.first.targets.first];
189+
expect(target.kind, ElementKind.CONSTRUCTOR);
190+
expect(target.offset, findOffset('Foo() {'));
191+
expect(target.length, 3);
192+
}
193+
194+
Future<void> test_constructorInvocation_insideNullAwareValue_inMap() async {
195+
addTestFile('''
196+
class Foo {
197+
Foo() {}
198+
}
199+
200+
final foo = {"key": ?Foo()};
201+
''');
202+
await waitForTasksFinished();
203+
204+
await _getNavigation(search: 'Foo()};');
205+
expect(regions, hasLength(1));
206+
expect(regions.first.targets, hasLength(1));
207+
var target = targets[regions.first.targets.first];
208+
expect(target.kind, ElementKind.CONSTRUCTOR);
209+
expect(target.offset, findOffset('Foo() {'));
210+
expect(target.length, 3);
211+
}
212+
137213
Future<void> test_field_underscore() async {
138214
addTestFile('''
139215
class C {

0 commit comments

Comments
 (0)