Skip to content

Commit

Permalink
Filter backticks in TestItem IDs
Browse files Browse the repository at this point in the history
Test functions with backticks in their identifier should have them
filtered out.

This is a stopgap until swiftlang/swift-syntax#2576 is ready.
  • Loading branch information
plemarquand committed May 1, 2024
1 parent 8f8e50e commit 1ac0685
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Sources/LanguageServerProtocol/SupportTypes/TestItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public struct TestItem: ResponseType, Equatable {
children: [TestItem],
tags: [TestTag]
) {
self.id = id
self.label = label
// Filtering backticks is temporary until we can use
// https://github.com/apple/swift-syntax/pull/2576
self.id = id.filter { $0 != "`" }
self.label = id == label ? self.id : label
self.description = description
self.sortText = sortText
self.disabled = disabled
Expand Down
33 changes: 33 additions & 0 deletions Tests/SourceKitLSPTests/DocumentTestDiscoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,39 @@ final class DocumentTestDiscoveryTests: XCTestCase {
)
}

func testSwiftTestingTestWithBackticksInName() async throws {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)

let positions = testClient.openDocument(
"""
import Testing
1️⃣@Test
func `oneIsTwo`(`foo`: Int) {
#expect(1 == 2)
}2️⃣
""",
uri: uri
)

let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
XCTAssertEqual(
tests,
[
TestItem(
id: "oneIsTwo(foo:)",
label: "oneIsTwo(foo:)",
disabled: false,
style: TestStyle.swiftTesting,
location: Location(uri: uri, range: positions["1️⃣"]..<positions["2️⃣"]),
children: [],
tags: []
)
]
)
}

func testDisabledSwiftTestingTest() async throws {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)
Expand Down

0 comments on commit 1ac0685

Please sign in to comment.