35 lines
688 B
Go
35 lines
688 B
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)
|
|
}
|
|
}
|
|
}
|