package email_test

import (
	"testing"

	email "github.com/gopherguides/learn/_training/fundamentals/testing/src/coverage"
)

func Test_ValidateEmail(t *testing.T) {
	tests := []struct {
		name      string
		em        string
		expectErr bool
	}{
		{name: "blank", em: "", expectErr: true},
		{name: "at", em: "yahoo.com", expectErr: true},
		{name: "period", em: "homer@yahoocom", expectErr: true},
		{name: "valid", em: "homer@yahoo.com"},
	}

	for _, test := range tests {
		t.Run(test.name, func(st *testing.T) {
			err := email.Validate(test.em)
			if err == nil && test.expectErr {
				st.Fatal("expected error, got nil")
			}
			if err != nil && !test.expectErr {
				st.Fatal(err)
			}
		})
	}
}
