ForgejoKit/Tests/ForgejoKitTests/NormalizeServerURLTests.swift
Stefan Hausotte 897a8ebedd feat: initial commit
Intitial commit for ForgejoKit, a native Swift library to interact with
the Frogejo API
2026-02-28 20:25:57 +01:00

51 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")
}
}