-
Notifications
You must be signed in to change notification settings - Fork 9
/
swearfilter_test.go
54 lines (50 loc) · 1.95 KB
/
swearfilter_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
46
47
48
49
50
51
52
53
54
package swearfilter
import (
"testing"
)
func TestNew(t *testing.T) {
filter := NewSwearFilter(true, "fuck", "hell")
if filter.DisableNormalize {
t.Errorf("Filter option DisableNormalize was incorrect, got: %t, want: %t", filter.DisableNormalize, false)
}
if filter.DisableSpacedTab {
t.Errorf("Filter option DisableSpacedTab was incorrect, got: %t, want: %t", filter.DisableSpacedTab, false)
}
if filter.DisableMultiWhitespaceStripping {
t.Errorf("Filter option DisableMultiWhitespaceStripping was incorrect, got: %t, want: %t", filter.DisableMultiWhitespaceStripping, false)
}
if filter.DisableZeroWidthStripping {
t.Errorf("Filter option DisableZeroWidthStripping was incorrect, got: %t, want: %t", filter.DisableZeroWidthStripping, false)
}
if !filter.EnableSpacedBypass {
t.Errorf("Filter option EnableSpacedBypass was incorrect, got: %t, want: %t", filter.EnableSpacedBypass, true)
}
if len(filter.BadWords) != 2 {
t.Errorf("Filter option BadWords was incorrect, got length: %d, want length: %d", len(filter.BadWords), 2)
}
}
func TestCheck(t *testing.T) {
filter := NewSwearFilter(true, "fuck")
messages := []string{"fucking", "fûçk", "asdf", "what the f u c k dude"}
for i := 0; i < len(messages); i++ {
trippers, err := filter.Check(messages[i])
if err != nil {
t.Errorf("Check failed due to external dependency: %v", err)
}
switch i {
case 0, 1, 3:
if len(trippers) != 1 {
t.Errorf("Check did not act as expected, got trippers length: %d, want trippers length: %d", len(trippers), 1)
}
if trippers[0] != "fuck" {
t.Errorf("Check did not act as expected, got first tripper: %s, want first tripper: %s", trippers[0], "fuck")
}
case 2:
if len(trippers) != 0 {
t.Errorf("Check did not act as expected, got trippers length: %d, want trippers length: %d", len(trippers), 0)
}
default:
t.Errorf("Check test invalid, got test messages length: %d, want test messages length: %d", len(messages), 4)
}
}
}