-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_test.go
154 lines (116 loc) · 3.3 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package kli
import (
"testing"
)
func TestCommand(t *testing.T) {
c := &Command{}
t.Run("Run NewCommand()", func(t *testing.T) {
c = NewCommand("test", "test description")
})
t.Run("Run setParentCommandPath()", func(t *testing.T) {
c.setParentCommandPath("path")
})
t.Run("Run setApp()", func(t *testing.T) {
c.setApp(&Cli{})
})
t.Run("Run parseFlags()", func(t *testing.T) {
_, err := c.parseFlags([]string{"test", "flags"})
t.Log(err)
})
t.Run("Run run()", func(t *testing.T) {
cl := NewCli("test", "description", "0")
cl.rootCommand.run([]string{"test"})
cl.rootCommand.subCommandsMap["test"] = &Command{
name: "subcom",
shortdescription: "short description",
hidden: false,
app: cl,
}
cl.rootCommand.run([]string{"test"})
cl.rootCommand.run([]string{"---"})
cl.rootCommand.run([]string{"-help"})
// cl.rootCommand.actionCallback = func() error {
// println("Hello World!")
// return nil
// }
// cl.rootCommand.run([]string{"test"})
cl.rootCommand.app.defaultCommand = &Command{
name: "subcom",
shortdescription: "short description",
hidden: false,
app: cl,
}
cl.rootCommand.run([]string{"test"})
})
t.Run("Run Action()", func(t *testing.T) {
c.Action(func() error { return nil })
})
t.Run("Run PrintHelp()", func(t *testing.T) {
cl := NewCli("test", "description", "0")
// co.shortdescription = ""
cl.PrintHelp()
cl.rootCommand.shortdescription = "test"
cl.PrintHelp()
cl.rootCommand.commandPath = "notTest"
cl.PrintHelp()
cl.rootCommand.longdescription = ""
cl.PrintHelp()
cl.rootCommand.longdescription = "test"
cl.PrintHelp()
mockCommand := &Command{
name: "test",
shortdescription: "short description",
hidden: true,
longestSubcommand: len("test"),
}
cl.rootCommand.subCommands = append(cl.rootCommand.subCommands, mockCommand)
cl.PrintHelp()
mockCommand = &Command{
name: "subcom",
shortdescription: "short description",
hidden: false,
app: cl,
}
cl.rootCommand.longestSubcommand = 10
cl.rootCommand.subCommands = append(cl.rootCommand.subCommands, mockCommand)
cl.PrintHelp()
mockCommand = &Command{
name: "subcom",
shortdescription: "short description",
hidden: false,
app: cl,
}
cl.rootCommand.longestSubcommand = 10
cl.defaultCommand = mockCommand
cl.rootCommand.subCommands = append(cl.rootCommand.subCommands, mockCommand)
cl.PrintHelp()
cl.rootCommand.flagCount = 3
cl.PrintHelp()
})
t.Run("Run isDefaultCommand()", func(t *testing.T) {
c.isDefaultCommand()
})
t.Run("Run isHidden()", func(t *testing.T) {
c.isHidden()
})
t.Run("Run Hidden()", func(t *testing.T) {
c.Hidden()
})
t.Run("Run NewSubCommand()", func(t *testing.T) {
c.NewSubCommand("name", "description")
})
t.Run("Run AddCommand()", func(t *testing.T) {
c.AddCommand(c)
})
t.Run("Run StringFlag()", func(t *testing.T) {
var variable = "variable"
c.StringFlag("name", "description", &variable)
})
t.Run("Run IntFlag()", func(t *testing.T) {
var variable int
c.IntFlag("test", "description", &variable)
})
t.Run("Run LongDescription()", func(t *testing.T) {
c.LongDescription("name")
})
}