Revision control
Copy as Markdown
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
import XCTest
import Foundation
class URLExtensionsTests: XCTestCase {
private let validURLwithIPv4Address = [
]
private let invalidURLwithIPv4Address = [
"127.0.0.1", // No scheme -> cannot extract host
]
private let validURLwithIPv6Address = [
]
private let invalidURLwithIPv6Address = [
"::1", // No scheme -> cannot extract host
]
func testValidIPv4Addresses() throws {
try validURLwithIPv4Address.forEach {
let url = try XCTUnwrap(URL(string: $0))
XCTAssertTrue(url.isIPv4, "No IPv4 address in URL: '\(url)'")
}
}
func testInvalidIPv4Addresses() throws {
try invalidURLwithIPv4Address.forEach {
let url = try XCTUnwrap(URL(string: $0))
XCTAssertFalse(url.isIPv4, "Unexpected IPv4 address in URL: '\(url)'")
}
}
func testValidIPv6Addresses() throws {
guard #available(iOS 17, *) else {
throw XCTSkip("IPv6 address is not supported completely.")
}
try validURLwithIPv6Address.forEach {
let url = try XCTUnwrap(URL(string: $0))
XCTAssertTrue(url.isIPv6, "No IPv6 address in URL: '\(url)'")
}
}
func testInvalidIPv6Addresses() throws {
try invalidURLwithIPv6Address.forEach {
let url = try XCTUnwrap(URL(string: $0))
XCTAssertFalse(url.isIPv6, "Unexpected IPv6 address in URL: '\(url)'")
}
}
}