package main import "testing" func TestStringAnonSettings_Apply(t *testing.T) { t.Run("Not replaced when nil", func(t *testing.T) { title := "Test" var anonTitle *StringAnonSettings = nil if anonTitle.Apply(title) != title { t.Fatal("The title should be unchanged.") } }) t.Run("Not replaced when empty", func(t *testing.T) { title := "Test" anonTitle := &StringAnonSettings{ReplaceWith: ""} if anonTitle.Apply(title) != title { t.Fatal("The title should be unchanged.") } }) t.Run("With whitelist", func(t *testing.T) { anonTitle := &StringAnonSettings{ ReplaceWith: "#Replaced", Whitelist: []string{ "lower", "Test", "With Space", }, } t.Run("No match", func(t *testing.T) { if anonTitle.Apply("unrelated title") != "#Replaced" { t.Fatal("The title should have been replaced.") } }) t.Run("Word found", func(t *testing.T) { if anonTitle.Apply("This is a Test title.") != "Test" { t.Fatal("One word should have matched.") } }) t.Run("Case ignored", func(t *testing.T) { if anonTitle.Apply("Something with LOWER case.") != "lower" { t.Fatal("The lower case variant should have matched.") } }) t.Run("Match with space", func(t *testing.T) { if anonTitle.Apply("A title With Space") != "With Space" { t.Fatal("A match with space should be found.") } }) t.Run("Multiple matches", func(t *testing.T) { if anonTitle.Apply("Some lower title Test") != "lower Test" { t.Fatal("Multiple matches should be concatenated.") } }) t.Run("Multiple matches keep their order", func(t *testing.T) { if anonTitle.Apply("Test title with lower order") != "Test lower" { t.Fatal("The original order should be kept") } }) }) }