Spaces:
Running
Running
| import Testing | |
| @testable import OpenClaw | |
| struct SettingsNetworkingHelpersTests { | |
| func parseHostPortParsesIPv4() { | |
| #expect(SettingsNetworkingHelpers.parseHostPort(from: "127.0.0.1:8080") == .init(host: "127.0.0.1", port: 8080)) | |
| } | |
| func parseHostPortParsesHostnameAndTrims() { | |
| #expect(SettingsNetworkingHelpers.parseHostPort(from: " example.com:80 \n") == .init( | |
| host: "example.com", | |
| port: 80)) | |
| } | |
| func parseHostPortParsesBracketedIPv6() { | |
| #expect( | |
| SettingsNetworkingHelpers.parseHostPort(from: "[2001:db8::1]:443") == | |
| .init(host: "2001:db8::1", port: 443)) | |
| } | |
| func parseHostPortRejectsMissingPort() { | |
| #expect(SettingsNetworkingHelpers.parseHostPort(from: "example.com") == nil) | |
| #expect(SettingsNetworkingHelpers.parseHostPort(from: "[2001:db8::1]") == nil) | |
| } | |
| func parseHostPortRejectsInvalidPort() { | |
| #expect(SettingsNetworkingHelpers.parseHostPort(from: "example.com:lol") == nil) | |
| #expect(SettingsNetworkingHelpers.parseHostPort(from: "[2001:db8::1]:lol") == nil) | |
| } | |
| func httpURLStringFormatsIPv4AndPort() { | |
| #expect(SettingsNetworkingHelpers | |
| .httpURLString(host: "127.0.0.1", port: 8080, fallback: "fallback") == "http://127.0.0.1:8080") | |
| } | |
| func httpURLStringBracketsIPv6() { | |
| #expect(SettingsNetworkingHelpers | |
| .httpURLString(host: "2001:db8::1", port: 8080, fallback: "fallback") == "http://[2001:db8::1]:8080") | |
| } | |
| func httpURLStringLeavesAlreadyBracketedIPv6() { | |
| #expect(SettingsNetworkingHelpers | |
| .httpURLString(host: "[2001:db8::1]", port: 8080, fallback: "fallback") == "http://[2001:db8::1]:8080") | |
| } | |
| func httpURLStringFallsBackWhenMissingHostOrPort() { | |
| #expect(SettingsNetworkingHelpers.httpURLString(host: nil, port: 80, fallback: "x") == "http://x") | |
| #expect(SettingsNetworkingHelpers.httpURLString(host: "example.com", port: nil, fallback: "y") == "http://y") | |
| } | |
| } | |