-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain_test.go
45 lines (39 loc) · 911 Bytes
/
chain_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package chain
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestChain_Filter(t *testing.T) {
tests1 := []struct {
name string
constant string
want bool
}{
{"safe", "今天天气多云转阴", false},
{"sexy", "色情内容", true},
{"politic", "政治敏感内容", false},
}
tests2 := []struct {
name string
constant string
want bool
}{
{"safe", "今天天气多云转阴", false},
{"sexy", "色情内容", true},
{"politic", "政治敏感内容", true},
}
chain := NewSensitiveWordChain(&SexyWordFilter{})
for _, tt := range tests1 {
t.Run(tt.name, func(t *testing.T) {
got := chain.Filter(tt.constant)
assert.Equal(t, tt.want, got)
})
}
chain.AddFilter(&PoliticalWordFilter{})
for _, tt := range tests2 {
t.Run(tt.name, func(t *testing.T) {
got := chain.Filter(tt.constant)
assert.Equal(t, tt.want, got)
})
}
}