...

Source file src/github.com/gobuffalo/flect/name/name_test.go

Documentation: github.com/gobuffalo/flect/name

     1  package name
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  type tt struct {
    10  	act string
    11  	exp string
    12  }
    13  
    14  func Test_Name(t *testing.T) {
    15  	table := []tt{
    16  		{"", ""},
    17  		{"bob dylan", "BobDylan"},
    18  		{"widgetID", "WidgetID"},
    19  		{"widget_ID", "WidgetID"},
    20  		{"Widget_ID", "WidgetID"},
    21  		{"Widget_Id", "WidgetID"},
    22  		{"Widget_id", "WidgetID"},
    23  		{"Nice to see you today!", "NiceToSeeYouToday"},
    24  		{"*hello*", "Hello"},
    25  		{"i've read a book! have you read it?", "IveReadABookHaveYouReadIt"},
    26  		{"This is `code` ok", "ThisIsCodeOK"},
    27  		{"foo_bar", "FooBar"},
    28  		{"admin/widget", "AdminWidget"},
    29  		{"admin/widgets", "AdminWidget"},
    30  		{"widget", "Widget"},
    31  		{"widgets", "Widget"},
    32  		{"status", "Status"},
    33  		{"Statuses", "Status"},
    34  		{"statuses", "Status"},
    35  		{"People", "Person"},
    36  		{"people", "Person"},
    37  	}
    38  
    39  	for _, tt := range table {
    40  		t.Run(tt.act, func(st *testing.T) {
    41  			r := require.New(st)
    42  			r.Equal(tt.exp, Proper(tt.act))
    43  			r.Equal(tt.exp, Proper(tt.exp))
    44  		})
    45  	}
    46  }
    47  
    48  func Test_Group(t *testing.T) {
    49  	table := []tt{
    50  		{"", ""},
    51  		{"Person", "People"},
    52  		{"foo_bar", "FooBars"},
    53  		{"admin/widget", "AdminWidgets"},
    54  		{"widget", "Widgets"},
    55  		{"widgets", "Widgets"},
    56  		{"greatPerson", "GreatPeople"},
    57  		{"great/person", "GreatPeople"},
    58  		{"status", "Statuses"},
    59  		{"Status", "Statuses"},
    60  		{"Statuses", "Statuses"},
    61  		{"statuses", "Statuses"},
    62  	}
    63  
    64  	for _, tt := range table {
    65  		t.Run(tt.act, func(st *testing.T) {
    66  			r := require.New(st)
    67  			r.Equal(tt.exp, Group(tt.act))
    68  			r.Equal(tt.exp, Group(tt.exp))
    69  		})
    70  	}
    71  }
    72  
    73  func Test_MarshalText(t *testing.T) {
    74  	r := require.New(t)
    75  
    76  	n := New("mark")
    77  	b, err := n.MarshalText()
    78  	r.NoError(err)
    79  	r.Equal("mark", string(b))
    80  
    81  	r.NoError((&n).UnmarshalText([]byte("bates")))
    82  	r.Equal("bates", n.String())
    83  }
    84  

View as plain text