@@ -18,6 +18,13 @@ void main() {
18
18
19
19
@reflectiveTest
20
20
class FormatTest extends AbstractLspAnalysisServerTest {
21
+ Future <void > expectFormattedContents (
22
+ Uri uri, String original, String expected) async {
23
+ final formatEdits = await formatDocument (uri.toString ());
24
+ final formattedContents = applyTextEdits (original, formatEdits);
25
+ expect (formattedContents, equals (expected));
26
+ }
27
+
21
28
Future <void > test_alreadyFormatted () async {
22
29
const contents = '''main() {
23
30
print('test');
@@ -149,6 +156,32 @@ class FormatTest extends AbstractLspAnalysisServerTest {
149
156
expect (formatEdits, isNull);
150
157
}
151
158
159
+ Future <void > test_lineLength () async {
160
+ const contents = '''
161
+ main() =>
162
+ print(
163
+ '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789'
164
+ );
165
+ ''' ;
166
+ final expectedDefault = '''main() => print(
167
+ '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789');\n ''' ;
168
+ final expectedLongLines =
169
+ '''main() => print('123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789');\n ''' ;
170
+
171
+ // Initialize with config support, supplying an empty config when requested.
172
+ await provideConfig (
173
+ () => initialize (
174
+ workspaceCapabilities: withDidChangeConfigurationDynamicRegistration (
175
+ withConfigurationSupport (emptyWorkspaceClientCapabilities))),
176
+ {}, // empty config
177
+ );
178
+ await openFile (mainFileUri, contents);
179
+
180
+ await expectFormattedContents (mainFileUri, contents, expectedDefault);
181
+ await updateConfig ({'lineLength' : 500 });
182
+ await expectFormattedContents (mainFileUri, contents, expectedLongLines);
183
+ }
184
+
152
185
Future <void > test_nonDartFile () async {
153
186
await initialize ();
154
187
await openFile (pubspecFileUri, simplePubspecContent);
@@ -201,11 +234,7 @@ class FormatTest extends AbstractLspAnalysisServerTest {
201
234
''' ;
202
235
await initialize ();
203
236
await openFile (mainFileUri, contents);
204
-
205
- final formatEdits = await formatDocument (mainFileUri.toString ());
206
- expect (formatEdits, isNotNull);
207
- final formattedContents = applyTextEdits (contents, formatEdits);
208
- expect (formattedContents, equals (expected));
237
+ await expectFormattedContents (mainFileUri, contents, expected);
209
238
}
210
239
211
240
Future <void > test_unopenFile () async {
@@ -222,10 +251,6 @@ class FormatTest extends AbstractLspAnalysisServerTest {
222
251
''' ;
223
252
newFile (mainFilePath, content: contents);
224
253
await initialize ();
225
-
226
- final formatEdits = await formatDocument (mainFileUri.toString ());
227
- expect (formatEdits, isNotNull);
228
- final formattedContents = applyTextEdits (contents, formatEdits);
229
- expect (formattedContents, equals (expected));
254
+ await expectFormattedContents (mainFileUri, contents, expected);
230
255
}
231
256
}
0 commit comments