Files
chirpy/internal/server/profanity_test.go
T

48 lines
864 B
Go
Raw Normal View History

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)
}
})
}
}