Files
web_hgcg_server/pub/models/hotsearchmod/hotsearch_test.go
T
2026-10-27 16:44:55 +08:00

32 lines
739 B
Go

package hotsearchmod
import "testing"
func TestNormalizeKeyword(t *testing.T) {
tests := []struct {
name string
raw string
want string
}{
{name: "空串", raw: " ", want: ""},
{name: "压缩空白", raw: " 霸道 总裁\t ", want: "霸道 总裁"},
{name: "截断长度", raw: stringsRepeat("测", 60), want: stringsRepeat("测", MaxKeywordRunes)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NormalizeKeyword(tt.raw); got != tt.want {
t.Fatalf("NormalizeKeyword() = %q, want %q", got, tt.want)
}
})
}
}
func stringsRepeat(s string, n int) string {
out := make([]rune, 0, n)
r := []rune(s)[0]
for i := 0; i < n; i++ {
out = append(out, r)
}
return string(out)
}