2013-09-24 21:04:00 +00:00
|
|
|
package cobra
|
2013-09-03 22:54:51 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-09-01 03:36:55 +00:00
|
|
|
"text/template"
|
2013-09-03 22:54:51 +00:00
|
|
|
)
|
|
|
|
|
2015-09-01 03:36:55 +00:00
|
|
|
func TestAddTemplateFunctions(t *testing.T) {
|
|
|
|
AddTemplateFunc("t", func() bool { return true })
|
|
|
|
AddTemplateFuncs(template.FuncMap{
|
2015-09-04 20:34:51 +00:00
|
|
|
"f": func() bool { return false },
|
|
|
|
"h": func() string { return "Hello," },
|
2015-09-01 03:36:55 +00:00
|
|
|
"w": func() string { return "world." }})
|
|
|
|
|
|
|
|
c := &Command{}
|
|
|
|
c.SetUsageTemplate(`{{if t}}{{h}}{{end}}{{if f}}{{h}}{{end}} {{w}}`)
|
2015-09-04 20:34:51 +00:00
|
|
|
|
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)
|
2017-04-05 16:44:50 +00:00
|
|
|
}
|
|
|
|
}
|