Skip to content

Commit 1ac0685

Browse files
committed
Filter backticks in TestItem IDs
Test functions with backticks in their identifier should have them filtered out. This is a stopgap until swiftlang/swift-syntax#2576 is ready.
1 parent 8f8e50e commit 1ac0685

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

Sources/LanguageServerProtocol/SupportTypes/TestItem.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ public struct TestItem: ResponseType, Equatable {
6767
children: [TestItem],
6868
tags: [TestTag]
6969
) {
70-
self.id = id
71-
self.label = label
70+
// Filtering backticks is temporary until we can use
71+
// https://github.com/apple/swift-syntax/pull/2576
72+
self.id = id.filter { $0 != "`" }
73+
self.label = id == label ? self.id : label
7274
self.description = description
7375
self.sortText = sortText
7476
self.disabled = disabled

Tests/SourceKitLSPTests/DocumentTestDiscoveryTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,39 @@ final class DocumentTestDiscoveryTests: XCTestCase {
483483
)
484484
}
485485

486+
func testSwiftTestingTestWithBackticksInName() async throws {
487+
let testClient = try await TestSourceKitLSPClient()
488+
let uri = DocumentURI.for(.swift)
489+
490+
let positions = testClient.openDocument(
491+
"""
492+
import Testing
493+
494+
1️⃣@Test
495+
func `oneIsTwo`(`foo`: Int) {
496+
#expect(1 == 2)
497+
}2️⃣
498+
""",
499+
uri: uri
500+
)
501+
502+
let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
503+
XCTAssertEqual(
504+
tests,
505+
[
506+
TestItem(
507+
id: "oneIsTwo(foo:)",
508+
label: "oneIsTwo(foo:)",
509+
disabled: false,
510+
style: TestStyle.swiftTesting,
511+
location: Location(uri: uri, range: positions["1️⃣"]..<positions["2️⃣"]),
512+
children: [],
513+
tags: []
514+
)
515+
]
516+
)
517+
}
518+
486519
func testDisabledSwiftTestingTest() async throws {
487520
let testClient = try await TestSourceKitLSPClient()
488521
let uri = DocumentURI.for(.swift)

0 commit comments

Comments
 (0)