Skip to content

Commit

Permalink
Merge branch 'master' into multiword-idents
Browse files Browse the repository at this point in the history
  • Loading branch information
paganotoni authored Aug 27, 2020
2 parents a7e5361 + 222210e commit dfc61c7
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 351 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: markbates
patreon: buffalo
22 changes: 22 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Tests
on: [push]
jobs:

tests-on:
name: ${{matrix.go-version}} ${{matrix.os}}
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.12.x, 1.13.x]
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- name: Checkout Code
uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Test
run: |
go mod tidy -v
go test -race ./...
71 changes: 0 additions & 71 deletions azure-pipelines.yml

This file was deleted.

19 changes: 0 additions & 19 deletions azure-tests.yml

This file was deleted.

6 changes: 6 additions & 0 deletions flect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ var singlePluralAssertions = []tt{
{"prize", "prizes"},
{"edge", "edges"},
{"database", "databases"},
{"circus", "circuses"},
{"plus", "pluses"},
{"fuse", "fuses"},
{"prometheus", "prometheuses"},
{"field", "fields"},
{"custom_field", "custom_fields"},
}

var pluralSingularAssertions = []tt{}
Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module github.com/gobuffalo/flect

go 1.12
go 1.13

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/stretchr/testify v1.3.0
)
require github.com/stretchr/testify v1.4.0
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
29 changes: 16 additions & 13 deletions ident.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func toParts(s string) []string {
return []string{strings.ToUpper(s)}
}
var prev rune
var x string
var x strings.Builder
x.Grow(len(s))
for _, c := range s {
cs := string(c)
// fmt.Println("### cs ->", cs)
// fmt.Println("### unicode.IsControl(c) ->", unicode.IsControl(c))
// fmt.Println("### unicode.IsDigit(c) ->", unicode.IsDigit(c))
Expand All @@ -58,35 +58,38 @@ func toParts(s string) []string {
}

if isSpace(c) {
parts = xappend(parts, x)
x = cs
parts = xappend(parts, x.String())
x.Reset()
x.WriteRune(c)
prev = c
continue
}

if unicode.IsUpper(c) && !unicode.IsUpper(prev) {
parts = xappend(parts, x)
x = cs
parts = xappend(parts, x.String())
x.Reset()
x.WriteRune(c)
prev = c
continue
}
if unicode.IsUpper(c) && baseAcronyms[strings.ToUpper(x)] {
parts = xappend(parts, x)
x = cs
if unicode.IsUpper(c) && baseAcronyms[strings.ToUpper(x.String())] {
parts = xappend(parts, x.String())
x.Reset()
x.WriteRune(c)
prev = c
continue
}
if unicode.IsLetter(c) || unicode.IsDigit(c) || unicode.IsPunct(c) || c == '`' {
prev = c
x += cs
x.WriteRune(c)
continue
}

parts = xappend(parts, x)
x = ""
parts = xappend(parts, x.String())
x.Reset()
prev = c
}
parts = xappend(parts, x)
parts = xappend(parts, x.String())

return parts
}
Expand Down
46 changes: 46 additions & 0 deletions ident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,49 @@ func Test_MarshalText(t *testing.T) {
r.NoError((&n).UnmarshalText([]byte("bates")))
r.Equal("bates", n.String())
}

func Benchmark_New(b *testing.B) {

table := []string{
"",
"widget",
"widget_id",
"WidgetID",
"Widget_ID",
"widget_ID",
"widget/ID",
"widgetID",
"widgetName",
"JWTName",
"JWTname",
"jwtname",
"sql",
"sQl",
"id",
"Id",
"iD",
"html",
"Html",
"HTML",
"with `code` inside",
"Donald E. Knuth",
"Random text with *(bad)* characters",
"Allow_Under_Scores",
"Trailing bad characters!@#",
"!@#Leading bad characters",
"Squeeze separators",
"Test with + sign",
"Malmö",
"Garçons",
"Opsů",
"Ærøskøbing",
"Aßlar",
"Japanese: 日本語",
}

for n := 0; n < b.N; n++ {
for i := range table {
New(table[i])
}
}
}
4 changes: 2 additions & 2 deletions name/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func Test_Name(t *testing.T) {
{"Widget_ID", "WidgetID"},
{"Widget_Id", "WidgetID"},
{"Widget_id", "WidgetID"},
{"Nice to see you!", "NiceToSeeYou"},
{"Nice to see you today!", "NiceToSeeYouToday"},
{"*hello*", "Hello"},
{"i've read a book! have you?", "IveReadABookHaveYou"},
{"i've read a book! have you read it?", "IveReadABookHaveYouReadIt"},
{"This is `code` ok", "ThisIsCodeOK"},
{"foo_bar", "FooBar"},
{"admin/widget", "AdminWidget"},
Expand Down
4 changes: 2 additions & 2 deletions name/tablize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ func Test_Tableize(t *testing.T) {
table := []tt{
{"", ""},
{"bob dylan", "bob_dylans"},
{"Nice to see you!", "nice_to_see_yous"},
{"Nice to see you!", "nice_to_see_you"},
{"*hello*", "hellos"},
{"i've read a book! have you?", "ive_read_a_book_have_yous"},
{"i've read a book! have you?", "ive_read_a_book_have_you"},
{"This is `code` ok", "this_is_code_oks"},
{"foo_bar", "foo_bars"},
{"admin/widget", "admin_widgets"},
Expand Down
Loading

0 comments on commit dfc61c7

Please sign in to comment.