29 lines
717 B
Go
29 lines
717 B
Go
package handler
|
||
|
||
import "testing"
|
||
|
||
func TestExtractContactsFromText(t *testing.T) {
|
||
text := "你好,我微信是 abc_wx_01,手机 13800138000,邮箱 test@example.com QQ:123456"
|
||
got := extractContactsFromText(text)
|
||
kinds := map[string]string{}
|
||
for _, c := range got {
|
||
kinds[c.Kind] = c.Value
|
||
}
|
||
if kinds["phone"] != "13800138000" {
|
||
t.Fatalf("phone: %+v", got)
|
||
}
|
||
if kinds["wechat"] != "abc_wx_01" {
|
||
t.Fatalf("wechat: %+v", got)
|
||
}
|
||
if kinds["email"] != "test@example.com" {
|
||
t.Fatalf("email: %+v", got)
|
||
}
|
||
if kinds["qq"] != "123456" {
|
||
t.Fatalf("qq: %+v", got)
|
||
}
|
||
// 不完整不应误提
|
||
if len(extractContactsFromText("微信 ab")) != 0 {
|
||
t.Fatal("partial wechat should not extract")
|
||
}
|
||
}
|