-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ricardo Zanini <[email protected]>
- Loading branch information
1 parent
0c27f20
commit d988f0c
Showing
3 changed files
with
121 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package model | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRegexValidators(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
validate func(string) bool | ||
input string | ||
expected bool | ||
}{ | ||
// ISO 8601 Duration Tests | ||
{"ISO 8601 Duration Valid 1", isISO8601DurationValid, "P2Y", true}, | ||
{"ISO 8601 Duration Valid 2", isISO8601DurationValid, "P1DT12H30M", true}, | ||
{"ISO 8601 Duration Valid 3", isISO8601DurationValid, "P1Y2M3D", true}, | ||
{"ISO 8601 Duration Valid 4", isISO8601DurationValid, "P1Y2M3D4H", false}, | ||
{"ISO 8601 Duration Valid 5", isISO8601DurationValid, "P1Y", true}, | ||
{"ISO 8601 Duration Valid 6", isISO8601DurationValid, "PT1H", true}, | ||
{"ISO 8601 Duration Valid 7", isISO8601DurationValid, "P1Y2M3D4H5M6S", false}, | ||
{"ISO 8601 Duration Invalid 1", isISO8601DurationValid, "P", false}, | ||
{"ISO 8601 Duration Invalid 2", isISO8601DurationValid, "P1Y2M3D4H5M6S7", false}, | ||
{"ISO 8601 Duration Invalid 3", isISO8601DurationValid, "1Y", false}, | ||
|
||
// Semantic Versioning Tests | ||
{"Semantic Version Valid 1", isSemanticVersionValid, "1.0.0", true}, | ||
{"Semantic Version Valid 2", isSemanticVersionValid, "1.2.3", true}, | ||
{"Semantic Version Valid 3", isSemanticVersionValid, "1.2.3-beta", true}, | ||
{"Semantic Version Valid 4", isSemanticVersionValid, "1.2.3-beta.1", true}, | ||
{"Semantic Version Valid 5", isSemanticVersionValid, "1.2.3-beta.1+build.123", true}, | ||
{"Semantic Version Invalid 1", isSemanticVersionValid, "v1.2.3", false}, | ||
{"Semantic Version Invalid 2", isSemanticVersionValid, "1.2", false}, | ||
{"Semantic Version Invalid 3", isSemanticVersionValid, "1.2.3-beta.x", true}, | ||
|
||
// RFC 1123 Hostname Tests | ||
{"RFC 1123 Hostname Valid 1", isHostnameValid, "example.com", true}, | ||
{"RFC 1123 Hostname Valid 2", isHostnameValid, "my-hostname", true}, | ||
{"RFC 1123 Hostname Valid 3", isHostnameValid, "subdomain.example.com", true}, | ||
{"RFC 1123 Hostname Invalid 1", isHostnameValid, "127.0.0.1", false}, | ||
{"RFC 1123 Hostname Invalid 2", isHostnameValid, "example.com.", false}, | ||
{"RFC 1123 Hostname Invalid 3", isHostnameValid, "example..com", false}, | ||
{"RFC 1123 Hostname Invalid 4", isHostnameValid, "example.com-", false}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result := tc.validate(tc.input) | ||
if result != tc.expected { | ||
t.Errorf("Validation failed for '%s': input='%s', expected=%v, got=%v", tc.name, tc.input, tc.expected, result) | ||
} | ||
}) | ||
} | ||
} |