-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for hostname method in z.string() #3589
- Loading branch information
1 parent
821d45b
commit 342fc32
Showing
11 changed files
with
105 additions
and
2 deletions.
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
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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ const includes = z.string().includes("includes"); | |
const includesFromIndex2 = z.string().includes("includes", { position: 2 }); | ||
const startsWith = z.string().startsWith("startsWith"); | ||
const endsWith = z.string().endsWith("endsWith"); | ||
const hostname = z.string().hostname(); | ||
|
||
test("passing validations", () => { | ||
minFive.parse("12345"); | ||
|
@@ -24,6 +25,12 @@ test("passing validations", () => { | |
includesFromIndex2.parse("XXXincludesXX"); | ||
startsWith.parse("startsWithX"); | ||
endsWith.parse("XendsWith"); | ||
hostname.parse("developer.mozilla.org"); | ||
hostname.parse("hello.world.example.com"); | ||
hostname.parse("www.google.com"); | ||
hostname.parse("[2001:db8::ff00:42:8329]"); | ||
hostname.parse("192.168.1.1"); | ||
hostname.parse("xn--d1acj3b"); | ||
}); | ||
|
||
test("failing validations", () => { | ||
|
@@ -36,6 +43,13 @@ test("failing validations", () => { | |
expect(() => includesFromIndex2.parse("XincludesXX")).toThrow(); | ||
expect(() => startsWith.parse("x")).toThrow(); | ||
expect(() => endsWith.parse("x")).toThrow(); | ||
expect(() => hostname.parse("ht!tp://invalid.com")).toThrow(); | ||
expect(() => hostname.parse("xn--d1acj3b..com")).toThrow(); | ||
expect(() => hostname.parse("[email protected]")).toThrow(); | ||
expect(() => hostname.parse("[2001:db8::zzzz]")).toThrow(); | ||
expect(() => hostname.parse("exa mple.com")).toThrow(); | ||
expect(() => hostname.parse("-example.com")).toThrow(); | ||
expect(() => hostname.parse("example..com")).toThrow(); | ||
}); | ||
|
||
test("email validations", () => { | ||
|
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
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ const includes = z.string().includes("includes"); | |
const includesFromIndex2 = z.string().includes("includes", { position: 2 }); | ||
const startsWith = z.string().startsWith("startsWith"); | ||
const endsWith = z.string().endsWith("endsWith"); | ||
const hostname = z.string().hostname(); | ||
|
||
test("passing validations", () => { | ||
minFive.parse("12345"); | ||
|
@@ -23,6 +24,12 @@ test("passing validations", () => { | |
includesFromIndex2.parse("XXXincludesXX"); | ||
startsWith.parse("startsWithX"); | ||
endsWith.parse("XendsWith"); | ||
hostname.parse("developer.mozilla.org"); | ||
hostname.parse("hello.world.example.com"); | ||
hostname.parse("www.google.com"); | ||
hostname.parse("[2001:db8::ff00:42:8329]"); | ||
hostname.parse("192.168.1.1"); | ||
hostname.parse("xn--d1acj3b"); | ||
}); | ||
|
||
test("failing validations", () => { | ||
|
@@ -35,6 +42,13 @@ test("failing validations", () => { | |
expect(() => includesFromIndex2.parse("XincludesXX")).toThrow(); | ||
expect(() => startsWith.parse("x")).toThrow(); | ||
expect(() => endsWith.parse("x")).toThrow(); | ||
expect(() => hostname.parse("ht!tp://invalid.com")).toThrow(); | ||
expect(() => hostname.parse("xn--d1acj3b..com")).toThrow(); | ||
expect(() => hostname.parse("[email protected]")).toThrow(); | ||
expect(() => hostname.parse("[2001:db8::zzzz]")).toThrow(); | ||
expect(() => hostname.parse("exa mple.com")).toThrow(); | ||
expect(() => hostname.parse("-example.com")).toThrow(); | ||
expect(() => hostname.parse("example..com")).toThrow(); | ||
}); | ||
|
||
test("email validations", () => { | ||
|
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