Skip to content

Commit ac8e50f

Browse files
committed
Simplify source formatting tests
1 parent b932f78 commit ac8e50f

File tree

4 files changed

+19
-90
lines changed

4 files changed

+19
-90
lines changed

Sources/SKTestSupport/String+applyingTextEdits.swift

Lines changed: 0 additions & 65 deletions
This file was deleted.

Tests/SourceKitLSPTests/FormattingTests.swift

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ final class FormattingTests: XCTestCase {
2727

2828
let source = """
2929
struct S {
30-
1️⃣var foo: 2️⃣ 3️⃣Int
31-
4️⃣var bar: Int
32-
}5️⃣
30+
var foo: Int
31+
var bar: Int
32+
}
3333
"""
3434
testClient.openDocument(source, uri: uri)
3535

@@ -41,8 +41,7 @@ final class FormattingTests: XCTestCase {
4141
)
4242

4343
let edits = try XCTUnwrap(response)
44-
let (_, unmarkedSource) = extractMarkers(source)
45-
let formattedSource = unmarkedSource.applying(edits)
44+
let formattedSource = apply(edits: edits, to: source)
4645

4746
XCTAssertEqual(
4847
formattedSource,
@@ -52,7 +51,6 @@ final class FormattingTests: XCTestCase {
5251
var bar: Int
5352
}
5453
55-
5654
"""
5755
)
5856
}
@@ -221,8 +219,8 @@ final class FormattingTests: XCTestCase {
221219
let uri = DocumentURI(for: .swift)
222220

223221
let source = """
224-
1️⃣public 2️⃣extension Example {
225-
3️⃣func function() {}
222+
public extension Example {
223+
func function() {}
226224
}
227225
228226
"""
@@ -236,8 +234,7 @@ final class FormattingTests: XCTestCase {
236234
)
237235

238236
let edits = try XCTUnwrap(response)
239-
let (_, unmarkedSource) = extractMarkers(source)
240-
let formattedSource = unmarkedSource.applying(edits)
237+
let formattedSource = apply(edits: edits, to: source)
241238

242239
XCTAssertEqual(
243240
formattedSource,
@@ -246,7 +243,6 @@ final class FormattingTests: XCTestCase {
246243
public func function() {}
247244
}
248245
249-
250246
"""
251247
)
252248
}
@@ -259,16 +255,16 @@ final class FormattingTests: XCTestCase {
259255
_ = [
260256
Node(
261257
documentation: """
262-
1️⃣A
263-
2️⃣B
264-
3️⃣C
265-
4️⃣""",
258+
A
259+
B
260+
C
261+
""",
266262
children: [
267263
Child(
268264
documentation: """
269-
5️⃣A
270-
6️⃣ 7️⃣\#("")
271-
8️⃣ 9️⃣ 🔟"""
265+
A
266+
\#("")
267+
"""
272268
)
273269
]
274270
)
@@ -285,8 +281,7 @@ final class FormattingTests: XCTestCase {
285281
)
286282

287283
let edits = try XCTUnwrap(response)
288-
let (_, unmarkedSource) = extractMarkers(source)
289-
let formattedSource = unmarkedSource.applying(edits)
284+
let formattedSource = apply(edits: edits, to: source)
290285

291286
XCTAssertEqual(
292287
formattedSource,
@@ -309,7 +304,6 @@ final class FormattingTests: XCTestCase {
309304
)
310305
]
311306
312-
313307
"""#
314308
)
315309
}

Tests/SourceKitLSPTests/OnTypeFormattingTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class OnTypeFormattingTests: XCTestCase {
5656

5757
let source = """
5858
func foo() {
59-
1️⃣if let SomeReallyLongVar = 2️⃣ 3️⃣Some.More.Stuff(), let a = 4️⃣ 5️⃣myfunc() 6️⃣{
59+
if let SomeReallyLongVar = Some.More.Stuff(), let a = myfunc() 1️⃣{
6060
}
6161
}
6262
"""
@@ -65,15 +65,15 @@ final class OnTypeFormattingTests: XCTestCase {
6565
let response = try await testClient.send(
6666
DocumentOnTypeFormattingRequest(
6767
textDocument: TextDocumentIdentifier(uri),
68-
position: positions["6️⃣"],
68+
position: positions["1️⃣"],
6969
ch: "{",
7070
options: FormattingOptions(tabSize: 4, insertSpaces: true)
7171
)
7272
)
7373

7474
let edits = try XCTUnwrap(response)
7575
let (_, unmarkedSource) = extractMarkers(source)
76-
let formattedSource = unmarkedSource.applying(edits)
76+
let formattedSource = apply(edits: edits, to: unmarkedSource)
7777

7878
XCTAssertEqual(
7979
formattedSource,

Tests/SourceKitLSPTests/RenameAssertions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SKTestSupport
1515
import SKUtilities
1616
import XCTest
1717

18-
private func apply(edits: [TextEdit], to source: String) -> String {
18+
internal func apply(edits: [TextEdit], to source: String) -> String {
1919
var lineTable = LineTable(source)
2020
let edits = edits.sorted(by: { $0.range.lowerBound < $1.range.lowerBound })
2121
for edit in edits.reversed() {

0 commit comments

Comments
 (0)