package utils import ( "testing" ) func TestSanitizeString(t *testing.T) { s := DefaultSanitizer() tests := []struct { name string input string expected string }{ {"simple text", "hello world", "hello world"}, {"with whitespace", " hello ", "hello"}, {"with html", "", "<script>alert('xss')</script>"}, {"empty string", "", ""}, {"special chars", "café & thé", "café & thé"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := s.SanitizeString(tt.input) if result != tt.expected { t.Errorf("SanitizeString(%q) = %q, want %q", tt.input, result, tt.expected) } }) } } func TestSanitizeSlug(t *testing.T) { s := DefaultSanitizer() tests := []struct { name string input string expected string }{ {"simple text", "Hello World", "hello-world"}, {"special chars", "Café & Thé!", "caf-th"}, {"multiple spaces", "hello world", "hello-world"}, {"already slug", "hello-world", "hello-world"}, {"numbers", "test 123", "test-123"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := s.SanitizeSlug(tt.input) if result != tt.expected { t.Errorf("SanitizeSlug(%q) = %q, want %q", tt.input, result, tt.expected) } }) } } func TestSanitizeName(t *testing.T) { s := DefaultSanitizer() s.MaxNameLength = 10 tests := []struct { name string input string expected string }{ {"short name", "John", "John"}, {"max length", "1234567890", "1234567890"}, {"over limit", "12345678901", "1234567890"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := s.SanitizeName(tt.input) if result != tt.expected { t.Errorf("SanitizeName(%q) = %q, want %q", tt.input, result, tt.expected) } }) } } func TestStripHTML(t *testing.T) { tests := []struct { name string input string expected string }{ {"simple html", "
hello
", "hello"}, {"script tag", "", "alert('xss')"}, {"nested tags", "