diff --git a/pkg/util/slug.go b/pkg/util/slug.go index 4d2aaf1..9bca23a 100644 --- a/pkg/util/slug.go +++ b/pkg/util/slug.go @@ -12,8 +12,11 @@ func Slugify(input string, namingStyle string) string { if namingStyle == "lowercase" { return strings.ToLower(input) } else if namingStyle == "slug" || namingStyle == "" { - s := slug.Make(input) - return strings.ToLower(s) + parts := strings.Split(input, "/") + for i, part := range parts { + parts[i] = slug.Make(part) + } + return strings.Join(parts, "/") } else if namingStyle == "name" { return input } diff --git a/pkg/util/slug_test.go b/pkg/util/slug_test.go new file mode 100644 index 0000000..11f43d6 --- /dev/null +++ b/pkg/util/slug_test.go @@ -0,0 +1,33 @@ +package util + +import ( + "testing" + + "github.com/gosimple/slug" +) + +func TestSlugify(t *testing.T) { + testCases := []struct { + input string + namingStyle string + expectedOutput string + }{ + {"Hello World", "lowercase", "hello world"}, + {"Hello World", "slug", "hello-world"}, + {"Hello World/My Project", "slug", "hello-world/my-project"}, + {"Hello World", "name", "Hello World"}, + + // Test case for empty naming style, defaulting to slug + {"Hello World", "", slug.Make("Hello World")}, + } + + for _, tc := range testCases { + t.Run(tc.namingStyle, func(t *testing.T) { + result := Slugify(tc.input, tc.namingStyle) + + if result != tc.expectedOutput { + t.Errorf("Expected %s, but got %s", tc.expectedOutput, result) + } + }) + } +}