Extract shared NormalizeAlnum into pkg/strutil

The alphanumeric-normalisation helper was duplicated verbatim in the
common-third-party owned-domains resolver and the cookiebanner tracker
mapping worker. Hoist it into a new dependency-free strutil package so
both call sites share one implementation and one test.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-06-12 10:59:31 +02:00
parent 474074480a
commit 213ac6ddbe
5 changed files with 92 additions and 64 deletions

View File

@@ -130,32 +130,6 @@ func TestNameIsCookieDatabaseAggregator(t *testing.T) {
}
}
func TestNormalizeAlnum(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input string
expected string
}{
{name: "letters lowercased", input: "Letaido", expected: "letaido"},
{name: "strips punctuation and spaces", input: "letaido.com - Inc", expected: "letaidocominc"},
{name: "keeps digits", input: "auth0", expected: "auth0"},
{name: "empty", input: "", expected: ""},
{name: "only punctuation", input: "-_.:", expected: ""},
}
for _, tt := range tests {
t.Run(
tt.name,
func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.expected, normalizeAlnum(tt.input))
},
)
}
}
func TestBuildAgentPrompt(t *testing.T) {
t.Parallel()