Skip to content

Commit fa2f490

Browse files
kallentuCommit Queue
authored andcommitted
[analysis_server] Dot shorthands: Selection range tests.
Testing that selection range still works with the new dot shorthands ASTs. Bug: #59836 Change-Id: I2f444998943b50c4976f3e905f21a50140ebba74 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433420 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Kallen Tu <[email protected]>
1 parent bc4e201 commit fa2f490

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed

pkg/analysis_server/test/lsp/selection_range_test.dart

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,107 @@ void main() {
2222
/// test/src/computer/selection_range_computer_test.dart
2323
@reflectiveTest
2424
class SelectionRangeTest extends AbstractLspAnalysisServerTest {
25+
Future<void> test_dotShorthand_constructorInvocation() async {
26+
var code = TestCode.parse('''
27+
class A {}
28+
void f() {
29+
A a = .^new();
30+
}
31+
''');
32+
33+
await initialize();
34+
await openFile(mainFileUri, code.code);
35+
var lineInfo = LineInfo.fromContent(code.code);
36+
var regions = await getSelectionRanges(mainFileUri, [
37+
code.position.position,
38+
]);
39+
expect(regions!.length, equals(1));
40+
var regionTexts =
41+
_getSelectionRangeText(lineInfo, code.code, regions.first).toList();
42+
43+
expect(
44+
regionTexts,
45+
equals([
46+
'new',
47+
'.new()',
48+
'a = .new()',
49+
'A a = .new()',
50+
'A a = .new();',
51+
'{\n A a = .new();\n}',
52+
'() {\n A a = .new();\n}',
53+
'void f() {\n A a = .new();\n}',
54+
]),
55+
);
56+
}
57+
58+
Future<void> test_dotShorthand_methodInvocation() async {
59+
var code = TestCode.parse('''
60+
class A {
61+
static A method() => A();
62+
}
63+
void f() {
64+
A a = .me^thod();
65+
}
66+
''');
67+
68+
await initialize();
69+
await openFile(mainFileUri, code.code);
70+
var lineInfo = LineInfo.fromContent(code.code);
71+
var regions = await getSelectionRanges(mainFileUri, [
72+
code.position.position,
73+
]);
74+
expect(regions!.length, equals(1));
75+
var regionTexts =
76+
_getSelectionRangeText(lineInfo, code.code, regions.first).toList();
77+
78+
expect(
79+
regionTexts,
80+
equals([
81+
'method',
82+
'.method()',
83+
'a = .method()',
84+
'A a = .method()',
85+
'A a = .method();',
86+
'{\n A a = .method();\n}',
87+
'() {\n A a = .method();\n}',
88+
'void f() {\n A a = .method();\n}',
89+
]),
90+
);
91+
}
92+
93+
Future<void> test_dotShorthand_propertyAccess() async {
94+
var code = TestCode.parse('''
95+
enum A { a }
96+
void f() {
97+
A a = .^a;
98+
}
99+
''');
100+
101+
await initialize();
102+
await openFile(mainFileUri, code.code);
103+
var lineInfo = LineInfo.fromContent(code.code);
104+
var regions = await getSelectionRanges(mainFileUri, [
105+
code.position.position,
106+
]);
107+
expect(regions!.length, equals(1));
108+
var regionTexts =
109+
_getSelectionRangeText(lineInfo, code.code, regions.first).toList();
110+
111+
expect(
112+
regionTexts,
113+
equals([
114+
'a',
115+
'.a',
116+
'a = .a',
117+
'A a = .a',
118+
'A a = .a;',
119+
'{\n A a = .a;\n}',
120+
'() {\n A a = .a;\n}',
121+
'void f() {\n A a = .a;\n}',
122+
]),
123+
);
124+
}
125+
25126
Future<void> test_multiple() async {
26127
var content = '''
27128
class Foo {

pkg/analysis_server/test/src/computer/selection_range_computer_test.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,27 @@ final foo = Foo("^test");
164164
]);
165165
}
166166

167+
Future<void> test_constructorCall_dotShorthand() async {
168+
var content = '''
169+
class A {}
170+
void f() {
171+
A a = .^new();
172+
}
173+
''';
174+
175+
var regions = await _computeSelectionRanges(content);
176+
_expectRegions(regions, [
177+
'new',
178+
'.new()',
179+
'a = .new()',
180+
'A a = .new()',
181+
'A a = .new();',
182+
'{\n A a = .new();\n}',
183+
'() {\n A a = .new();\n}',
184+
'void f() {\n A a = .new();\n}',
185+
]);
186+
}
187+
167188
Future<void> test_extensionType() async {
168189
var content = '''
169190
extension type E<T>(int it) {
@@ -265,6 +286,29 @@ augment class Foo {
265286
]);
266287
}
267288

289+
Future<void> test_method_dotShorthand() async {
290+
var content = '''
291+
class A {
292+
static A method() => A();
293+
}
294+
void f() {
295+
A a = .me^thod();
296+
}
297+
''';
298+
299+
var regions = await _computeSelectionRanges(content);
300+
_expectRegions(regions, [
301+
'method',
302+
'.method()',
303+
'a = .method()',
304+
'A a = .method()',
305+
'A a = .method();',
306+
'{\n A a = .method();\n}',
307+
'() {\n A a = .method();\n}',
308+
'void f() {\n A a = .method();\n}',
309+
]);
310+
}
311+
268312
Future<void> test_method_withNullAwareElements_inList() async {
269313
var content = '''
270314
class Foo<T> {
@@ -484,6 +528,27 @@ class Circle {
484528
]);
485529
}
486530

531+
Future<void> test_propertyAccess_dotShorthand() async {
532+
var content = '''
533+
enum A { a }
534+
void f() {
535+
A a = .^a;
536+
}
537+
''';
538+
539+
var regions = await _computeSelectionRanges(content);
540+
_expectRegions(regions, [
541+
'a',
542+
'.a',
543+
'a = .a',
544+
'A a = .a',
545+
'A a = .a;',
546+
'{\n A a = .a;\n}',
547+
'() {\n A a = .a;\n}',
548+
'void f() {\n A a = .a;\n}',
549+
]);
550+
}
551+
487552
Future<void> test_topLevelFunction() async {
488553
var content = '''
489554
void a(String b) {

0 commit comments

Comments
 (0)