tpl: Consolidate and complete the Inflect tests

This commit is contained in:
Bjørn Erik Pedersen 2016-02-07 14:37:04 +01:00
parent 1e8b4d9cde
commit ec49dbb8f5

View file

@ -1533,32 +1533,28 @@ func TestChomp(t *testing.T) {
} }
} }
func TestHumanize(t *testing.T) { func TestInflect(t *testing.T) {
for i, this := range []struct { for i, this := range []struct {
in, expect interface{} inflectFunc func(i interface{}) (string, error)
in string
expected string
}{ }{
{"MyCamelPost", "My camel post"}, {humanize, "MyCamel", "My camel"},
{"myLowerCamelPost", "My lower camel post"}, {pluralize, "cat", "cats"},
{"my-dash-post", "My dash post"}, {singularize, "cats", "cat"},
{"my_underscore_post", "My underscore post"},
{"posts/my-first-post", "Posts/my first post"},
{tstNoStringer{}, false},
} { } {
result, err := humanize(this.in) result, err := this.inflectFunc(this.in)
if b, ok := this.expect.(bool); ok && !b { if err != nil {
if err == nil { t.Errorf("[%d] Unexpected Inflect error: %s", i, err)
t.Errorf("[%d] Humanize didn't return an expected error", i) } else if result != this.expected {
} t.Errorf("[%d] Inflect method error, got %v expected %v", i, result, this.expected)
} else { }
if err != nil {
t.Errorf("[%d] failed: %s", i, err) _, err = this.inflectFunc(t)
continue if err == nil {
} t.Errorf("[%d] Expected Inflect error", i)
if result != this.expect {
t.Errorf("[%d] Humanize got %v but expected %v", i, result, this.expect)
}
} }
} }
} }