@@ -25,15 +25,13 @@ final class FormattingTests: XCTestCase {
25
25
let testClient = try await TestSourceKitLSPClient ( )
26
26
let uri = DocumentURI ( for: . swift)
27
27
28
- let positions = testClient. openDocument (
29
- """
28
+ let source = """
30
29
struct S {
31
30
1️⃣var foo: 2️⃣ 3️⃣Int
32
31
4️⃣var bar: Int
33
32
}5️⃣
34
- """ ,
35
- uri: uri
36
- )
33
+ """
34
+ testClient. openDocument ( source, uri: uri)
37
35
38
36
let response = try await testClient. send (
39
37
DocumentFormattingRequest (
@@ -43,14 +41,19 @@ final class FormattingTests: XCTestCase {
43
41
)
44
42
45
43
let edits = try XCTUnwrap ( response)
44
+ let ( _, unmarkedSource) = extractMarkers ( source)
45
+ let formattedSource = unmarkedSource. applying ( edits)
46
+
46
47
XCTAssertEqual (
47
- edits,
48
- [
49
- TextEdit ( range: Range ( positions [ " 1️⃣ " ] ) , newText: " " ) ,
50
- TextEdit ( range: positions [ " 2️⃣ " ] ..< positions [ " 3️⃣ " ] , newText: " " ) ,
51
- TextEdit ( range: Range ( positions [ " 4️⃣ " ] ) , newText: " " ) ,
52
- TextEdit ( range: Range ( positions [ " 5️⃣ " ] ) , newText: " \n " ) ,
53
- ]
48
+ formattedSource,
49
+ """
50
+ struct S {
51
+ var foo: Int
52
+ var bar: Int
53
+ }
54
+
55
+
56
+ """
54
57
)
55
58
}
56
59
@@ -217,15 +220,13 @@ final class FormattingTests: XCTestCase {
217
220
let testClient = try await TestSourceKitLSPClient ( )
218
221
let uri = DocumentURI ( for: . swift)
219
222
220
- let positions = testClient. openDocument (
221
- """
223
+ let source = """
222
224
1️⃣public 2️⃣extension Example {
223
225
3️⃣func function() {}
224
226
}
225
227
226
- """ ,
227
- uri: uri
228
- )
228
+ """
229
+ testClient. openDocument ( source, uri: uri)
229
230
230
231
let response = try await testClient. send (
231
232
DocumentFormattingRequest (
@@ -235,21 +236,26 @@ final class FormattingTests: XCTestCase {
235
236
)
236
237
237
238
let edits = try XCTUnwrap ( response)
239
+ let ( _, unmarkedSource) = extractMarkers ( source)
240
+ let formattedSource = unmarkedSource. applying ( edits)
241
+
238
242
XCTAssertEqual (
239
- edits,
240
- [
241
- TextEdit ( range: positions [ " 1️⃣ " ] ..< positions [ " 2️⃣ " ] , newText: " " ) ,
242
- TextEdit ( range: Range ( positions [ " 3️⃣ " ] ) , newText: " public " ) ,
243
- ]
243
+ formattedSource,
244
+ """
245
+ extension Example {
246
+ public func function() {}
247
+ }
248
+
249
+
250
+ """
244
251
)
245
252
}
246
253
247
254
func testMultiLineStringInsertion( ) async throws {
248
255
let testClient = try await TestSourceKitLSPClient ( )
249
256
let uri = DocumentURI ( for: . swift)
250
257
251
- let positions = testClient. openDocument (
252
- #"""
258
+ let source = #"""
253
259
_ = [
254
260
Node(
255
261
documentation: """
@@ -268,9 +274,8 @@ final class FormattingTests: XCTestCase {
268
274
)
269
275
]
270
276
271
- """# ,
272
- uri: uri
273
- )
277
+ """#
278
+ testClient. openDocument ( source, uri: uri)
274
279
275
280
let response = try await testClient. send (
276
281
DocumentFormattingRequest (
@@ -280,18 +285,32 @@ final class FormattingTests: XCTestCase {
280
285
)
281
286
282
287
let edits = try XCTUnwrap ( response)
288
+ let ( _, unmarkedSource) = extractMarkers ( source)
289
+ let formattedSource = unmarkedSource. applying ( edits)
290
+
283
291
XCTAssertEqual (
284
- edits,
285
- [
286
- TextEdit ( range: Range ( positions [ " 1️⃣ " ] ) , newText: " " ) ,
287
- TextEdit ( range: Range ( positions [ " 2️⃣ " ] ) , newText: " " ) ,
288
- TextEdit ( range: Range ( positions [ " 3️⃣ " ] ) , newText: " " ) ,
289
- TextEdit ( range: Range ( positions [ " 4️⃣ " ] ) , newText: " " ) ,
290
- TextEdit ( range: Range ( positions [ " 5️⃣ " ] ) , newText: " " ) ,
291
- TextEdit ( range: Range ( positions [ " 6️⃣ " ] ) , newText: " \n " ) ,
292
- TextEdit ( range: positions [ " 7️⃣ " ] ..< positions [ " 8️⃣ " ] , newText: " " ) ,
293
- TextEdit ( range: positions [ " 9️⃣ " ] ..< positions [ " 🔟 " ] , newText: " " ) ,
292
+ formattedSource,
293
+ #"""
294
+ _ = [
295
+ Node(
296
+ documentation: """
297
+ A
298
+ B
299
+ C
300
+ """,
301
+ children: [
302
+ Child(
303
+ documentation: """
304
+ A
305
+
306
+ """
307
+ )
308
+ ]
309
+ )
294
310
]
311
+
312
+
313
+ """#
295
314
)
296
315
}
297
316
0 commit comments