1package cobra
2
3import (
4	"testing"
5	"text/template"
6)
7
8func assertNoErr(t *testing.T, e error) {
9	if e != nil {
10		t.Error(e)
11	}
12}
13
14func TestAddTemplateFunctions(t *testing.T) {
15	AddTemplateFunc("t", func() bool { return true })
16	AddTemplateFuncs(template.FuncMap{
17		"f": func() bool { return false },
18		"h": func() string { return "Hello," },
19		"w": func() string { return "world." }})
20
21	c := &Command{}
22	c.SetUsageTemplate(`{{if t}}{{h}}{{end}}{{if f}}{{h}}{{end}} {{w}}`)
23
24	const expected = "Hello, world."
25	if got := c.UsageString(); got != expected {
26		t.Errorf("Expected UsageString: %v\nGot: %v", expected, got)
27	}
28}
29