Skip to content

Commit 6dac726

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Update some more tests to handle EOL normalization
This sets `useLineEndingsForPlatform=true` for basic completion tests that now pass, but leave it set to `false` in `AbstractCompletionDriverTest` for now because there are a large number of failures in other tests that use that base class due to hard-coded offsets. It also updates the format tests to support this (plus extracts some helpers to reduce the duplication). Change-Id: Id2a0323b4605761d05e30bee89f7dccebb1f48c4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451020 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 75ef4ef commit 6dac726

File tree

5 files changed

+109
-210
lines changed

5 files changed

+109
-210
lines changed

pkg/analysis_server/test/client/completion_driver_test.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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 'package:analyzer/src/test_utilities/platform.dart';
56
import 'package:analyzer_plugin/protocol/protocol_common.dart';
67
import 'package:meta/meta.dart';
78
import 'package:test/test.dart';
@@ -74,11 +75,11 @@ abstract class AbstractCompletionDriverTest
7475

7576
@override
7677
@protected
77-
Future<List<CompletionSuggestion>> addTestFile(
78-
String content, {
79-
int? offset,
80-
}) async {
81-
driver.addTestFile(content, offset: offset);
78+
Future<List<CompletionSuggestion>> addTestFile(String content) async {
79+
if (useLineEndingsForPlatform) {
80+
content = normalizeNewlinesForPlatform(content);
81+
}
82+
driver.addTestFile(content);
8283

8384
// Wait after adding the test file, this might affect diagnostics.
8485
await pumpEventQueue(times: 1000);

pkg/analysis_server/test/client/impl/completion_driver.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,9 @@ class CompletionDriver with ExpectMixin {
3636
server.serverChannel.notifications.listen(processNotification);
3737
}
3838

39-
void addTestFile(String content, {int? offset}) {
39+
void addTestFile(String content) {
4040
var code = TestCode.parse(content);
41-
42-
if (offset != null) {
43-
expect(code.positions, isEmpty, reason: 'cannot supply offset and ^');
44-
completionOffset = offset;
45-
} else {
46-
completionOffset = code.position.offset;
47-
}
41+
completionOffset = code.position.offset;
4842

4943
server.newFile(server.testFilePath, code.code);
5044
}

pkg/analysis_server/test/completion_test_support.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ abstract class CompletionTestCase extends AbstractCompletionDomainTest {
123123
await super.tearDown();
124124
}
125125
}
126+
127+
@override
128+
Future<void> setUp() async {
129+
// TODO(dantup): All tests that use this base class support normalization
130+
// however the base class of this (`AbstractCompletionDomainTest`) has a
131+
// lot of other tests classes that do not currently.
132+
useLineEndingsForPlatform = true;
133+
134+
await super.setUp();
135+
}
126136
}
127137

128138
/// A specification of the completion results expected at a given location.

0 commit comments

Comments
 (0)