github.com/kristoff-it/hugo@v0.47.1/tpl/inflect/inflect_test.go (about)

     1  package inflect
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestInflect(t *testing.T) {
    12  	t.Parallel()
    13  
    14  	ns := New()
    15  
    16  	for i, test := range []struct {
    17  		fn     func(i interface{}) (string, error)
    18  		in     interface{}
    19  		expect interface{}
    20  	}{
    21  		{ns.Humanize, "MyCamel", "My camel"},
    22  		{ns.Humanize, "óbito", "Óbito"},
    23  		{ns.Humanize, "", ""},
    24  		{ns.Humanize, "103", "103rd"},
    25  		{ns.Humanize, "41", "41st"},
    26  		{ns.Humanize, 103, "103rd"},
    27  		{ns.Humanize, int64(92), "92nd"},
    28  		{ns.Humanize, "5.5", "5.5"},
    29  		{ns.Humanize, t, false},
    30  		{ns.Pluralize, "cat", "cats"},
    31  		{ns.Pluralize, "", ""},
    32  		{ns.Pluralize, t, false},
    33  		{ns.Singularize, "cats", "cat"},
    34  		{ns.Singularize, "", ""},
    35  		{ns.Singularize, t, false},
    36  	} {
    37  		errMsg := fmt.Sprintf("[%d] %v", i, test)
    38  
    39  		result, err := test.fn(test.in)
    40  
    41  		if b, ok := test.expect.(bool); ok && !b {
    42  			require.Error(t, err, errMsg)
    43  			continue
    44  		}
    45  
    46  		require.NoError(t, err, errMsg)
    47  		assert.Equal(t, test.expect, result, errMsg)
    48  	}
    49  }