@@ -25,15 +25,13 @@ final class FormattingTests: XCTestCase {
2525 let testClient = try await TestSourceKitLSPClient ( )
2626 let uri = DocumentURI ( for: . swift)
2727
28- let positions = testClient. openDocument (
29- """
28+ let source = """
3029 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)
3735
3836 let response = try await testClient. send (
3937 DocumentFormattingRequest (
@@ -43,14 +41,18 @@ final class FormattingTests: XCTestCase {
4341 )
4442
4543 let edits = try XCTUnwrap ( response)
44+ let formattedSource = apply ( edits: edits, to: source)
45+
46+ XCTAssert ( edits. allSatisfy { $0. newText. allSatisfy ( \. isWhitespace) } )
4647 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+ """
5456 )
5557 }
5658
@@ -217,15 +219,13 @@ final class FormattingTests: XCTestCase {
217219 let testClient = try await TestSourceKitLSPClient ( )
218220 let uri = DocumentURI ( for: . swift)
219221
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() {}
224225 }
225226
226- """ ,
227- uri: uri
228- )
227+ """
228+ testClient. openDocument ( source, uri: uri)
229229
230230 let response = try await testClient. send (
231231 DocumentFormattingRequest (
@@ -235,42 +235,44 @@ final class FormattingTests: XCTestCase {
235235 )
236236
237237 let edits = try XCTUnwrap ( response)
238+ let formattedSource = apply ( edits: edits, to: source)
239+
238240 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+ """
244248 )
245249 }
246250
247251 func testMultiLineStringInsertion( ) async throws {
248252 let testClient = try await TestSourceKitLSPClient ( )
249253 let uri = DocumentURI ( for: . swift)
250254
251- let positions = testClient. openDocument (
252- #"""
255+ let source = #"""
253256 _ = [
254257 Node(
255258 documentation: """
256- 1️⃣A
257- 2️⃣B
258- 3️⃣C
259- 4️⃣ """,
259+ A
260+ B
261+ C
262+ """,
260263 children: [
261264 Child(
262265 documentation: """
263- 5️⃣A
264- 6️⃣ 7️⃣ \#( " " )
265- 8️⃣ 9️⃣ 🔟 """
266+ A
267+ \#( " " )
268+ """
266269 )
267270 ]
268271 )
269272 ]
270273
271- """# ,
272- uri: uri
273- )
274+ """#
275+ testClient. openDocument ( source, uri: uri)
274276
275277 let response = try await testClient. send (
276278 DocumentFormattingRequest (
@@ -280,18 +282,31 @@ final class FormattingTests: XCTestCase {
280282 )
281283
282284 let edits = try XCTUnwrap ( response)
285+ let formattedSource = apply ( edits: edits, to: source)
286+
287+ XCTAssert ( edits. allSatisfy { $0. newText. allSatisfy ( \. isWhitespace) } )
283288 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+ )
294307 ]
308+
309+ """#
295310 )
296311 }
297312
0 commit comments