-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
4 changed files
with
180 additions
and
24 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 |
---|---|---|
|
@@ -46,15 +46,23 @@ func Test_String(t *testing.T) { | |
}) | ||
|
||
t.Run("min", func(t *testing.T) { | ||
t.Run("should succeed", func(t *testing.T) { | ||
t.Run("should succeed when nil", func(t *testing.T) { | ||
err := owl.String().Min(5).Validate(nil) | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should succeed when length gt min", func(t *testing.T) { | ||
err := owl.String().Min(5).Validate("tester") | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should fail", func(t *testing.T) { | ||
t.Run("should fail when length lt min", func(t *testing.T) { | ||
err := owl.String().Min(5).Validate("test") | ||
|
||
if err == nil { | ||
|
@@ -64,15 +72,23 @@ func Test_String(t *testing.T) { | |
}) | ||
|
||
t.Run("max", func(t *testing.T) { | ||
t.Run("should succeed", func(t *testing.T) { | ||
t.Run("should succeed when nil", func(t *testing.T) { | ||
err := owl.String().Max(5).Validate(nil) | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should succeed when length lt max", func(t *testing.T) { | ||
err := owl.String().Max(5).Validate("test") | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should fail", func(t *testing.T) { | ||
t.Run("should fail when length gt max", func(t *testing.T) { | ||
err := owl.String().Max(5).Validate("tester") | ||
|
||
if err == nil { | ||
|
@@ -82,15 +98,23 @@ func Test_String(t *testing.T) { | |
}) | ||
|
||
t.Run("regex", func(t *testing.T) { | ||
t.Run("should succeed", func(t *testing.T) { | ||
t.Run("should succeed when nil", func(t *testing.T) { | ||
err := owl.String().Regex(regexp.MustCompile("^[0-9a-zA-Z_-]+$")).Validate(nil) | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should succeed when matches", func(t *testing.T) { | ||
err := owl.String().Regex(regexp.MustCompile("^[0-9a-zA-Z_-]+$")).Validate("test") | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should fail", func(t *testing.T) { | ||
t.Run("should fail when not matches", func(t *testing.T) { | ||
err := owl.String().Regex(regexp.MustCompile("^[0-9a-zA-Z_-]+$")).Validate("a test") | ||
|
||
if err == nil { | ||
|
@@ -100,15 +124,23 @@ func Test_String(t *testing.T) { | |
}) | ||
|
||
t.Run("email", func(t *testing.T) { | ||
t.Run("should succeed", func(t *testing.T) { | ||
t.Run("should succeed when nil", func(t *testing.T) { | ||
err := owl.String().Email().Validate(nil) | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should succeed when email", func(t *testing.T) { | ||
err := owl.String().Email().Validate("[email protected]") | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should fail", func(t *testing.T) { | ||
t.Run("should fail when not email", func(t *testing.T) { | ||
err := owl.String().Email().Validate("test") | ||
|
||
if err == nil { | ||
|
@@ -118,15 +150,23 @@ func Test_String(t *testing.T) { | |
}) | ||
|
||
t.Run("uuid", func(t *testing.T) { | ||
t.Run("should succeed", func(t *testing.T) { | ||
t.Run("should succeed when nil", func(t *testing.T) { | ||
err := owl.String().UUID().Validate(nil) | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should succeed when uuid", func(t *testing.T) { | ||
err := owl.String().UUID().Validate("afefc1ab-b8f2-4803-8e9a-60515854141a") | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should fail", func(t *testing.T) { | ||
t.Run("should fail when not uuid", func(t *testing.T) { | ||
err := owl.String().UUID().Validate("test") | ||
|
||
if err == nil { | ||
|
@@ -136,15 +176,23 @@ func Test_String(t *testing.T) { | |
}) | ||
|
||
t.Run("url", func(t *testing.T) { | ||
t.Run("should succeed", func(t *testing.T) { | ||
t.Run("should succeed when nil", func(t *testing.T) { | ||
err := owl.String().URL().Validate(nil) | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should succeed when url", func(t *testing.T) { | ||
err := owl.String().URL().Validate("https://www.google.com") | ||
|
||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("should fail", func(t *testing.T) { | ||
t.Run("should fail when not url", func(t *testing.T) { | ||
err := owl.String().URL().Validate("test") | ||
|
||
if err == nil { | ||
|
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