Skip to content

Commit

Permalink
added VarCase and clean up some code
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Feb 5, 2019
1 parent a62e61d commit b2cb381
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMe
github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk=
github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dustin/go-humanize v0.0.0-20180713052910-9f541cc9db5d/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down Expand Up @@ -34,6 +35,7 @@ github.com/gobuffalo/envy v1.6.7/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9k
github.com/gobuffalo/envy v1.6.8/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ=
github.com/gobuffalo/envy v1.6.9/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ=
github.com/gobuffalo/envy v1.6.10/go.mod h1:X0CFllQjTV5ogsnUrg+Oks2yTI+PU2dGYBJOEI2D1Uo=
github.com/gobuffalo/envy v1.6.11 h1:dCKSFypLRvqaaUtyzkfKKF2j35ce5agsqfyIrRmm02E=
github.com/gobuffalo/envy v1.6.11/go.mod h1:Fiq52W7nrHGDggFPhn2ZCcHw4u/rqXkqo+i7FB6EAcg=
github.com/gobuffalo/events v1.0.3/go.mod h1:Txo8WmqScapa7zimEQIwgiJBvMECMe9gJjsKNPN3uZw=
github.com/gobuffalo/events v1.0.7/go.mod h1:z8txf6H9jWhQ5Scr7YPLWg/cgXBRj8Q4uYI+rsVCCSQ=
Expand Down Expand Up @@ -170,6 +172,7 @@ github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80s
github.com/jackc/pgx v3.2.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
github.com/jmoiron/sqlx v0.0.0-20180614180643-0dae4fefe7c0/go.mod h1:IiEW3SEiiErVyFdH8NTuWjSifiEQKUoyK3LNqr2kCHU=
github.com/joho/godotenv v1.2.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/karrick/godirwalk v1.7.5/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34=
github.com/karrick/godirwalk v1.7.7/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34=
Expand Down Expand Up @@ -216,7 +219,9 @@ github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.0.0 h1:o4VLZ5jqHE+HahLT6drNtSGTrrUA3wPBmtpgqtdbClo=
github.com/rogpeppe/go-internal v1.0.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs=
Expand Down
3 changes: 0 additions & 3 deletions ident.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package flect

import (
"encoding"
"regexp"
"strings"
"unicode"
"unicode/utf8"
Expand All @@ -29,8 +28,6 @@ func New(s string) Ident {
return i
}

var splitRx = regexp.MustCompile("[^\\p{L}]")

func toParts(s string) []string {
parts := []string{}
s = strings.TrimSpace(s)
Expand Down
2 changes: 1 addition & 1 deletion name/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
)

var alphanum = regexp.MustCompile("[^a-zA-Z0-9_\\-\\/]+")
var alphanum = regexp.MustCompile(`[^a-zA-Z0-9_\-\/]+`)

// Folder creates a suitable folder name
// admin/widget = admin/widget
Expand Down
9 changes: 0 additions & 9 deletions name/name_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package name

import (
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -83,10 +81,3 @@ func Test_MarshalText(t *testing.T) {
r.NoError((&n).UnmarshalText([]byte("bates")))
r.Equal("bates", n.String())
}

func osify(s string) string {
if runtime.GOOS == "windows" {
return strings.Replace(s, "/", "\\", -1)
}
return s
}
16 changes: 16 additions & 0 deletions name/var_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ func VarCasePlural(s string) string {
func (i Ident) VarCasePlural() Ident {
return Ident{i.Group().Pluralize().Camelize()}
}

// VarCase version of a name.
// foo_bar = fooBar
// admin/widget = adminWidget
// Users = users
func (i Ident) VarCase() Ident {
return Ident{i.Camelize()}
}

// VarCase version of a name.
// foo_bar = fooBar
// admin/widget = adminWidget
// Users = users
func VarCase(s string) string {
return New(s).VarCase().String()
}
24 changes: 24 additions & 0 deletions name/var_case_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,27 @@ func Test_VarCasePlural(t *testing.T) {
})
}
}

func Test_VarCase(t *testing.T) {
table := []tt{
{"foo_bar", "fooBar"},
{"admin/widget", "adminWidget"},
{"widget", "widget"},
{"widgets", "widgets"},
{"User", "user"},
{"FooBar", "fooBar"},
{"FooBars", "fooBars"},
{"status", "status"},
{"statuses", "statuses"},
{"Status", "status"},
{"Statuses", "statuses"},
}

for _, tt := range table {
t.Run(tt.act, func(st *testing.T) {
r := require.New(st)
r.Equal(tt.exp, VarCase(tt.act))
r.Equal(tt.exp, VarCase(tt.exp))
})
}
}
3 changes: 1 addition & 2 deletions titleize.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ func Titleize(s string) string {
func (i Ident) Titleize() Ident {
var parts []string
for _, part := range i.Parts {
var x string
x = string(unicode.ToTitle(rune(part[0])))
x := string(unicode.ToTitle(rune(part[0])))
if len(part) > 1 {
x += part[1:]
}
Expand Down

0 comments on commit b2cb381

Please sign in to comment.