From 7d1eabdb28cfb15d3380ca9f45a6e30b9fda6fe1 Mon Sep 17 00:00:00 2001 From: Yonghwan SO Date: Sat, 7 Jan 2023 03:25:38 +0900 Subject: [PATCH] removed deprecated strings.Title(), updated test cases and benchmarks --- humanize.go | 10 +++------- humanize_test.go | 3 +++ pluralize_test.go | 11 +++++++++++ singularize_test.go | 11 +++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/humanize.go b/humanize.go index 6a0b75a..311c8be 100644 --- a/humanize.go +++ b/humanize.go @@ -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, " ")) diff --git a/humanize_test.go b/humanize_test.go index d507b52..b2a963a 100644 --- a/humanize_test.go +++ b/humanize_test.go @@ -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"}, diff --git a/pluralize_test.go b/pluralize_test.go index dbf6a90..0ec507c 100644 --- a/pluralize_test.go +++ b/pluralize_test.go @@ -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) + } + } + } +} diff --git a/singularize_test.go b/singularize_test.go index f28f35d..86f04c7 100644 --- a/singularize_test.go +++ b/singularize_test.go @@ -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) + } + } + } +}