-
Notifications
You must be signed in to change notification settings - Fork 2
/
options_test.go
85 lines (72 loc) · 1.92 KB
/
options_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 gommander
import "testing"
func TestOptionsCreation(t *testing.T) {
opt := NewOption("port").Short('p').Help("The port option").Argument("<port-number>").Required(true)
optB := newOption("-p --port <port-number>", "The port option", true)
assertDeepEq(t, *opt, optB, "Option creation methods out of sync")
assert(t, opt.IsRequired, "Failed to set required value on options")
expL := "-p, --port <port-number> "
expF := "The port option"
gotL, gotF := opt.generate(App())
assertEq(t, expL, gotL, "The option generate func is faulty")
assertEq(t, expF, gotF, "The option generate func is faulty")
expectedArg := NewArgument("<port-number>")
assertDeepEq(t, expectedArg, opt.Arg, "Option args created incorrectly")
}
func BenchmarkOptFunc(b *testing.B) {
for i := 0; i < b.N; i++ {
newOption("-p --port <port-number>", "A port option", true)
}
}
func BenchmarkOptBuilder(b *testing.B) {
for i := 0; i < b.N; i++ {
NewOption("port").
Short('p').
Help("A port option").
Required(true)
}
}
func BenchmarkOptBuilderwArg(b *testing.B) {
for i := 0; i < b.N; i++ {
NewOption("port").
Short('p').
Help("A port option").
Required(true).
Argument("<port-number>")
}
}
func BenchmarkOptAndArgBuilder(b *testing.B) {
for i := 0; i < b.N; i++ {
NewOption("port").
Short('p').
Help("A port option").
Required(true).
AddArgument(
NewArgument("port-number").
Required(true),
)
}
}
func BenchmarkOptConstructor(b *testing.B) {
fn := func(o Option) {}
for i := 0; i < b.N; i++ {
fn(Option{
Name: "port",
LongVal: "--port",
ShortVal: "-p",
HelpStr: "port option",
Arg: &Argument{
Name: "port-no",
IsRequired: true,
},
IsRequired: true,
})
}
}
func BenchmarkOptGenerateFn(b *testing.B) {
o := newOption("-p --port <int:port-no>", "a port number", false)
c := Command{theme: DefaultTheme()}
for i := 0; i < b.N; i++ {
o.generate(&c)
}
}