-
Notifications
You must be signed in to change notification settings - Fork 2
/
flags_test.go
63 lines (51 loc) · 1.46 KB
/
flags_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
package gommander
import "testing"
func TestFlagsCreation(t *testing.T) {
flag := NewFlag("help").Short('h').Help("The help flag").Global(true)
flagB := newFlag("-h --help", "The help flag")
flagB.Global(true)
assert(t, flag.IsGlobal, "Failed to set flag as global")
assertDeepEq(t, *flag, flagB, "Flag creation functions are out of sync")
expL := "-h, --help"
expF := "The help flag"
gotL, gotF := flag.generate(App())
assertEq(t, expL, gotL, "Flag generate method functioning incorrectly")
assertEq(t, expF, gotF, "Flag generate method functioning incorrectly")
{
flag := newFlag("--help", "Help flag")
expL := " --help"
expF := "Help flag"
gotL, gotF := flag.generate(App())
assertEq(t, expL, gotL, "Flag generate method functioning incorrectly")
assertEq(t, expF, gotF, "Flag generate method functioning incorrectly")
}
}
func BenchmarkFlagBuilder(b *testing.B) {
for i := 0; i < b.N; i++ {
NewFlag("version").Short('V').Help("A version flag")
}
}
func BenchmarkFlagFunc(b *testing.B) {
for i := 0; i < b.N; i++ {
newFlag("-V --version", "A version flag")
}
}
func BenchmarkFlagConstructor(b *testing.B) {
fn := func(f Flag) {}
for i := 0; i < b.N; i++ {
fn(Flag{
Name: "version",
ShortVal: "-v",
LongVal: "--version",
HelpStr: "A version flag",
IsGlobal: true,
})
}
}
func BenchmarkFlagGenerateFn(b *testing.B) {
f := helpFlag()
c := Command{theme: DefaultTheme()}
for i := 0; i < b.N; i++ {
f.generate(&c)
}
}