package util import "testing" func TestSlugify(t *testing.T) { tests := []struct { name string input string expected string }{ {"already a slug", "hello-world", "hello-world"}, {"mixed case", "Hello World", "hello-world"}, {"punctuation", "What's new?", "what-s-new"}, {"run of separators", "one --- two", "one-two"}, {"leading separators", "///one", "one"}, {"trailing separators", "one///", "one"}, {"separators at both ends", " --one two-- ", "one-two"}, {"digits are kept", "Go 1.14 release", "go-1-14-release"}, {"underscores are separators", "some_name_here", "some-name-here"}, {"nothing usable", "!!! ???", ""}, {"empty string", "", ""}, {"outside ascii", "Grüße, Welt", "gr-e-welt"}, {"only characters outside ascii", "日本語", ""}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { got := Slugify(test.input) if got != test.expected { t.Errorf("expected %q got %q", test.expected, got) } }) } }