| 1 |
package inflect |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
qt "github.com/frankban/quicktest" |
| 7 |
) |
| 8 |
|
| 9 |
func TestInflect(t *testing.T) { |
| 10 |
t.Parallel() |
| 11 |
c := qt.New(t) |
| 12 |
|
| 13 |
ns := New() |
| 14 |
|
| 15 |
for _, test := range []struct { |
| 16 |
fn func(i any) (string, error) |
| 17 |
in any |
| 18 |
expect any |
| 19 |
}{ |
| 20 |
{ns.Humanize, "MyCamel", "My camel"}, |
| 21 |
{ns.Humanize, "óbito", "Óbito"}, |
| 22 |
{ns.Humanize, "", ""}, |
| 23 |
{ns.Humanize, "103", "103rd"}, |
| 24 |
{ns.Humanize, "41", "41st"}, |
| 25 |
{ns.Humanize, 103, "103rd"}, |
| 26 |
{ns.Humanize, int64(92), "92nd"}, |
| 27 |
{ns.Humanize, "5.5", "5.5"}, |
| 28 |
{ns.Humanize, t, false}, |
| 29 |
{ns.Humanize, "this is a TEST", "This is a test"}, |
| 30 |
{ns.Humanize, "my-first-Post", "My first post"}, |
| 31 |
{ns.Pluralize, "cat", "cats"}, |
| 32 |
{ns.Pluralize, "", ""}, |
| 33 |
{ns.Pluralize, t, false}, |
| 34 |
{ns.Singularize, "cats", "cat"}, |
| 35 |
{ns.Singularize, "", ""}, |
| 36 |
{ns.Singularize, t, false}, |
| 37 |
} { |
| 38 |
|
| 39 |
result, err := test.fn(test.in) |
| 40 |
|
| 41 |
if b, ok := test.expect.(bool); ok && !b { |
| 42 |
c.Assert(err, qt.Not(qt.IsNil)) |
| 43 |
continue |
| 44 |
} |
| 45 |
|
| 46 |
c.Assert(err, qt.IsNil) |
| 47 |
c.Assert(result, qt.Equals, test.expect) |
| 48 |
} |
| 49 |
} |