Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
package store
import (
"strings"
"testing"
)
func TestNormalizeEmail(t *testing.T) {
tests := []struct {
name string
email string
want string
wantErr bool
}{
{name: "plain", email: "[email protected]", want: "[email protected]"},
{name: "empty means none", email: "", want: ""},
{name: "whitespace only means none", email: " ", want: ""},
{name: "trims and lowercases", email: " [email protected] ", want: "[email protected]"},
{name: "local part is folded", email: "[email protected]", want: "[email protected]"},
{name: "plus address kept", email: "[email protected]", want: "[email protected]"},
{name: "dotless domain allowed", email: "1@gmail", want: "1@gmail"},
{name: "missing local part", email: "@usememos.com", wantErr: true},
{name: "missing at sign", email: "usememos.com", wantErr: true},
{name: "display name form", email: "Alice <[email protected]>", wantErr: true},
{name: "angle brackets only", email: "<[email protected]>", wantErr: true},
{name: "two at signs", email: "[email protected]@example.com", wantErr: true},
{name: "interior whitespace", email: "alice @example.com", wantErr: true},
{name: "too long", email: strings.Repeat("a", 250) + "@x.io", wantErr: true},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := NormalizeEmail(test.email)
if test.wantErr {
if err == nil {
t.Fatalf("NormalizeEmail(%q) = %q, want error", test.email, got)
}
return
}
if err != nil {
t.Fatalf("NormalizeEmail(%q) unexpected error: %v", test.email, err)
}
if got != test.want {
t.Fatalf("NormalizeEmail(%q) = %q, want %q", test.email, got, test.want)
}
})
}
}