@@ -21,6 +21,52 @@ void main() {
2121
2222@reflectiveTest
2323class SourceEditsTest extends AbstractSingleUnitTest with LspEditHelpersMixin {
24+ Future <void > test_format_version_defaultsToLatest () async {
25+ // Latest version should parse and format records.
26+ const startContent = '''
27+ var a = (1, 2);
28+ ''' ;
29+ const endContent = '''
30+ var a = (1, 2);
31+ ''' ;
32+ const expectedEdits = r'''
33+ Delete 1:5-1:8
34+ ''' ;
35+
36+ await _assertFormatEdits (startContent, endContent, expectedEdits);
37+ }
38+
39+ Future <void > test_format_version_languageVersionToken () async {
40+ // 2.19 will not parse/format records.
41+ const content = '''
42+ // @dart = 2.19
43+ var a = (1, 2);
44+ ''' ;
45+
46+ await _assertNoFormatEdits (content);
47+ }
48+
49+ Future <void > test_format_version_packageConfig () async {
50+ // 2.19 will not parse/format records.
51+ writeTestPackageConfig (languageVersion: '2.19' );
52+ const content = '''
53+ var a = (1, 2);
54+ ''' ;
55+
56+ await _assertNoFormatEdits (content);
57+ }
58+
59+ Future <void > test_format_version_versionToken_overridesPackageConfig () async {
60+ // 2.19 will not parse/format records.
61+ writeTestPackageConfig (languageVersion: '3.0' );
62+ const content = '''
63+ // @dart = 2.19
64+ var a = (1, 2);
65+ ''' ;
66+
67+ await _assertNoFormatEdits (content);
68+ }
69+
2470 Future <void > test_minimalEdits_comma_delete () async {
2571 const startContent = '''
2672void f(int a,) {}
@@ -572,6 +618,26 @@ void g() {
572618 );
573619 }
574620
621+ /// Assert that generating edits to format [start] match those described
622+ /// in [expected] and when applied, result in [end] .
623+ ///
624+ /// Edits will be automatically applied and verified. [expected] is to ensure
625+ /// the edits are minimal and we didn't accidentally produces a single edit
626+ /// replacing the entire file.
627+ Future <void > _assertFormatEdits (
628+ String start,
629+ String end,
630+ String expected, {
631+ String ? expectedFormatResult,
632+ Range ? range,
633+ }) async {
634+ await parseTestCode (start);
635+ var edits =
636+ generateEditsForFormatting (testParsedResult, range: range).result! ;
637+ expect (edits.toText ().trim (), expected.trim ());
638+ expect (applyTextEdits (start, edits), expectedFormatResult ?? end);
639+ }
640+
575641 /// Assert that computing minimal edits to convert [start] to [end] produces
576642 /// the set of edits described in [expected] .
577643 ///
@@ -595,6 +661,13 @@ void g() {
595661 expect (edits.toText ().trim (), expected);
596662 expect (applyTextEdits (start, edits.result), expectedFormatResult ?? end);
597663 }
664+
665+ /// Assert that formatting [content] produces no edits.
666+ Future <void > _assertNoFormatEdits (String content) async {
667+ await parseTestCode (content);
668+ var edits = generateEditsForFormatting (testParsedResult).result;
669+ expect (edits, isNull);
670+ }
598671}
599672
600673/// Helpers for building simple text representations of edits to verify that
0 commit comments