|
|
|
@ -252,3 +252,58 @@ func TestListEmails(t *testing.T) { |
|
|
|
|
assert.Len(t, emails, 5) |
|
|
|
|
assert.Greater(t, count, int64(len(emails))) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestEmailAddressValidate(t *testing.T) { |
|
|
|
|
kases := map[string]error{ |
|
|
|
|
"abc@gmail.com": nil, |
|
|
|
|
"132@hotmail.com": nil, |
|
|
|
|
"1-3-2@test.org": nil, |
|
|
|
|
"1.3.2@test.org": nil, |
|
|
|
|
"a_123@test.org.cn": nil, |
|
|
|
|
`first.last@iana.org`: nil, |
|
|
|
|
`first!last@iana.org`: nil, |
|
|
|
|
`first#last@iana.org`: nil, |
|
|
|
|
`first$last@iana.org`: nil, |
|
|
|
|
`first%last@iana.org`: nil, |
|
|
|
|
`first&last@iana.org`: nil, |
|
|
|
|
`first'last@iana.org`: nil, |
|
|
|
|
`first*last@iana.org`: nil, |
|
|
|
|
`first+last@iana.org`: nil, |
|
|
|
|
`first/last@iana.org`: nil, |
|
|
|
|
`first=last@iana.org`: nil, |
|
|
|
|
`first?last@iana.org`: nil, |
|
|
|
|
`first^last@iana.org`: nil, |
|
|
|
|
"first`last@iana.org": nil, |
|
|
|
|
`first{last@iana.org`: nil, |
|
|
|
|
`first|last@iana.org`: nil, |
|
|
|
|
`first}last@iana.org`: nil, |
|
|
|
|
`first~last@iana.org`: nil, |
|
|
|
|
`first;last@iana.org`: ErrEmailCharIsNotSupported{`first;last@iana.org`}, |
|
|
|
|
".233@qq.com": ErrEmailInvalid{".233@qq.com"}, |
|
|
|
|
"!233@qq.com": ErrEmailInvalid{"!233@qq.com"}, |
|
|
|
|
"#233@qq.com": ErrEmailInvalid{"#233@qq.com"}, |
|
|
|
|
"$233@qq.com": ErrEmailInvalid{"$233@qq.com"}, |
|
|
|
|
"%233@qq.com": ErrEmailInvalid{"%233@qq.com"}, |
|
|
|
|
"&233@qq.com": ErrEmailInvalid{"&233@qq.com"}, |
|
|
|
|
"'233@qq.com": ErrEmailInvalid{"'233@qq.com"}, |
|
|
|
|
"*233@qq.com": ErrEmailInvalid{"*233@qq.com"}, |
|
|
|
|
"+233@qq.com": ErrEmailInvalid{"+233@qq.com"}, |
|
|
|
|
"/233@qq.com": ErrEmailInvalid{"/233@qq.com"}, |
|
|
|
|
"=233@qq.com": ErrEmailInvalid{"=233@qq.com"}, |
|
|
|
|
"?233@qq.com": ErrEmailInvalid{"?233@qq.com"}, |
|
|
|
|
"^233@qq.com": ErrEmailInvalid{"^233@qq.com"}, |
|
|
|
|
"`233@qq.com": ErrEmailInvalid{"`233@qq.com"}, |
|
|
|
|
"{233@qq.com": ErrEmailInvalid{"{233@qq.com"}, |
|
|
|
|
"|233@qq.com": ErrEmailInvalid{"|233@qq.com"}, |
|
|
|
|
"}233@qq.com": ErrEmailInvalid{"}233@qq.com"}, |
|
|
|
|
"~233@qq.com": ErrEmailInvalid{"~233@qq.com"}, |
|
|
|
|
";233@qq.com": ErrEmailCharIsNotSupported{";233@qq.com"}, |
|
|
|
|
"Foo <foo@bar.com>": ErrEmailCharIsNotSupported{"Foo <foo@bar.com>"}, |
|
|
|
|
string([]byte{0xE2, 0x84, 0xAA}): ErrEmailCharIsNotSupported{string([]byte{0xE2, 0x84, 0xAA})}, |
|
|
|
|
} |
|
|
|
|
for kase, err := range kases { |
|
|
|
|
t.Run(kase, func(t *testing.T) { |
|
|
|
|
assert.EqualValues(t, err, ValidateEmail(kase)) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|