2017-03-13 22:55:02 +00:00
|
|
|
package inflect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-08-10 19:05:17 +00:00
|
|
|
qt "github.com/frankban/quicktest"
|
2017-03-13 22:55:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInflect(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-08-10 19:05:17 +00:00
|
|
|
c := qt.New(t)
|
2017-03-13 22:55:02 +00:00
|
|
|
|
|
|
|
ns := New()
|
|
|
|
|
2019-08-10 19:05:17 +00:00
|
|
|
for _, test := range []struct {
|
2022-03-17 21:03:27 +00:00
|
|
|
fn func(i any) (string, error)
|
|
|
|
in any
|
|
|
|
expect any
|
2017-03-13 22:55:02 +00:00
|
|
|
}{
|
|
|
|
{ns.Humanize, "MyCamel", "My camel"},
|
2017-11-28 20:16:01 +00:00
|
|
|
{ns.Humanize, "óbito", "Óbito"},
|
2017-03-13 22:55:02 +00:00
|
|
|
{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},
|
2021-02-14 17:30:59 +00:00
|
|
|
{ns.Humanize, "this is a TEST", "This is a test"},
|
|
|
|
{ns.Humanize, "my-first-Post", "My first post"},
|
2017-03-13 22:55:02 +00:00
|
|
|
{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 {
|
2019-08-10 19:05:17 +00:00
|
|
|
c.Assert(err, qt.Not(qt.IsNil))
|
2017-03-13 22:55:02 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-08-10 19:05:17 +00:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(result, qt.Equals, test.expect)
|
2017-03-13 22:55:02 +00:00
|
|
|
}
|
|
|
|
}
|