65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package handler
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeShortcut(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{"", "", false},
|
|
{"nh", "nh", false},
|
|
{"/NH", "nh", false},
|
|
{"hello_1", "hello_1", false},
|
|
{"a-b", "a-b", false},
|
|
{"中文", "", true},
|
|
{"has space", "", true},
|
|
}
|
|
for _, tc := range cases {
|
|
got, err := normalizeShortcut(tc.in)
|
|
if tc.wantErr {
|
|
if err == nil {
|
|
t.Fatalf("normalizeShortcut(%q) 期望错误", tc.in)
|
|
}
|
|
continue
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("normalizeShortcut(%q): %v", tc.in, err)
|
|
}
|
|
if got != tc.want {
|
|
t.Fatalf("normalizeShortcut(%q)=%q want %q", tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseQuickReplyScopeLabel(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want string
|
|
wantOK bool
|
|
}{
|
|
{"团队", "team", true},
|
|
{"个人", "personal", true},
|
|
{"", "", true},
|
|
{"team", "", false},
|
|
{"personal", "", false},
|
|
{"其它", "", false},
|
|
}
|
|
for _, tc := range cases {
|
|
got, ok := parseQuickReplyScopeLabel(tc.in)
|
|
if ok != tc.wantOK || got != tc.want {
|
|
t.Fatalf("parseQuickReplyScopeLabel(%q)=(%q,%v) want (%q,%v)", tc.in, got, ok, tc.want, tc.wantOK)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsQuickReplyCSVHeader(t *testing.T) {
|
|
if !isQuickReplyCSVHeader([]string{"一级分类", "二级分类", "输入码", "内容"}) {
|
|
t.Fatal("expected header match")
|
|
}
|
|
if isQuickReplyCSVHeader([]string{"title", "content", "shortcut", "group_name"}) {
|
|
t.Fatal("legacy english header should not match")
|
|
}
|
|
}
|