-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathguinea_test.go
52 lines (43 loc) · 968 Bytes
/
guinea_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
package guinea
import (
"testing"
)
func TestFindCommand(t *testing.T) {
var subSubCmdA = Command{}
var subSubCmdB = Command{}
var subCmdA = Command{
Subcommands: map[string]*Command{
"subA": &subSubCmdA,
"subB": &subSubCmdB,
},
}
var subCmdB = Command{}
var mainCmd = Command{
Subcommands: map[string]*Command{
"subA": &subCmdA,
"subB": &subCmdB,
},
}
// mainCmd --- subA --- subA
// |_ subB |_ subB
cmd, cmdName, cmdArgs := FindCommand(&mainCmd, []string{"program"})
if cmd != &mainCmd {
t.Fatal("Invalid cmd")
}
if cmdName != "program" {
t.Fatal("Invalid cmdName")
}
if len(cmdArgs) != 0 {
t.Fatal("Invalid cmdArgs")
}
cmd, cmdName, cmdArgs = FindCommand(&mainCmd, []string{"program", "subA", "subB", "param1", "param2"})
if cmd != &subSubCmdB {
t.Fatal("Invalid cmd")
}
if cmdName != "program subA subB" {
t.Fatal("Invalid cmdName")
}
if len(cmdArgs) != 2 {
t.Fatal("Invalid cmdArgs")
}
}