helptext_test.go 1.22 KB
Newer Older
Jakub Sztandera's avatar
Jakub Sztandera committed
1 2 3 4 5 6 7
package cli

import (
	"strings"
	"testing"

	cmds "github.com/ipfs/go-ipfs/commands"
Jan Winkelmann's avatar
Jan Winkelmann committed
8

Steven Allen's avatar
Steven Allen committed
9
	"gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit"
Jakub Sztandera's avatar
Jakub Sztandera committed
10 11 12 13
)

func TestSynopsisGenerator(t *testing.T) {
	command := &cmds.Command{
Jan Winkelmann's avatar
Jan Winkelmann committed
14 15 16
		Arguments: []cmdkit.Argument{
			cmdkit.StringArg("required", true, false, ""),
			cmdkit.StringArg("variadic", false, true, ""),
Jakub Sztandera's avatar
Jakub Sztandera committed
17
		},
Jan Winkelmann's avatar
Jan Winkelmann committed
18 19
		Options: []cmdkit.Option{
			cmdkit.StringOption("opt", "o", "Option"),
Jakub Sztandera's avatar
Jakub Sztandera committed
20
		},
Jan Winkelmann's avatar
Jan Winkelmann committed
21
		Helptext: cmdkit.HelpText{
Jakub Sztandera's avatar
Jakub Sztandera committed
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
			SynopsisOptionsValues: map[string]string{
				"opt": "OPTION",
			},
		},
	}
	syn := generateSynopsis(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, "<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")
	}
}