mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
tpl: Complete coverage for Humanize
This commit is contained in:
parent
7c3dceeaed
commit
b3a70abe40
1 changed files with 20 additions and 5 deletions
|
@ -1523,18 +1523,33 @@ func TestChomp(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHumanize(t *testing.T) {
|
func TestHumanize(t *testing.T) {
|
||||||
for _, e := range []struct {
|
for i, this := range []struct {
|
||||||
in, exp string
|
in, expect interface{}
|
||||||
}{
|
}{
|
||||||
{"MyCamelPost", "My camel post"},
|
{"MyCamelPost", "My camel post"},
|
||||||
{"myLowerCamelPost", "My lower camel post"},
|
{"myLowerCamelPost", "My lower camel post"},
|
||||||
{"my-dash-post", "My dash post"},
|
{"my-dash-post", "My dash post"},
|
||||||
{"my_underscore_post", "My underscore post"},
|
{"my_underscore_post", "My underscore post"},
|
||||||
{"posts/my-first-post", "Posts/my first post"},
|
{"posts/my-first-post", "Posts/my first post"},
|
||||||
|
{tstNoStringer{}, false},
|
||||||
} {
|
} {
|
||||||
res, err := Humanize(e.in)
|
|
||||||
assert.Nil(t, err)
|
result, err := Humanize(this.in)
|
||||||
assert.Equal(t, e.exp, res)
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue