email_test.go 505 B

12345678910111213141516171819202122232425262728
  1. package validate
  2. import "testing"
  3. func TestEmail(t *testing.T) {
  4. type TestCase struct {
  5. Input string
  6. Err bool
  7. }
  8. testCases := []TestCase{
  9. {Input: "test@example.com"},
  10. {Input: "testexample.com", Err: true},
  11. }
  12. for _, tc := range testCases {
  13. err := Email(tc.Input)
  14. if tc.Err {
  15. if err == nil {
  16. t.Errorf("Expected %q to be an invalid email; got nil", tc.Input)
  17. }
  18. } else {
  19. if err != nil {
  20. t.Errorf("Expected %q to be a valid email; got %s", tc.Input, err)
  21. }
  22. }
  23. }
  24. }