2023-10-06 11:58:24 +01:00
|
|
|
package validate
|
|
|
|
|
|
2023-11-19 20:27:33 +00:00
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
2023-10-06 11:58:24 +01:00
|
|
|
|
2023-10-07 10:43:21 +01:00
|
|
|
func TestEmail(t *testing.T) {
|
|
|
|
|
type TestCase struct {
|
|
|
|
|
Input string
|
2023-10-08 15:21:02 +01:00
|
|
|
Err error
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 10:43:21 +01:00
|
|
|
testCases := []TestCase{
|
|
|
|
|
{Input: "test@example.com"},
|
2023-10-08 15:21:02 +01:00
|
|
|
{Input: "testexample.com", Err: ErrInvalidEmail},
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 16:20:21 +01:00
|
|
|
for n, tc := range testCases {
|
|
|
|
|
t.Logf("(%d) Testing %q", n, tc.Input)
|
2023-10-08 15:21:02 +01:00
|
|
|
|
2023-10-07 10:44:47 +01:00
|
|
|
err := Email(tc.Input)
|
2023-10-08 15:21:02 +01:00
|
|
|
|
2023-11-19 20:27:33 +00:00
|
|
|
if !errors.Is(err, tc.Err) {
|
2023-10-08 15:21:02 +01:00
|
|
|
t.Errorf("Expected error %v, got %v", tc.Err, err)
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|