2023-10-06 11:58:24 +01:00
|
|
|
package validate
|
|
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
2023-10-07 10:43:21 +01:00
|
|
|
func TestEmail(t *testing.T) {
|
|
|
|
|
type TestCase struct {
|
|
|
|
|
Input string
|
|
|
|
|
Err bool
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 10:43:21 +01:00
|
|
|
testCases := []TestCase{
|
|
|
|
|
{Input: "test@example.com"},
|
|
|
|
|
{Input: "testexample.com", Err: true},
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 10:43:21 +01:00
|
|
|
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)
|
|
|
|
|
}
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|