-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringflag_test.go
More file actions
87 lines (66 loc) · 2.76 KB
/
stringflag_test.go
File metadata and controls
87 lines (66 loc) · 2.76 KB
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
package argumentative
import "testing"
func TestNewStringFlag(t *testing.T) {
flag := NewStringFlag("longname", "s", true, "default", "description")
if flag.Longflag != "longname" {
t.Errorf("Longflag assignment wrong, got [%s], want [%s]", flag.Longflag, "longname")
}
if flag.Shortflag != "s" {
t.Errorf("Shortflag assignment wrong, got [%s], want [%s]", flag.Shortflag, "s")
}
if flag.Default != "default" {
t.Errorf("Default assignment wrong, got [%s], want [%s]", flag.Default, "default")
}
if flag.Description != "description" {
t.Errorf("Description assignment wrong, got [%s], want [%s]", flag.Description, "description")
}
if *flag.Value != "default" {
t.Errorf("Assignment of default to value wrong, got [%s], want [%s]", *flag.Value, flag.Default)
}
}
func TestGetLongDescription(t *testing.T) {
flag := NewStringFlag("longname", "s", true, "default", "description")
result := flag.GetLongDescription()
await := "-s, --longname description (Default: default)"
if result != await {
t.Errorf("Generation of long description failed, got [%s], want [%s]", result, await)
}
flag = NewStringFlag("longname", "s", true, "", "description")
result = flag.GetLongDescription()
await = "-s, --longname description"
if result != await {
t.Errorf("Generation of long description without default failed, got [%s], want [%s]", result, await)
}
flag = NewStringFlag("longname", "s", false, "", "description")
result = flag.GetLongDescription()
await = "-s, --longname description"
if result != await {
t.Errorf("Generation of long description without default failed, got [%s], want [%s]", result, await)
}
flag = NewStringFlag("longname", "", true, "", "description")
result = flag.GetLongDescription()
await = "--longname description"
if result != await {
t.Errorf("Generation of long description without shortname failed, got [%s], want [%s]", result, await)
}
}
func TestGetShortDescription(t *testing.T) {
flag := NewStringFlag("longname", "s", true, "default", "description")
result := flag.GetShortDescription()
await := " -s" // @todo: remove space
if result != await {
t.Errorf("Generation of short description failed, got [%s], want [%s]", result, await)
}
flag = NewStringFlag("longname", "s", false, "", "description")
result = flag.GetShortDescription()
await = " [-s]" // @todo remove space
if result != await {
t.Errorf("Generation of short description no required failed, got [%s], want [%s]", result, await)
}
flag = NewStringFlag("longname", "", false, "", "description")
result = flag.GetShortDescription()
await = " [--longname]" // @todo remove space
if result != await {
t.Errorf("Generation of short description no short name failed, got [%s], want [%s]", result, await)
}
}