-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2efee14
commit a486a77
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,4 +336,39 @@ final class StringExtensionTests: XCTestCase { | |
|
||
} | ||
|
||
func testWhenStringIsValidHost_thenValidHostIsTrue() { | ||
let validHostnames = [ | ||
"example.com", | ||
"subdomain.example.com", | ||
"my-host123", | ||
"localhost", | ||
"192.168.1.1", // Valid IP address | ||
"2001:0db8:85a3:0000:0000:8a2e:0370:7334" // Valid IPv6 address | ||
] | ||
|
||
for hostname in validHostnames { | ||
XCTAssertTrue(hostname.isValidHost, "\(hostname) should be a valid host") | ||
} | ||
} | ||
|
||
func testWhenStringIsInvalidHost_thenValidHostIsFalse() { | ||
let invalidHostnames = [ | ||
"invalid_hostname", // Invalid character | ||
"-example.com", // Starts with a hyphen | ||
"example-.com", // Ends with a hyphen | ||
"example..com", // Consecutive dots | ||
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.com", // Too long | ||
"example.com.", // Ends with a dot | ||
"3 + 5 * (2 - 1)", // Mathematical expression | ||
"16385-12228.72", // Other mathetmatical expression | ||
"[email protected]", // Invalid character | ||
"192.168.1.256", // Invalid IP address | ||
"2001:0db8:85a3:0000:0000:8a2e:0370:7334:1234" // Invalid IPv6 address | ||
] | ||
|
||
for hostname in invalidHostnames { | ||
XCTAssertFalse(hostname.isValidHost, "\(hostname) should NOT be a valid host") | ||
} | ||
} | ||
|
||
} |