-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package name | ||
|
||
// VarCaseSingle version of a name. | ||
// foo_bar = fooBar | ||
// admin/widget = adminWidget | ||
// User = users | ||
func VarCaseSingle(s string) string { | ||
return New(s).VarCaseSingle().String() | ||
} | ||
|
||
// VarCaseSingle version of a name. | ||
// foo_bar = fooBar | ||
// admin/widget = adminWidget | ||
// User = users | ||
func (i Ident) VarCaseSingle() Ident { | ||
return Ident{i.Group().Singularize().Camelize()} | ||
} | ||
|
||
// VarCasePlural version of a name. | ||
// foo_bar = fooBars | ||
// admin/widget = adminWidgets | ||
// User = users | ||
func VarCasePlural(s string) string { | ||
return New(s).VarCasePlural().String() | ||
} | ||
|
||
// VarCasePlural version of a name. | ||
// foo_bar = fooBars | ||
// admin/widget = adminWidgets | ||
// User = users | ||
func (i Ident) VarCasePlural() Ident { | ||
return Ident{i.Group().Pluralize().Camelize()} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package name | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_VarCaseSingle(t *testing.T) { | ||
table := []tt{ | ||
{"foo_bar", "fooBar"}, | ||
{"admin/widget", "adminWidget"}, | ||
{"widget", "widget"}, | ||
{"widgets", "widget"}, | ||
{"User", "user"}, | ||
{"FooBar", "fooBar"}, | ||
{"status", "status"}, | ||
{"statuses", "status"}, | ||
{"Status", "status"}, | ||
{"Statuses", "status"}, | ||
} | ||
|
||
for _, tt := range table { | ||
t.Run(tt.act, func(st *testing.T) { | ||
r := require.New(st) | ||
r.Equal(tt.exp, VarCaseSingle(tt.act)) | ||
r.Equal(tt.exp, VarCaseSingle(tt.exp)) | ||
}) | ||
} | ||
} | ||
|
||
func Test_VarCasePlural(t *testing.T) { | ||
table := []tt{ | ||
{"foo_bar", "fooBars"}, | ||
{"admin/widget", "adminWidgets"}, | ||
{"widget", "widgets"}, | ||
{"widgets", "widgets"}, | ||
{"User", "users"}, | ||
{"FooBar", "fooBars"}, | ||
{"status", "statuses"}, | ||
{"statuses", "statuses"}, | ||
{"Status", "statuses"}, | ||
{"Statuses", "statuses"}, | ||
} | ||
|
||
for _, tt := range table { | ||
t.Run(tt.act, func(st *testing.T) { | ||
r := require.New(st) | ||
r.Equal(tt.exp, VarCasePlural(tt.act)) | ||
r.Equal(tt.exp, VarCasePlural(tt.exp)) | ||
}) | ||
} | ||
} |