cobra/cobra_test.go

29 lines
623 B
Go
Raw Permalink Normal View History

package cobra
2013-09-04 02:54:51 +04:00
import (
"testing"
"text/template"
2013-09-04 02:54:51 +04:00
)
func assertNoErr(t *testing.T, e error) {
if e != nil {
t.Error(e)
}
}
func TestAddTemplateFunctions(t *testing.T) {
AddTemplateFunc("t", func() bool { return true })
AddTemplateFuncs(template.FuncMap{
"f": func() bool { return false },
"h": func() string { return "Hello," },
"w": func() string { return "world." }})
c := &Command{}
c.SetUsageTemplate(`{{if t}}{{h}}{{end}}{{if f}}{{h}}{{end}} {{w}}`)
2017-10-31 21:58:37 +03:00
const expected = "Hello, world."
if got := c.UsageString(); got != expected {
t.Errorf("Expected UsageString: %v\nGot: %v", expected, got)
}
}