add min/max length validation, improve tests
This commit is contained in:
+19
-18
@@ -2,26 +2,27 @@ package validate
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestInvalidEmail(t *testing.T) {
|
||||
valid := []string{
|
||||
"testexample.com",
|
||||
func TestEmail(t *testing.T) {
|
||||
type TestCase struct {
|
||||
Input string
|
||||
Err bool
|
||||
}
|
||||
|
||||
for _, email := range valid {
|
||||
if err := Email(email); err == nil {
|
||||
t.Errorf("%s is not a valid email", email)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidEmail(t *testing.T) {
|
||||
valid := []string{
|
||||
"test@example.com",
|
||||
}
|
||||
|
||||
for _, email := range valid {
|
||||
if err := Email(email); err != nil {
|
||||
t.Errorf("%s is a valid email", email)
|
||||
testCases := []TestCase{
|
||||
{Input: "test@example.com"},
|
||||
{Input: "testexample.com", Err: true},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
err := Email(testCase.Input)
|
||||
if testCase.Err {
|
||||
if err == nil {
|
||||
t.Errorf("Expected %q to be an invalid email; got nil", testCase.Input)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("Expected %q to be a valid email; got %s", testCase.Input, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user