From 15fd35e7b4a52cf771f18d1d00fc4a4b25c68df9 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Mon, 5 Sep 2022 17:40:42 -0400 Subject: [PATCH] Add parametrize tests --- flag_test.go | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/flag_test.go b/flag_test.go index 8451ccb..aee9b83 100644 --- a/flag_test.go +++ b/flag_test.go @@ -77,27 +77,36 @@ func TestBoolFlagApply_SetsCount(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"}) - expect(t, err, nil) - expect(t, tf.Get(ctx), true) - expect(t, ctx.Count("tf"), 3) + boolCountTests := []struct { + input []string + expectedVal bool + expectedCount int + }{ + { + input: []string{"-tf", "-w", "-huh"}, + expectedVal: true, + expectedCount: 3, + }, + { + input: []string{}, + expectedVal: false, + expectedCount: 0, + }, + } - set1 := flag.NewFlagSet("test", 0) - ctx1 := NewContext(nil, set1, nil) - tf1 := &BoolFlag{Name: "tf", Aliases: []string{"w", "huh"}} - err = tf1.Apply(set1) - expect(t, err, nil) + for _, bct := range boolCountTests { + 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 = set1.Parse([]string{}) - expect(t, err, nil) - expect(t, tf1.Get(ctx1), false) - expect(t, ctx1.Count("tf"), 0) + err = set.Parse(bct.input) + expect(t, err, nil) + expect(t, tf.Get(ctx), bct.expectedVal) + expect(t, ctx.Count("tf"), bct.expectedCount) + } } func TestFlagsFromEnv(t *testing.T) {