forked from alecthomas/kingpin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usage_test.go
65 lines (56 loc) · 1.48 KB
/
usage_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package kingpin
import (
"bytes"
"strings"
"testing"
"github.com/alecthomas/assert"
)
func TestFormatTwoColumns(t *testing.T) {
buf := bytes.NewBuffer(nil)
formatTwoColumns(buf, 2, 2, 20, [][2]string{
{"--hello", "Hello world help with something that is cool."},
})
expected := ` --hello Hello
world
help with
something
that is
cool.
`
assert.Equal(t, expected, buf.String())
}
func TestFormatTwoColumnsWide(t *testing.T) {
samples := [][2]string{
{strings.Repeat("x", 29), "29 chars"},
{strings.Repeat("x", 30), "30 chars"}}
buf := bytes.NewBuffer(nil)
formatTwoColumns(buf, 0, 0, 200, samples)
expected := `xxxxxxxxxxxxxxxxxxxxxxxxxxxxx29 chars
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
30 chars
`
assert.Equal(t, expected, buf.String())
}
func TestHiddenCommand(t *testing.T) {
templates := []struct{ name, template string }{
{"default", DefaultUsageTemplate},
{"Compact", CompactUsageTemplate},
{"Long", LongHelpTemplate},
{"Man", ManPageTemplate},
}
var buf bytes.Buffer
t.Log("1")
a := New("test", "Test").Writer(&buf).Terminate(nil)
a.Command("visible", "visible")
a.Command("hidden", "hidden").Hidden()
for _, tp := range templates {
buf.Reset()
a.UsageTemplate(tp.template)
a.Parse(nil)
// a.Parse([]string{"--help"})
usage := buf.String()
t.Logf("Usage for %s is:\n%s\n", tp.name, usage)
assert.NotContains(t, usage, "hidden")
assert.Contains(t, usage, "visible")
}
}