ffmd/tree_test.go

58 lines
980 B
Go

package ffmd
import (
"testing"
"github.com/matryer/is"
"github.com/peterbourgon/ff/v3/ffcli"
)
func TestTree(t *testing.T) {
is := is.NewRelaxed(t)
treeSingle := Tree(cmdSingle)
is.Equal(treeSingle, singleTree) // single command tree
treeSub := Tree(cmdRoot)
is.Equal(treeSub, subTree) // multi-command tree
}
var (
cmdSingle = &ffcli.Command{
Name: "myapp",
}
sub1 = &ffcli.Command{
Name: "sub1",
}
sub4 = &ffcli.Command{
Name: "sub4",
}
sub5 = &ffcli.Command{
Name: "sub5",
}
sub6 = &ffcli.Command{
Name: "sub6",
}
sub3 = &ffcli.Command{
Name: "sub3",
Subcommands: []*ffcli.Command{sub4},
}
sub2 = &ffcli.Command{
Name: "sub2",
Subcommands: []*ffcli.Command{sub3, sub5},
}
cmdRoot = &ffcli.Command{
Name: "myapp",
Subcommands: []*ffcli.Command{sub1, sub2, sub6},
}
singleTree = `myapp`
subTree = `myapp
├─ sub1
├─ sub2
│ ├─ sub3
│ │ └─ sub4
│ └─ sub5
└─ sub6`
)