Skip to content

Commit

Permalink
removed deprecated strings.Title(), updated test cases and benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Jan 6, 2023
1 parent 2466a05 commit 7d1eabd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
10 changes: 3 additions & 7 deletions humanize.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ func (i Ident) Humanize() Ident {
return New("")
}

var parts []string
for index, part := range i.Parts {
if index == 0 {
part = strings.Title(i.Parts[0])
}

parts = xappend(parts, part)
parts := xappend([]string{}, Titleize(i.Parts[0]))
if len(i.Parts) > 1 {
parts = xappend(parts, i.Parts[1:]...)
}

return New(strings.Join(parts, " "))
Expand Down
3 changes: 3 additions & 0 deletions humanize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (
func Test_Humanize(t *testing.T) {
table := []tt{
{"", ""},
{"id", "ID"},
{"url", "URL"},
{"IBM", "IBM"},
{"CAUTION! CAPs are CAPs!", "CAUTION! CAPs are CAPs!"},
{"employee_mobile_number", "Employee mobile number"},
{"employee_salary", "Employee salary"},
{"employee_id", "Employee ID"},
Expand Down
11 changes: 11 additions & 0 deletions pluralize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ func Test_PluralizeWithSize(t *testing.T) {
})
}
}

func BenchmarkPluralize(b *testing.B) {
for n := 0; n < b.N; n++ {
for _, tt := range singlePluralAssertions {
if tt.doPluralizeTest {
Pluralize(tt.singular)
Pluralize(tt.plural)
}
}
}
}
11 changes: 11 additions & 0 deletions singularize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ func Test_SingularizeWithSize(t *testing.T) {
})
}
}

func BenchmarkSingularize(b *testing.B) {
for n := 0; n < b.N; n++ {
for _, tt := range singlePluralAssertions {
if tt.doSingularizeTest {
Singularize(tt.singular)
Singularize(tt.plural)
}
}
}
}

0 comments on commit 7d1eabd

Please sign in to comment.