Skip to content

Commit

Permalink
Add ExpressibleByStringInterpolation conformance to RouterPath
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Jul 5, 2024
1 parent e3160eb commit 1559d8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/Hummingbird/Router/RouterPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//

/// Split router path into components
public struct RouterPath: Sendable, ExpressibleByStringLiteral, CustomStringConvertible {
public struct RouterPath: Sendable, ExpressibleByStringLiteral, ExpressibleByStringInterpolation, CustomStringConvertible {
public struct Element: Equatable, Sendable, CustomStringConvertible {
package enum _Internal: Equatable, Sendable {
case path(Substring)
Expand Down Expand Up @@ -175,7 +175,7 @@ public struct RouterPath: Sendable, ExpressibleByStringLiteral, CustomStringConv
/// A textual representation of the RouterPath
public let description: String

internal init(components: [Element]) {
init(components: [Element]) {
self.components = components
self.description = "/\(self.components.map(\.description).joined(separator: "/"))"
}
Expand Down
15 changes: 15 additions & 0 deletions Tests/HummingbirdTests/RouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,21 @@ final class RouterTests: XCTestCase {
}
}
}

func testRouterPathStringInterpolation() async throws {
let route = "/test"
let router = Router()
router.get("\(route)") { _, _ in
return "TestString"
}
let app = Application(responder: router.buildResponder())
try await app.test(.router) { client in
try await client.execute(uri: "/test", method: .get) { response in
XCTAssertEqual(response.status, .ok)
XCTAssertEqual(response.headers[.contentLength], "10")
}
}
}
}

struct TestRouterContext2: RequestContext {
Expand Down

0 comments on commit 1559d8a

Please sign in to comment.