package api import ( "strings" "testing" ) func TestValidAuthorParam(t *testing.T) { cases := []struct { name string in string want bool }{ {"slug", "jane-doe", true}, {"dotted login", "jan.kowalski", true}, {"at sign", "a@b", true}, {"max bytes", strings.Repeat("a", 255), true}, {"multibyte", "zażółć", true}, {"empty", "", false}, {"whitespace only", strings.TrimSpace(" \t "), false}, {"over max bytes", strings.Repeat("a", 256), false}, {"nul byte", "a\x00b", false}, {"newline", "a\nb", false}, {"tab", "a\tb", false}, {"invalid utf8", "\xff", false}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { if got := validAuthorParam(tc.in); got != tc.want { t.Fatalf("validAuthorParam(%q) = %v, want %v", tc.in, got, tc.want) } }) } }