From 619c8511abad83212936684fa09addae641f9dc1 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Mon, 2 Dec 2024 19:32:41 +0000 Subject: [PATCH] [analysis_server] Add tests for formatter language version for legacy protocol LSP already has equiv tests in `test/lsp/source_edits_test.dart`. Fixes https://github.com/dart-lang/sdk/issues/56685 Change-Id: I70a836e4de9a50816f08382b81c0fc4a3f3e6fba Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397540 Reviewed-by: Phil Quitslund Commit-Queue: Brian Wilkerson Reviewed-by: Brian Wilkerson --- .../test/edit/format_test.dart | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/pkg/analysis_server/test/edit/format_test.dart b/pkg/analysis_server/test/edit/format_test.dart index d84b2db8a798..01755a9ee120 100644 --- a/pkg/analysis_server/test/edit/format_test.dart +++ b/pkg/analysis_server/test/edit/format_test.dart @@ -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 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 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 test_format_withErrors() async { addTestFile(''' void f() { int x = '''); await waitForTasksFinished(); + await _expectFormatError(0, 3); + } + + Future _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'));