Skip to content

Commit

Permalink
fix(gen): making the first letter upper case on snake case (#20)
Browse files Browse the repository at this point in the history
first letter
  • Loading branch information
Jacobbrewer1 authored Oct 16, 2024
1 parent cc432ae commit babf9b2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/services/generation/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func nonIdentityColumns(t *models.Table) []*models.Column {
// by following golint conventions
func structify(s string) string {
s = xstrings.ToCamelCase(s)

// Capitalize the first letter
s = xstrings.FirstRuneToUpper(s)

return s
}

Expand Down
45 changes: 45 additions & 0 deletions pkg/services/generation/template_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package generation

import "testing"

func TestStructify(t *testing.T) {
tests := []struct {
name string
in string
want string
}{
{
name: "snake_case",
in: "snake_case",
want: "SnakeCase",
},
{
name: "snake_case_with_underscores",
in: "snake_case_with_underscores",
want: "SnakeCaseWithUnderscores",
},
{
name: "snake_case_with_underscores_and_numbers_123",
in: "snake_case_with_underscores_and_numbers_123",
want: "SnakeCaseWithUnderscoresAndNumbers123",
},
{
name: "snake_case_with_underscores_and_numbers_123_and_underscores",
in: "snake_case_with_underscores_and_numbers_123_and_underscores",
want: "SnakeCaseWithUnderscoresAndNumbers123AndUnderscores",
},
{
name: "single",
in: "single",
want: "Single",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := structify(tt.in); got != tt.want {
t.Errorf("structify() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit babf9b2

Please sign in to comment.