chore: baseline snapshot before moderation-strictness feature
Repo .git was damaged (refs/ missing, index truncated, object store near-empty). Repaired via git init (rebuilt refs), stale index preserved as .git/index.corrupt-20260910.bak, then full worktree committed as a rollback baseline.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package shared
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBlockWordHit(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
words string // CSV 词表
|
||||
text string
|
||||
word string
|
||||
hit bool
|
||||
}{
|
||||
{name: "empty list", words: "", text: "广告", word: "", hit: false},
|
||||
{name: "empty text", words: "广告", text: "", word: "", hit: false},
|
||||
{name: "single hit", words: "广告,spam", text: "请勿发广告", word: "广告", hit: true},
|
||||
{name: "second word hit", words: "广告,spam", text: "buy now spam!", word: "spam", hit: true},
|
||||
{name: "no hit", words: "广告,spam", text: "你好呀", word: "", hit: false},
|
||||
{name: "dirty csv trims space", words: " 广告 , spam ", text: "这是广告", word: "广告", hit: true},
|
||||
{name: "dirty csv empty items skipped", words: "广告,,,spam", text: "spam again", word: "spam", hit: true},
|
||||
{name: "substring semantics", words: "抽奖", text: "参与抽奖活动", word: "抽奖", hit: true},
|
||||
{name: "chinese word bytes safe", words: "屏蔽", text: "你被屏蔽了吗", word: "屏蔽", hit: true},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
gotWord, gotHit := BlockWordHit(c.words, c.text)
|
||||
if gotHit != c.hit || gotWord != c.word {
|
||||
t.Fatalf("BlockWordHit(%q, %q) = (%q, %v), want (%q, %v)",
|
||||
c.words, c.text, gotWord, gotHit, c.word, c.hit)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user