Skip to content

Commit bee89cf

Browse files
committed
Add Synopsis generator test
License: MIT Signed-off-by: Jakub Sztandera <[email protected]>
1 parent b308edd commit bee89cf

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

commands/cli/helptext_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cli
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
cmds "github.com/ipfs/go-ipfs/commands"
8+
)
9+
10+
func TestSynopsisGenerator(t *testing.T) {
11+
command := &cmds.Command{
12+
Arguments: []cmds.Argument{
13+
cmds.StringArg("required", true, false, ""),
14+
cmds.StringArg("variadic", false, true, ""),
15+
},
16+
Options: []cmds.Option{
17+
cmds.StringOption("opt", "o", "Option"),
18+
},
19+
Helptext: cmds.HelpText{
20+
SynopsisOptionsValues: map[string]string{
21+
"opt": "OPTION",
22+
},
23+
},
24+
}
25+
syn := generateSynopsis(command, "cmd")
26+
t.Logf("Synopsis is: %s", syn)
27+
if !strings.HasPrefix(syn, "cmd ") {
28+
t.Fatal("Synopsis should start with command name")
29+
}
30+
if !strings.Contains(syn, "[--opt=<OPTION> | -o]") {
31+
t.Fatal("Synopsis should contain option descriptor")
32+
}
33+
if !strings.Contains(syn, "<required>") {
34+
t.Fatal("Synopsis should contain required argument")
35+
}
36+
if !strings.Contains(syn, "<variadic>...") {
37+
t.Fatal("Synopsis should contain variadic argument")
38+
}
39+
if !strings.Contains(syn, "[<variadic>...]") {
40+
t.Fatal("Synopsis should contain optional argument")
41+
}
42+
if !strings.Contains(syn, "[--]") {
43+
t.Fatal("Synopsis should contain options finalizer")
44+
}
45+
}

0 commit comments

Comments
 (0)