forked from ipfs/go-ipfs-cmds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelptext_test.go
50 lines (47 loc) · 1.33 KB
/
helptext_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
package cli
import (
"strings"
"testing"
cmds "github.com/ipfs/go-ipfs-cmds"
)
func TestSynopsisGenerator(t *testing.T) {
command := &cmds.Command{
Arguments: []cmds.Argument{
cmds.StringArg("required", true, false, ""),
cmds.StringArg("variadic", false, true, ""),
},
Options: []cmds.Option{
cmds.StringOption("opt", "o", "Option"),
cmds.StringsOption("var-opt", "Variadic Option"),
},
Helptext: cmds.HelpText{
SynopsisOptionsValues: map[string]string{
"opt": "OPTION",
},
},
}
terminalWidth := 100
syn := generateSynopsis(terminalWidth, command, "cmd")
t.Logf("Synopsis is: %s", syn)
if !strings.HasPrefix(syn, "cmd ") {
t.Fatal("Synopsis should start with command name")
}
if !strings.Contains(syn, "[--opt=<OPTION> | -o]") {
t.Fatal("Synopsis should contain option descriptor")
}
if !strings.Contains(syn, "[--var-opt=<var-opt>]...") {
t.Fatal("Synopsis should contain option descriptor")
}
if !strings.Contains(syn, "<required>") {
t.Fatal("Synopsis should contain required argument")
}
if !strings.Contains(syn, "<variadic>...") {
t.Fatal("Synopsis should contain variadic argument")
}
if !strings.Contains(syn, "[<variadic>...]") {
t.Fatal("Synopsis should contain optional argument")
}
if !strings.Contains(syn, "[--]") {
t.Fatal("Synopsis should contain options finalizer")
}
}