Skip to content

Commit

Permalink
Add benchmark and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaksv committed Jan 31, 2021
1 parent b6019c9 commit c04ec3a
Showing 1 changed file with 47 additions and 40 deletions.
87 changes: 47 additions & 40 deletions strcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,43 @@ import (
"testing"
)

func BenchmarkToCamelCase(b *testing.B) {
b.Run("Foo Bar", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ToCamelCase("Foo Bar")
}
})
}

func BenchmarkToPascalCase(b *testing.B) {
b.Run("Foo Bar", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ToPascalCase("Foo Bar")
}
})
}
func BenchmarkToDotCase(b *testing.B) {
b.Run("Foo Bar", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ToDotCase("Foo Bar")
}
})
}
func BenchmarkToSnakeCase(b *testing.B) {
b.Run("Foo Bar", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ToSnakeCase("Foo Bar")
}
})
}
func BenchmarkToKebabCase(b *testing.B) {
b.Run("Foo Bar", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ToKebabCase("Foo Bar")
}
})
}

func TestToCamelCase(t *testing.T) {
type args struct {
str string
Expand Down Expand Up @@ -281,7 +318,7 @@ func TestParseString(t *testing.T) {
type args struct {
str string
}
want := []string{"field", "name"}

tests := []struct {
name string
args args
Expand All @@ -293,49 +330,19 @@ func TestParseString(t *testing.T) {
want: []string{"field", "name", "field", "name"},
},
{
name: "space(lower)",
args: args{str: "field name"},
want: want,
},
{
name: "space(upper)",
args: args{str: "FIELD NAME"},
want: want,
},
{
name: "snake_case(lower)",
args: args{str: "field_name"},
want: want,
},
{
name: "snake_case(upper)",
args: args{str: "FIELD_NAME"},
want: want,
},
{
name: "kebab-case(lower)",
args: args{str: "field-name"},
want: want,
name: "digit",
args: args{str: "field001"},
want: []string{"field001"},
},
{
name: "kebab-case(upper)",
args: args{str: "FIELD-NAME"},
want: want,
name: "digit2",
args: args{str: "field 001"},
want: []string{"field", "001"},
},
{
name: "PascalCase",
args: args{str: "FieldName"},
want: want,
},
{
name: "camelCase",
args: args{str: "fieldName"},
want: want,
},
{
name: "dotCase",
args: args{str: "field.Name"},
want: want,
name: "space",
args: args{str: " field name "},
want: []string{"field", "name"},
},
}
for _, tt := range tests {
Expand Down

0 comments on commit c04ec3a

Please sign in to comment.