1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
package strcase
import (
"testing"
)
func TestToKebabCase(t *testing.T) {
cases := []struct {
in string
want string
}{
{"testCase", "test-case"},
{"TestCase", "test-case"},
{"Test Case", "test-case"},
{" Test Case", "test-case"},
{"Test Case ", "test-case"},
{" Test Case ", "test-case"},
{"test", "test"},
{"test_case", "test-case"},
{"Test", "test"},
{"", ""},
{"ManyManyWords", "many-many-words"},
{"manyManyWords", "many-many-words"},
{"AnyKind of_string", "any-kind-of-string"},
{"numbers2and55with000", "numbers2and55with000"},
{"JSONData", "json-data"},
{"userID", "user-id"},
{"AAAbbb", "aa-abbb"},
}
for _, c := range cases {
t.Run(c.in, func(t *testing.T) {
got := toKebab(c.in)
if got != c.want {
t.Errorf("toKebab(%q) == %q, want %q", c.in, got, c.want)
}
})
}
}
|