Files
cc-connect/platform/wecom/mention_strip_test.go
2026-06-02 23:14:41 +08:00

33 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package wecom
import "testing"
func TestStripWeComAtMentions(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in string
ids []string
want string
}{
{"empty", "", []string{"x"}, ""},
{"no ids", "允许", nil, "允许"},
{"suffix mention", "允许 @mybot", []string{"mybot"}, "允许"},
{"prefix mention", "@MyBot 允许", []string{"mybot"}, "允许"},
{"fullwidth at", "允许 mybot", []string{"mybot"}, "允许"},
{"two ids second", "ok @a @b", []string{"a", "b"}, "ok"},
{"unrelated at", "email x@y.com", []string{"mybot"}, "email x@y.com"},
{"display mention before slash command", "@小口不休息 /whoami", []string{"robot01"}, "/whoami"},
{"display mention before bang command", "@小口不休息 !pwd", []string{"robot01"}, "!pwd"},
{"display mention before normal text preserved", "@小口不休息 你好", []string{"robot01"}, "@小口不休息 你好"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := stripWeComAtMentions(tt.in, tt.ids...)
if got != tt.want {
t.Fatalf("got %q want %q", got, tt.want)
}
})
}
}