forked from heroku/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flag_test.go
40 lines (36 loc) · 1.02 KB
/
flag_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
package main
import "testing"
var verboseFlag = &Flag{
Name: "verbose",
Char: "v",
HasValue: false,
}
func checkFlag(t *testing.T, flag *Flag, input, expectedValue, expectedError string) {
out, val, err := parseFlag(input, []*Flag{flag})
if expectedError != "" {
if expectedError != err.Error() {
t.Error(err)
}
return
}
if err != nil {
t.Error(err)
}
if flag != out {
t.Error(flag, "not returned")
}
if val != expectedValue {
t.Error(expectedValue + " not returned")
}
}
func TestParseFlag(t *testing.T) {
checkFlag(t, appFlag, "-amyapp", "myapp", "")
checkFlag(t, appFlag, "--app=myapp", "myapp", "")
checkFlag(t, appFlag, "--app=myapp=app", "myapp=app", "")
checkFlag(t, appFlag, "-a=myapp", "myapp", "")
checkFlag(t, appFlag, "-amyapp", "myapp", "")
checkFlag(t, appFlag, "--app", "", " -a, --app APP needs a value")
checkFlag(t, verboseFlag, "--verbose", "", "")
checkFlag(t, verboseFlag, "--verbose=foo", "", " -v, --verbose does not take a value")
checkFlag(t, verboseFlag, "-v", "", "")
}