Skip to content

Commit

Permalink
[analysis_server] Add tests for formatter language version for legacy…
Browse files Browse the repository at this point in the history
… protocol

LSP already has equiv tests in `test/lsp/source_edits_test.dart`.

Fixes #56685

Change-Id: I70a836e4de9a50816f08382b81c0fc4a3f3e6fba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397540
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
DanTup authored and Commit Queue committed Dec 2, 2024
1 parent a8f5e64 commit 619c851
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions pkg/analysis_server/test/edit/format_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,48 @@ void f() {
expect(formatResult.selectionLength, equals(3));
}

/// Verify version 2.19 is passed to the formatter so it will not produce any
/// edits for code containing records (since it fails to parse).
Future<void> test_format_version_2_19() async {
writeTestPackageConfig(languageVersion: '2.19');
addTestFile('''
var a = (1, 2);
''');
await waitForTasksFinished();
await _expectFormatError(0, 3);
}

/// Verify version 3.0 is passed to the formatter so will produce edits for
/// code containing records.
Future<void> test_format_version_3_0() async {
addTestFile('''
var a = (1, 2);
''');
await waitForTasksFinished();
var formatResult = await _formatAt(0, 3);

expect(formatResult.edits, isNotNull);
expect(formatResult.edits, hasLength(1));
}

Future<void> test_format_withErrors() async {
addTestFile('''
void f() { int x =
''');
await waitForTasksFinished();
await _expectFormatError(0, 3);
}

Future<void> _expectFormatError(
int selectionOffset,
int selectionLength, {
int? lineLength,
}) async {
var request = EditFormatParams(
testFile.path,
0,
3,
selectionOffset,
selectionLength,
lineLength: lineLength,
).toRequest('0', clientUriConverter: server.uriConverter);
var response = await handleRequest(request);
expect(response, isResponseFailure('0'));
Expand Down

0 comments on commit 619c851

Please sign in to comment.