Smail/backend/utils/address/address_test.go
smail b96cc4937d
Some checks are pending
Security Checks / security (push) Waiting to run
修复邮箱地址格式校验
2026-09-06 05:17:13 +08:00

64 lines
1.1 KiB
Go

package address
import "testing"
func TestIsValidEmailAddress(t *testing.T) {
type args struct {
str string
}
tests := []struct {
name string
args args
want bool
}{
{
"",
args{"test@qq.com"},
true,
},
{
"",
args{"1000@qq.com"},
true,
},
{
"",
args{"1000@163.com"},
true,
},
{
"",
args{"1000@1631com"},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsValidEmailAddress(tt.args.str); got != tt.want {
t.Errorf("IsValidEmailAddress() = %v, want %v", got, tt.want)
}
})
}
}
func TestIsValidEmailAddressRejectsMalformedAddresses(t *testing.T) {
invalid := []string{
"@example.com",
"user@",
"user..name@example.com",
"user@example..com",
"user name@example.com",
"User <user@example.com>",
" user@example.com",
"user@example.com ",
".user@example.com",
"user.@example.com",
"user@example.com.",
}
for _, value := range invalid {
if IsValidEmailAddress(value) {
t.Errorf("IsValidEmailAddress(%q) = true, want false", value)
}
}
}