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