summaryrefslogtreecommitdiffstats
path: root/tpl/inflect/inflect_test.go
blob: 083e7da4e96a2f5985d16067f339a937897b4540 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package inflect

import (
	"testing"

	qt "github.com/frankban/quicktest"
)

func TestInflect(t *testing.T) {
	t.Parallel()
	c := qt.New(t)

	ns := New()

	for _, test := range []struct {
		fn     func(i any) (string, error)
		in     any
		expect any
	}{
		{ns.Humanize, "MyCamel", "My camel"},
		{ns.Humanize, "óbito", "Óbito"},
		{ns.Humanize, "", ""},
		{ns.Humanize, "103", "103rd"},
		{ns.Humanize, "41", "41st"},
		{ns.Humanize, 103, "103rd"},
		{ns.Humanize, int64(92), "92nd"},
		{ns.Humanize, "5.5", "5.5"},
		{ns.Humanize, t, false},
		{ns.Humanize, "this is a TEST", "This is a test"},
		{ns.Humanize, "my-first-Post", "My first post"},
		{ns.Pluralize, "cat", "cats"},
		{ns.Pluralize, "", ""},
		{ns.Pluralize, t, false},
		{ns.Singularize, "cats", "cat"},
		{ns.Singularize, "", ""},
		{ns.Singularize, t, false},
	} {

		result, err := test.fn(test.in)

		if b, ok := test.expect.(bool); ok && !b {
			c.Assert(err, qt.Not(qt.IsNil))
			continue
		}

		c.Assert(err, qt.IsNil)
		c.Assert(result, qt.Equals, test.expect)
	}
}