Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ func (g *Generator) Generate() (string, error) {
return strings.Join(g.applyCasing(words), g.delimiter), nil
}

var titleCaser = cases.Title(language.English)

func (g *Generator) applyCasing(words []string) []string {
for i, word := range words {
switch g.casing {
Expand All @@ -149,7 +147,7 @@ func (g *Generator) applyCasing(words []string) []string {
case Upper:
words[i] = strings.ToUpper(word)
case Title:
words[i] = titleCaser.String(word)
words[i] = cases.Title(language.English).String(word)
}
}
return words
Expand Down
45 changes: 45 additions & 0 deletions generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,51 @@ func TestWithDictionary(t *testing.T) {
}
}

func TestGenerateTitleConcurrent(t *testing.T) {
testCases := []struct {
name string
adjective string
noun string
want string
}{
{
name: "mixed case and hyphen",
adjective: "hAPPY",
noun: "t-shirt",
want: "Happy-T-Shirt",
},
{
name: "apostrophe and underscore",
adjective: "don't",
noun: "foo_bar",
want: "Don't-Foo_bar",
},
{
name: "unicode",
adjective: "ßeta",
noun: "ΟΣ",
want: "Sseta-Ος",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
dict := NewCustomDictionary([]string{tc.adjective}, nil, []string{tc.noun}, nil)
g := NewGenerator(WithDictionary(dict), WithCasing(Title), WithSeed(1))
for i := 0; i < 100; i++ {
got, err := g.Generate()
if err != nil {
t.Fatal(err)
}
if got != tc.want {
t.Fatalf("Generate() = %q, want %q", got, tc.want)
}
}
})
}
}

func TestCasingFromString(t *testing.T) {
t.Log("Given the need to parse casing strings")
{
Expand Down
Loading