Skip to content

Commit d7c0e17

Browse files
committed
style(args_test)
1 parent 85271fc commit d7c0e17

File tree

1 file changed

+61
-91
lines changed

1 file changed

+61
-91
lines changed

args_test.go

Lines changed: 61 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
)
77

8-
func getCommand(args PositionalArgs, withValid bool) *Command {
8+
func newCommand(args PositionalArgs, withValid bool) *Command {
99
c := &Command{
1010
Use: "c",
1111
Args: args,
@@ -54,193 +54,163 @@ func expectError(err error, t *testing.T, ex string) {
5454
// NoArgs
5555

5656
func TestNoArgs(t *testing.T) {
57-
c := getCommand(NoArgs, false)
58-
output, err := executeCommand(c)
59-
expectSuccess(output, err, t)
57+
o, e := executeCommand(newCommand(NoArgs, false))
58+
expectSuccess(o, e, t)
6059
}
6160

6261
func TestNoArgsWithArgs(t *testing.T) {
63-
c := getCommand(NoArgs, false)
64-
_, err := executeCommand(c, "one")
65-
expectError(err, t, "no")
62+
_, e := executeCommand(newCommand(NoArgs, false), "one")
63+
expectError(e, t, "no")
6664
}
6765

6866
func TestNoArgsWithArgsWithValid(t *testing.T) {
69-
c := getCommand(NoArgs, true)
70-
_, err := executeCommand(c, "one")
71-
expectError(err, t, "no")
67+
_, e := executeCommand(newCommand(NoArgs, true), "one")
68+
expectError(e, t, "no")
7269
}
7370

7471
// ArbitraryArgs
7572

7673
func TestArbitraryArgs(t *testing.T) {
77-
c := getCommand(ArbitraryArgs, false)
78-
output, err := executeCommand(c, "a", "b")
79-
expectSuccess(output, err, t)
74+
o, e := executeCommand(newCommand(ArbitraryArgs, false), "a", "b")
75+
expectSuccess(o, e, t)
8076
}
8177

8278
func TestArbitraryArgsWithValid(t *testing.T) {
83-
c := getCommand(ArbitraryArgs, true)
84-
output, err := executeCommand(c, "one", "two")
85-
expectSuccess(output, err, t)
79+
o, e := executeCommand(newCommand(ArbitraryArgs, true), "one", "two")
80+
expectSuccess(o, e, t)
8681
}
8782

8883
func TestArbitraryArgsWithValidWithInvalidArgs(t *testing.T) {
89-
c := getCommand(ArbitraryArgs, true)
90-
_, err := executeCommand(c, "a")
91-
expectError(err, t, "valid")
84+
_, e := executeCommand(newCommand(ArbitraryArgs, true), "a")
85+
expectError(e, t, "valid")
9286
}
9387

9488
// MinimumNArgs
9589

9690
func TestMinimumNArgs(t *testing.T) {
97-
c := getCommand(MinimumNArgs(2), false)
98-
output, err := executeCommand(c, "a", "b", "c")
99-
expectSuccess(output, err, t)
91+
o, e := executeCommand(newCommand(MinimumNArgs(2), false), "a", "b", "c")
92+
expectSuccess(o, e, t)
10093
}
10194

10295
func TestMinimumNArgsWithValid(t *testing.T) {
103-
c := getCommand(MinimumNArgs(2), true)
104-
output, err := executeCommand(c, "one", "three")
105-
expectSuccess(output, err, t)
96+
o, e := executeCommand(newCommand(MinimumNArgs(2), true), "one", "three")
97+
expectSuccess(o, e, t)
10698
}
10799

108100
func TestMinimumNArgsWithValidWithInvalidArgs(t *testing.T) {
109-
c := getCommand(MinimumNArgs(2), true)
110-
_, err := executeCommand(c, "a", "b")
111-
expectError(err, t, "valid")
101+
_, e := executeCommand(newCommand(MinimumNArgs(2), true), "a", "b")
102+
expectError(e, t, "valid")
112103
}
113104

114105
func TestMinimumNArgsWithLessArgs(t *testing.T) {
115-
c := getCommand(MinimumNArgs(2), false)
116-
_, err := executeCommand(c, "a")
117-
expectError(err, t, "min")
106+
_, e := executeCommand(newCommand(MinimumNArgs(2), false), "a")
107+
expectError(e, t, "min")
118108
}
119109

120110
func TestMinimumNArgsWithLessArgsWithValid(t *testing.T) {
121-
c := getCommand(MinimumNArgs(2), true)
122-
_, err := executeCommand(c, "one")
123-
expectError(err, t, "min")
111+
_, e := executeCommand(newCommand(MinimumNArgs(2), true), "one")
112+
expectError(e, t, "min")
124113
}
125114

126115
func TestMinimumNArgsWithLessArgsWithValidWithInvalidArgs(t *testing.T) {
127-
c := getCommand(MinimumNArgs(2), true)
128-
_, err := executeCommand(c, "a")
129-
expectError(err, t, "valid")
116+
_, e := executeCommand(newCommand(MinimumNArgs(2), true), "a")
117+
expectError(e, t, "valid")
130118
}
131119

132120
// MaximumNArgs
133121

134122
func TestMaximumNArgs(t *testing.T) {
135-
c := getCommand(MaximumNArgs(3), false)
136-
output, err := executeCommand(c, "a", "b")
137-
expectSuccess(output, err, t)
123+
o, e := executeCommand(newCommand(MaximumNArgs(3), false), "a", "b")
124+
expectSuccess(o, e, t)
138125
}
139126

140127
func TestMaximumNArgsWithValid(t *testing.T) {
141-
c := getCommand(MaximumNArgs(2), true)
142-
output, err := executeCommand(c, "one", "three")
143-
expectSuccess(output, err, t)
128+
o, e := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three")
129+
expectSuccess(o, e, t)
144130
}
145131

146132
func TestMaximumNArgsWithValidWithInvalidArgs(t *testing.T) {
147-
c := getCommand(MaximumNArgs(2), true)
148-
_, err := executeCommand(c, "a", "b")
149-
expectError(err, t, "valid")
133+
_, e := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b")
134+
expectError(e, t, "valid")
150135
}
151136

152137
func TestMaximumNArgsWithMoreArgs(t *testing.T) {
153-
c := getCommand(MaximumNArgs(2), false)
154-
_, err := executeCommand(c, "a", "b", "c")
155-
expectError(err, t, "max")
138+
_, e := executeCommand(newCommand(MaximumNArgs(2), false), "a", "b", "c")
139+
expectError(e, t, "max")
156140
}
157141

158142
func TestMaximumNArgsWithMoreArgsWithValid(t *testing.T) {
159-
c := getCommand(MaximumNArgs(2), true)
160-
_, err := executeCommand(c, "one", "three", "two")
161-
expectError(err, t, "max")
143+
_, e := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three", "two")
144+
expectError(e, t, "max")
162145
}
163146

164147
func TestMaximumNArgsWithMoreArgsWithValidWithInvalidArgs(t *testing.T) {
165-
c := getCommand(MaximumNArgs(2), true)
166-
_, err := executeCommand(c, "a", "b", "c")
167-
expectError(err, t, "valid")
148+
_, e := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b", "c")
149+
expectError(e, t, "valid")
168150
}
169151

170152
// ExactArgs
171153

172154
func TestExactArgs(t *testing.T) {
173-
c := getCommand(ExactArgs(3), false)
174-
output, err := executeCommand(c, "a", "b", "c")
175-
expectSuccess(output, err, t)
155+
o, e := executeCommand(newCommand(ExactArgs(3), false), "a", "b", "c")
156+
expectSuccess(o, e, t)
176157
}
177158

178159
func TestExactArgsWithValid(t *testing.T) {
179-
c := getCommand(ExactArgs(3), true)
180-
output, err := executeCommand(c, "three", "one", "two")
181-
expectSuccess(output, err, t)
160+
o, e := executeCommand(newCommand(ExactArgs(3), true), "three", "one", "two")
161+
expectSuccess(o, e, t)
182162
}
183163

184164
func TestExactArgsWithValidWithInvalidArgs(t *testing.T) {
185-
c := getCommand(ExactArgs(3), true)
186-
_, err := executeCommand(c, "three", "a", "two")
187-
expectError(err, t, "valid")
165+
_, e := executeCommand(newCommand(ExactArgs(3), true), "three", "a", "two")
166+
expectError(e, t, "valid")
188167
}
189168

190169
func TestExactArgsWithInvalidCount(t *testing.T) {
191-
c := getCommand(ExactArgs(2), false)
192-
_, err := executeCommand(c, "a", "b", "c")
193-
expectError(err, t, "exact")
170+
_, e := executeCommand(newCommand(ExactArgs(2), false), "a", "b", "c")
171+
expectError(e, t, "exact")
194172
}
195173

196174
func TestExactArgsWithInvalidCountWithValid(t *testing.T) {
197-
c := getCommand(ExactArgs(2), true)
198-
_, err := executeCommand(c, "three", "one", "two")
199-
expectError(err, t, "exact")
175+
_, e := executeCommand(newCommand(ExactArgs(2), true), "three", "one", "two")
176+
expectError(e, t, "exact")
200177
}
201178

202179
func TestExactArgsWithInvalidCountWithValidWithInvalidArgs(t *testing.T) {
203-
c := getCommand(ExactArgs(2), true)
204-
_, err := executeCommand(c, "three", "a", "two")
205-
expectError(err, t, "valid")
180+
_, e := executeCommand(newCommand(ExactArgs(2), true), "three", "a", "two")
181+
expectError(e, t, "valid")
206182
}
207183

208184
// RangeArgs
209185

210186
func TestRangeArgs(t *testing.T) {
211-
c := getCommand(RangeArgs(2, 4), false)
212-
output, err := executeCommand(c, "a", "b", "c")
213-
expectSuccess(output, err, t)
187+
o, e := executeCommand(newCommand(RangeArgs(2, 4), false), "a", "b", "c")
188+
expectSuccess(o, e, t)
214189
}
215190

216191
func TestRangeArgsWithValid(t *testing.T) {
217-
c := getCommand(RangeArgs(2, 4), true)
218-
output, err := executeCommand(c, "three", "one", "two")
219-
expectSuccess(output, err, t)
192+
o, e := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "one", "two")
193+
expectSuccess(o, e, t)
220194
}
221195

222196
func TestRangeArgsWithValidWithInvalidArgs(t *testing.T) {
223-
c := getCommand(RangeArgs(2, 4), true)
224-
_, err := executeCommand(c, "three", "a", "two")
225-
expectError(err, t, "valid")
197+
_, e := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "a", "two")
198+
expectError(e, t, "valid")
226199
}
227200

228201
func TestRangeArgsWithInvalidCount(t *testing.T) {
229-
c := getCommand(RangeArgs(2, 4), false)
230-
_, err := executeCommand(c, "a")
231-
expectError(err, t, "range")
202+
_, e := executeCommand(newCommand(RangeArgs(2, 4), false), "a")
203+
expectError(e, t, "range")
232204
}
233205

234206
func TestRangeArgsWithInvalidCountWithValid(t *testing.T) {
235-
c := getCommand(RangeArgs(2, 4), true)
236-
_, err := executeCommand(c, "two")
237-
expectError(err, t, "range")
207+
_, e := executeCommand(newCommand(RangeArgs(2, 4), true), "two")
208+
expectError(e, t, "range")
238209
}
239210

240211
func TestRangeArgsWithInvalidCountWithValidWithInvalidArgs(t *testing.T) {
241-
c := getCommand(RangeArgs(2, 4), true)
242-
_, err := executeCommand(c, "a")
243-
expectError(err, t, "valid")
212+
_, e := executeCommand(newCommand(RangeArgs(2, 4), true), "a")
213+
expectError(e, t, "valid")
244214
}
245215

246216
// Takes(No)Args

0 commit comments

Comments
 (0)