2022-01-08 20:07:14 +00:00
|
|
|
package domain_test
|
|
|
|
|
|
|
|
import (
|
2022-01-30 17:49:25 +00:00
|
|
|
"fmt"
|
2022-01-08 20:07:14 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"source.toby3d.me/website/indieauth/internal/domain"
|
|
|
|
)
|
|
|
|
|
2022-01-29 14:43:00 +00:00
|
|
|
func TestParseEmail(t *testing.T) {
|
2022-01-08 20:07:14 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-01-30 17:49:25 +00:00
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
in string
|
|
|
|
out string
|
2022-02-01 17:27:48 +00:00
|
|
|
}{
|
|
|
|
{name: "simple", in: "user@example.com", out: "user@example.com"},
|
|
|
|
{name: "subAddress", in: "user+suffix@example.com", out: "user+suffix@example.com"},
|
|
|
|
{name: "mailto prefix", in: "mailto:user@example.com", out: "user@example.com"},
|
|
|
|
} {
|
2022-01-30 17:49:25 +00:00
|
|
|
tc := tc
|
2022-01-08 20:07:14 +00:00
|
|
|
|
2022-01-30 17:49:25 +00:00
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2022-01-08 20:07:14 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-01-30 17:49:25 +00:00
|
|
|
result, err := domain.ParseEmail(tc.in)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", err)
|
2022-01-08 20:07:14 +00:00
|
|
|
}
|
|
|
|
|
2022-01-30 17:49:25 +00:00
|
|
|
if fmt.Sprint(result) != tc.out {
|
|
|
|
t.Errorf("ParseEmail(%s) = %s, want %s", tc.in, result, tc.out)
|
|
|
|
}
|
2022-01-08 20:07:14 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-01-30 17:49:25 +00:00
|
|
|
|
|
|
|
func TestEmail_String(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2022-02-01 17:27:48 +00:00
|
|
|
email := domain.TestEmail(t) //nolint: ifshort
|
2022-01-30 17:49:25 +00:00
|
|
|
if result := email.String(); result != fmt.Sprint(email) {
|
|
|
|
t.Errorf("String() = %v, want %v", result, email)
|
|
|
|
}
|
|
|
|
}
|