forked from rliebz/tusk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp_test.go
101 lines (87 loc) · 1.83 KB
/
help_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
package appcli
import (
"fmt"
"testing"
"github.com/rliebz/ghost"
"github.com/rliebz/ghost/be"
"github.com/rliebz/tusk/runner"
)
func TestFlagPrefixer(t *testing.T) {
tests := []struct {
name string
flags string
placeholder string
want string
}{
{"short", "a", "", "-a"},
{"short placeholder", "a", "foo", "-a <foo>"},
{"long", "aa", "", " --aa"},
{"long placeholder", "aa", "foo", " --aa <foo>"},
{"short first", "a, aa", "", "-a, --aa"},
{"long first", "aa, a", "", "-a, --aa"},
{"short first placeholder", "a, aa", "foo", "-a, --aa <foo>"},
{"long first placeholder", "aa, a", "foo", "-a, --aa <foo>"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := ghost.New(t)
got := flagPrefixer(tt.flags, tt.placeholder)
g.Should(be.Equal(tt.want, got))
})
}
}
func TestCreateArgsSection(t *testing.T) {
tests := []struct {
name string
taskCfg string
want string
}{
{
"no args",
"",
"",
},
{
"one args",
"foo: {usage: 'some usage'}",
`
Arguments:
foo some usage`,
},
{
"args without usage",
"foo: {}, bar: {}",
`
Arguments:
foo
bar`,
},
{
"args with usage",
"foo: {usage: 'some usage'}, bar: {usage: 'other usage'}",
`
Arguments:
foo some usage
bar other usage`,
},
{
"variable length arguments",
"a: {usage: 'some usage'}, aaaaa: {usage: 'other usage'}",
`
Arguments:
a some usage
aaaaa other usage`,
},
}
for _, tt := range tests {
taskName := "someTaskName"
t.Run(tt.name, func(t *testing.T) {
g := ghost.New(t)
cfgText := fmt.Sprintf("tasks: { %s: { args: {%s} } }", taskName, tt.taskCfg)
cfg, err := runner.Parse([]byte(cfgText))
g.NoError(err)
got := createArgsSection(cfg.Tasks[taskName])
g.Should(be.Equal(tt.want, got))
})
}
}