forked from JoshuaDoes/gofuckyourself
-
Notifications
You must be signed in to change notification settings - Fork 2
/
swearfilter_test.go
67 lines (60 loc) · 2.26 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
55
56
57
58
59
60
61
62
63
64
65
66
67
package swearfilter
import (
"testing"
"github.com/stretchr/testify/require"
)
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)
}
}
}
func TestCheck2(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])
require.NoError(t, err)
t.Log(trippers)
}
}