mirror of
https://codeberg.org/secana/ForgejoKit.git
synced 2026-06-16 05:13:53 -07:00
52 lines
1.7 KiB
Swift
52 lines
1.7 KiB
Swift
|
|
import Foundation
|
||
|
|
import Testing
|
||
|
|
@testable import ForgejoKit
|
||
|
|
|
||
|
|
struct NormalizeServerURLTests {
|
||
|
|
|
||
|
|
@Test func stripsTrailingSlash() {
|
||
|
|
let result = ForgejoClient.normalizeServerURL("https://forgejo.example.com/")
|
||
|
|
#expect(result == "https://forgejo.example.com")
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func addsHttpsWhenNoScheme() {
|
||
|
|
let result = ForgejoClient.normalizeServerURL("forgejo.example.com")
|
||
|
|
#expect(result == "https://forgejo.example.com")
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func preservesHttpScheme() {
|
||
|
|
let result = ForgejoClient.normalizeServerURL("http://localhost:3000")
|
||
|
|
#expect(result == "http://localhost:3000")
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func preservesHttpsScheme() {
|
||
|
|
let result = ForgejoClient.normalizeServerURL("https://forgejo.example.com")
|
||
|
|
#expect(result == "https://forgejo.example.com")
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func trimsWhitespace() {
|
||
|
|
let result = ForgejoClient.normalizeServerURL(" https://forgejo.example.com ")
|
||
|
|
#expect(result == "https://forgejo.example.com")
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func handlesTrailingSlashAndWhitespace() {
|
||
|
|
let result = ForgejoClient.normalizeServerURL(" forgejo.example.com/ ")
|
||
|
|
#expect(result == "https://forgejo.example.com")
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func preservesPort() {
|
||
|
|
let result = ForgejoClient.normalizeServerURL("https://forgejo.example.com:3000")
|
||
|
|
#expect(result == "https://forgejo.example.com:3000")
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func preservesPath() {
|
||
|
|
let result = ForgejoClient.normalizeServerURL("https://example.com/forgejo")
|
||
|
|
#expect(result == "https://example.com/forgejo")
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func stripsMultipleTrailingSlashes() {
|
||
|
|
let result = ForgejoClient.normalizeServerURL("https://example.com///")
|
||
|
|
#expect(result == "https://example.com")
|
||
|
|
}
|
||
|
|
}
|