MCPcopy
hub / github.com/spf13/cobra / TestAddTemplateFunctions

Function TestAddTemplateFunctions

cobra_test.go:33–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestAddTemplateFunctions(t *testing.T) {
34 AddTemplateFunc("t", func() bool { return true })
35 AddTemplateFuncs(template.FuncMap{
36 "f": func() bool { return false },
37 "h": func() string { return "Hello," },
38 "w": func() string { return "world." }})
39
40 c := &Command{}
41 c.SetUsageTemplate(`{{if t}}{{h}}{{end}}{{if f}}{{h}}{{end}} {{w}}`)
42
43 const expected = "Hello, world."
44 if got := c.UsageString(); got != expected {
45 t.Errorf("Expected UsageString: %v\nGot: %v", expected, got)
46 }
47}
48
49func TestLevenshteinDistance(t *testing.T) {
50 tests := []struct {

Callers

nothing calls this directly

Calls 4

SetUsageTemplateMethod · 0.95
UsageStringMethod · 0.95
AddTemplateFuncFunction · 0.85
AddTemplateFuncsFunction · 0.85

Tested by

no test coverage detected