forked from alecthomas/kingpin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
args_test.go
47 lines (40 loc) · 1 KB
/
args_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
package kingpin
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestArgRemainder(t *testing.T) {
a := newArgGroup()
v := a.Arg("test", "").Strings()
a.init()
args := []string{"hello", "world"}
tokens := Tokenize(args)
a.parse(tokens)
assert.Equal(t, args, *v)
}
func TestArgRemainderErrorsWhenNotLast(t *testing.T) {
a := newArgGroup()
a.Arg("test", "").Strings()
a.Arg("test2", "").String()
assert.Error(t, a.init())
}
func TestArgMultipleRequired(t *testing.T) {
a := newArgGroup()
a.Arg("a", "").Required().String()
a.Arg("b", "").Required().String()
a.init()
err := a.parse(Tokenize([]string{}))
assert.Error(t, err)
err = a.parse(Tokenize([]string{"A"}))
assert.Error(t, err)
err = a.parse(Tokenize([]string{"A", "B"}))
assert.NoError(t, err)
}
func TestInvalidArgsDefaultCanBeOverridden(t *testing.T) {
a := newArgGroup()
a.Arg("a", "").Default("invalid").Bool()
assert.NoError(t, a.init())
tokens := Tokenize([]string{})
err := a.parse(tokens)
assert.Error(t, err)
}