-
Notifications
You must be signed in to change notification settings - Fork 2
/
command_test.go
85 lines (74 loc) · 1.78 KB
/
command_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package mcli
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCommandsSuggest(t *testing.T) {
resetDefaultApp()
addTestGithubCliCommands()
suggest := defaultApp.cmds.suggest("aapi")
assert.True(t, len(suggest) > 0)
assert.Equal(t, "api", suggest[0])
suggest = defaultApp.cmds.suggest("extenson create")
assert.True(t, len(suggest) > 0)
assert.Equal(t, "extension create", suggest[0])
suggest = defaultApp.cmds.suggest("extension crate")
assert.True(t, len(suggest) > 0)
assert.Equal(t, "extension create", suggest[0])
}
func TestCommandsGrouping(t *testing.T) {
cmds := commands{
{
Name: "cmd0",
level: 1,
},
{
Name: "cmd1",
Hidden: false,
cmdOpts: []CmdOpt{WithCategory("group1")},
level: 1,
},
{
Name: "cmd1 sub1",
Hidden: false,
cmdOpts: []CmdOpt{WithCategory("group1")},
level: 2,
},
{
Name: "cmd2",
Hidden: true,
cmdOpts: []CmdOpt{WithCategory("group1")},
level: 1,
},
{
Name: "cmd3",
Hidden: true,
cmdOpts: []CmdOpt{WithCategory("group3")},
level: 1,
},
{
Name: "cmd4",
Hidden: false,
level: 1,
},
{
Name: "cmd5",
Hidden: false,
cmdOpts: []CmdOpt{WithCategory("group5")},
level: 1,
},
}
cmdGroups, hasCategoreis := cmds.groupByCategory()
require.True(t, hasCategoreis)
t.Log(cmdGroups)
require.Len(t, cmdGroups, 4)
assert.Equal(t, "group1", cmdGroups[0].category)
assert.Len(t, cmdGroups[0].commands, 2)
assert.Equal(t, "group3", cmdGroups[1].category)
assert.Len(t, cmdGroups[1].commands, 1)
assert.Equal(t, "group5", cmdGroups[2].category)
assert.Len(t, cmdGroups[2].commands, 1)
assert.Equal(t, "Other Commands", cmdGroups[3].category)
assert.Len(t, cmdGroups[3].commands, 2)
}