-
Notifications
You must be signed in to change notification settings - Fork 31
/
helpValues_whitebox_test.go
56 lines (44 loc) · 1.5 KB
/
helpValues_whitebox_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
package flaggy
import (
"testing"
)
func TestMakeSpacer(t *testing.T) {
if spacer := makeSpacer("short", 20); len(spacer) != 15 {
t.Errorf("spacer length expected to be 15, got %d.", len(spacer))
}
if spacer := makeSpacer("very long", 20); len(spacer) != 11 {
t.Errorf("spacer length expected to be 11, got %d.", len(spacer))
}
if spacer := makeSpacer("very long", 0); len(spacer) != 0 {
t.Errorf("spacer length expected to be 0, got %d.", len(spacer))
}
}
func TestGetLongestNameLength(t *testing.T) {
input := []string{"short", "longer", "very-long"}
var subcommands []*Subcommand
var flags []*Flag
var positionalValues []*PositionalValue
for _, name := range input {
subcommands = append(subcommands, NewSubcommand(name))
flags = append(flags, &Flag{LongName: name})
positionalValues = append(positionalValues, &PositionalValue{Name: name})
}
if l := getLongestNameLength(subcommands, 0); l != 9 {
t.Errorf("should have returned 9, got %d.", l)
}
if l := getLongestNameLength(subcommands, 15); l != 15 {
t.Errorf("should have returned 15, got %d.", l)
}
if l := getLongestNameLength(flags, 0); l != 9 {
t.Errorf("should have returned 9, got %d.", l)
}
if l := getLongestNameLength(flags, 15); l != 15 {
t.Errorf("should have returned 15, got %d.", l)
}
if l := getLongestNameLength(positionalValues, 0); l != 9 {
t.Errorf("should have returned 15, got %d.", l)
}
if l := getLongestNameLength(positionalValues, 15); l != 15 {
t.Errorf("should have returned 9, got %d.", l)
}
}