Skip to content

Commit 83c2f1c

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Removes assertHasAssistAt and assertNoAssistAt
Bug: #60234 Change-Id: Ic9d181bd4356ca1e9a11d6760cf025610a697d2a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421501 Reviewed-by: Samuel Rawlins <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 36b38d5 commit 83c2f1c

File tree

48 files changed

+1582
-1602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1582
-1602
lines changed

pkg/analysis_server/test/src/services/correction/assist/add_type_annotation_test.dart

Lines changed: 132 additions & 132 deletions
Large diffs are not rendered by default.

pkg/analysis_server/test/src/services/correction/assist/assign_to_local_variable_test.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ class AssignToLocalVariableTest extends AssistProcessorTest {
2525
await resolveTestCode('''
2626
void f() {
2727
var vvv;
28-
vvv = 42;
28+
^vvv = 42;
2929
}
3030
''');
31-
await assertNoAssistAt('vvv =');
31+
await assertNoAssist();
3232
}
3333

3434
Future<void> test_inClosure() async {
3535
await resolveTestCode(r'''
3636
void f() {
3737
print(() {
38-
12345;
38+
12^345;
3939
});
4040
}
4141
''');
42-
await assertHasAssistAt('345', '''
42+
await assertHasAssist('''
4343
void f() {
4444
print(() {
4545
var i = 12345;
@@ -52,11 +52,11 @@ void f() {
5252
await resolveTestCode('''
5353
void f() {
5454
List<int> bytes;
55-
readBytes();
55+
^readBytes();
5656
}
5757
List<int> readBytes() => <int>[];
5858
''');
59-
await assertHasAssistAt('readBytes();', '''
59+
await assertHasAssist('''
6060
void f() {
6161
List<int> bytes;
6262
var readBytes = readBytes();
@@ -77,21 +77,21 @@ List<int> readBytes() => <int>[];
7777
Future<void> test_invocationArgument() async {
7878
await resolveTestCode(r'''
7979
void f() {
80-
g(12345);
80+
g(12^345);
8181
}
8282
void g(p) {}
8383
''');
84-
await assertNoAssistAt('345');
84+
await assertNoAssist();
8585
}
8686

8787
Future<void> test_lint_prefer_final_locals() async {
8888
createAnalysisOptionsFile(lints: [LintNames.prefer_final_locals]);
8989
await resolveTestCode(r'''
9090
void f() {
91-
12345;
91+
12^345;
9292
}
9393
''');
94-
await assertHasAssistAt('345', '''
94+
await assertHasAssist('''
9595
void f() {
9696
final i = 12345;
9797
}
@@ -103,28 +103,28 @@ void f() {
103103
await resolveTestCode('''
104104
Future<void> _extractDataForSite() async {
105105
final Map<String, Object> data = {};
106-
final data['table'][] //marker
106+
final data['table'][^]
107107
}
108108
''');
109-
await assertNoAssistAt('] //marker');
109+
await assertNoAssist();
110110
}
111111

112112
Future<void> test_throw() async {
113113
await resolveTestCode('''
114114
void f() {
115-
throw 42;
115+
^throw 42;
116116
}
117117
''');
118-
await assertNoAssistAt('throw ');
118+
await assertNoAssist();
119119
}
120120

121121
Future<void> test_void() async {
122122
await resolveTestCode('''
123123
void f() {
124-
f();
124+
^f();
125125
}
126126
void g() {}
127127
''');
128-
await assertNoAssistAt('f();');
128+
await assertNoAssist();
129129
}
130130
}

pkg/analysis_server/test/src/services/correction/assist/assist_processor.dart

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:math';
6+
57
import 'package:analysis_server_plugin/edit/assist/assist.dart';
68
import 'package:analysis_server_plugin/edit/assist/dart_assist_context.dart';
79
import 'package:analysis_server_plugin/src/correction/assist_processor.dart';
@@ -38,21 +40,8 @@ abstract class AssistProcessorTest extends AbstractSingleUnitTest {
3840

3941
@override
4042
void addTestSource(String code) {
41-
code = normalizeSource(code);
42-
var parsedCode = TestCode.parse(code);
43-
code = parsedCode.code;
44-
if (parsedCode.positions.isNotEmpty) {
45-
_offset = parsedCode.position.offset;
46-
_length = 0;
47-
} else if (parsedCode.ranges.isNotEmpty) {
48-
var range = parsedCode.range.sourceRange;
49-
_offset = range.offset;
50-
_length = range.length;
51-
} else {
52-
_offset = 0;
53-
_length = 0;
54-
}
5543
super.addTestSource(code);
44+
_setPositionOrRange(0);
5645
}
5746

5847
void assertExitPosition({String? before, String? after}) {
@@ -79,7 +68,9 @@ abstract class AssistProcessorTest extends AbstractSingleUnitTest {
7968
Future<SourceChange> assertHasAssist(
8069
String expected, {
8170
Map<String, List<String>>? additionallyChangedFiles,
71+
int index = 0,
8272
}) async {
73+
_setPositionOrRange(index);
8374
if (useLineEndingsForPlatform) {
8475
expected = normalizeNewlinesForPlatform(expected);
8576
additionallyChangedFiles = additionallyChangedFiles?.map(
@@ -115,26 +106,6 @@ abstract class AssistProcessorTest extends AbstractSingleUnitTest {
115106
return _change;
116107
}
117108

118-
/// Asserts that there is an [Assist] of the given [kind] at the offset of the
119-
/// given [snippet] which produces the [expected] code when applied to [testCode].
120-
Future<void> assertHasAssistAt(
121-
String snippet,
122-
String expected, {
123-
int length = 0,
124-
}) async {
125-
expected = normalizeSource(expected);
126-
_offset = findOffset(snippet);
127-
_length = length;
128-
var assist = await _assertHasAssist();
129-
_change = assist.change;
130-
expect(_change.id, kind.id);
131-
// apply to "file"
132-
var fileEdits = _change.edits;
133-
expect(fileEdits, hasLength(1));
134-
_resultCode = SourceEdit.applySequence(testCode, _change.edits[0].edits);
135-
expect(_resultCode, expected);
136-
}
137-
138109
void assertLinkedGroup(
139110
int groupIndex,
140111
List<String> expectedStrings, [
@@ -149,20 +120,8 @@ abstract class AssistProcessorTest extends AbstractSingleUnitTest {
149120
}
150121

151122
/// Asserts that there is no [Assist] of the given [kind] at [_offset].
152-
Future<void> assertNoAssist() async {
153-
var assists = await _computeAssists();
154-
for (var assist in assists) {
155-
if (assist.kind == kind) {
156-
fail('Unexpected assist $kind in\n${assists.join('\n')}');
157-
}
158-
}
159-
}
160-
161-
/// Asserts that there is no [Assist] of the given [kind] at the offset of the
162-
/// given [snippet].
163-
Future<void> assertNoAssistAt(String snippet, {int length = 0}) async {
164-
_offset = findOffset(snippet);
165-
_length = length;
123+
Future<void> assertNoAssist([int index = 0]) async {
124+
_setPositionOrRange(index);
166125
var assists = await _computeAssists();
167126
for (var assist in assists) {
168127
if (assist.kind == kind) {
@@ -221,4 +180,24 @@ abstract class AssistProcessorTest extends AbstractSingleUnitTest {
221180
}
222181
return positions;
223182
}
183+
184+
void _setPositionOrRange(int index) {
185+
if (index < 0) {
186+
throw ArgumentError('Index must be non-negative.');
187+
}
188+
if (index >
189+
max(parsedTestCode.positions.length, parsedTestCode.ranges.length)) {
190+
throw ArgumentError('Index exceeds the number of positions and ranges.');
191+
}
192+
if (parsedTestCode.positions.isNotEmpty) {
193+
_offset = parsedTestCode.positions[index].offset;
194+
_length = 0;
195+
} else if (parsedTestCode.ranges.isNotEmpty) {
196+
var range = parsedTestCode.ranges[index].sourceRange;
197+
_offset = range.offset;
198+
_length = range.length;
199+
} else {
200+
throw ArgumentError('Test code must contain a position or range marker.');
201+
}
202+
}
224203
}

0 commit comments

Comments
 (0)