From ec49dbb8f50f7d00bd94136b6dad5d509cb62238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 7 Feb 2016 14:37:04 +0100 Subject: [PATCH] tpl: Consolidate and complete the Inflect tests --- tpl/template_funcs_test.go | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go index 447cf9569..cac729457 100644 --- a/tpl/template_funcs_test.go +++ b/tpl/template_funcs_test.go @@ -1533,32 +1533,28 @@ func TestChomp(t *testing.T) { } } -func TestHumanize(t *testing.T) { +func TestInflect(t *testing.T) { for i, this := range []struct { - in, expect interface{} + inflectFunc func(i interface{}) (string, error) + in string + expected string }{ - {"MyCamelPost", "My camel post"}, - {"myLowerCamelPost", "My lower camel post"}, - {"my-dash-post", "My dash post"}, - {"my_underscore_post", "My underscore post"}, - {"posts/my-first-post", "Posts/my first post"}, - {tstNoStringer{}, false}, + {humanize, "MyCamel", "My camel"}, + {pluralize, "cat", "cats"}, + {singularize, "cats", "cat"}, } { - result, err := humanize(this.in) + result, err := this.inflectFunc(this.in) - if b, ok := this.expect.(bool); ok && !b { - if err == nil { - t.Errorf("[%d] Humanize didn't return an expected error", i) - } - } else { - if err != nil { - t.Errorf("[%d] failed: %s", i, err) - continue - } - if result != this.expect { - t.Errorf("[%d] Humanize got %v but expected %v", i, result, this.expect) - } + if err != nil { + t.Errorf("[%d] Unexpected Inflect error: %s", i, err) + } else if result != this.expected { + t.Errorf("[%d] Inflect method error, got %v expected %v", i, result, this.expected) + } + + _, err = this.inflectFunc(t) + if err == nil { + t.Errorf("[%d] Expected Inflect error", i) } } }