spf13--cobra/cobra_test.go

23 lines
547 B
Go
Raw Normal View History

package cobra
2013-09-03 22:54:51 +00:00
import (
"testing"
"text/template"
2013-09-03 22:54:51 +00:00
)
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 18:58:37 +00:00
const expected = "Hello, world."
if got := c.UsageString(); got != expected {
t.Errorf("Expected UsageString: %v\nGot: %v", expected, got)
}
}