48 lines
864 B
Go
48 lines
864 B
Go
package server
|
|||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestCleanProfanity(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
input string
|
||
|
|
expected string
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "no profanity",
|
||
|
|
input: "hello world",
|
||
|
|
expected: "hello world",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "case insensitive",
|
||
|
|
input: "That was a KERFUFFLE",
|
||
|
|
expected: "That was a ****",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "not a substring match",
|
||
|
|
input: "kerfuffling away",
|
||
|
|
expected: "kerfuffling away",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "multiple words",
|
||
|
|
input: "sharbert fornax",
|
||
|
|
expected: "**** ****",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "empty body",
|
||
|
|
input: "",
|
||
|
|
expected: "",
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
got := cleanProfanity(tt.input)
|
||
|
|
|
||
|
|
if got != tt.expected {
|
||
|
|
t.Errorf("cleanProfanity(%q) = %q, want %q", tt.input, got, tt.expected)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|