Skip to content

Commit

Permalink
added Tableize
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Jul 28, 2018
1 parent 34fcb09 commit 2006683
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tablize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package flect

// Tableize returns an underscore, pluralized string
// User = users
// Person = persons
// Admin/Widget = admin_widgets
func Tableize(s string) string {
return New(s).Tableize()
}

// Tableize returns an underscore, pluralized string
// User = users
// Person = persons
// Admin/Widget = admin_widgets
func (i Ident) Tableize() string {
return Underscore(i.Pluralize())
}
35 changes: 35 additions & 0 deletions tablize_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package flect

import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_Tableize(t *testing.T) {
table := []tt{
{"", ""},
{"bob dylan", "bob_dylans"},
{"Nice to see you!", "nice_to_see_yous"},
{"*hello*", "hellos"},
{"i've read a book! have you?", "ive_read_a_book_have_yous"},
{"This is `code` ok", "this_is_code_oks"},
{"foo_bar", "foo_bars"},
{"admin/widget", "admin_widgets"},
{"widget", "widgets"},
{"widgets", "widgets"},
{"status", "statuses"},
{"Statuses", "statuses"},
{"statuses", "statuses"},
{"People", "people"},
{"people", "people"},
}

for _, tt := range table {
t.Run(tt.act, func(st *testing.T) {
r := require.New(st)
r.Equal(tt.exp, Tableize(tt.act))
r.Equal(tt.exp, Tableize(tt.exp))
})
}
}

0 comments on commit 2006683

Please sign in to comment.