init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user