Add parametrize tests
This commit is contained in:
parent
7941e8ccf6
commit
15fd35e7b4
45
flag_test.go
45
flag_test.go
@ -77,27 +77,36 @@ func TestBoolFlagApply_SetsCount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBoolFlagCountFromContext(t *testing.T) {
|
func TestBoolFlagCountFromContext(t *testing.T) {
|
||||||
set := flag.NewFlagSet("test", 0)
|
|
||||||
ctx := NewContext(nil, set, nil)
|
|
||||||
tf := &BoolFlag{Name: "tf", Aliases: []string{"w", "huh"}}
|
|
||||||
err := tf.Apply(set)
|
|
||||||
expect(t, err, nil)
|
|
||||||
|
|
||||||
err = set.Parse([]string{"-tf", "-w", "-huh"})
|
boolCountTests := []struct {
|
||||||
expect(t, err, nil)
|
input []string
|
||||||
expect(t, tf.Get(ctx), true)
|
expectedVal bool
|
||||||
expect(t, ctx.Count("tf"), 3)
|
expectedCount int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
input: []string{"-tf", "-w", "-huh"},
|
||||||
|
expectedVal: true,
|
||||||
|
expectedCount: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: []string{},
|
||||||
|
expectedVal: false,
|
||||||
|
expectedCount: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
set1 := flag.NewFlagSet("test", 0)
|
for _, bct := range boolCountTests {
|
||||||
ctx1 := NewContext(nil, set1, nil)
|
set := flag.NewFlagSet("test", 0)
|
||||||
tf1 := &BoolFlag{Name: "tf", Aliases: []string{"w", "huh"}}
|
ctx := NewContext(nil, set, nil)
|
||||||
err = tf1.Apply(set1)
|
tf := &BoolFlag{Name: "tf", Aliases: []string{"w", "huh"}}
|
||||||
expect(t, err, nil)
|
err := tf.Apply(set)
|
||||||
|
expect(t, err, nil)
|
||||||
|
|
||||||
err = set1.Parse([]string{})
|
err = set.Parse(bct.input)
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
expect(t, tf1.Get(ctx1), false)
|
expect(t, tf.Get(ctx), bct.expectedVal)
|
||||||
expect(t, ctx1.Count("tf"), 0)
|
expect(t, ctx.Count("tf"), bct.expectedCount)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlagsFromEnv(t *testing.T) {
|
func TestFlagsFromEnv(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user