From b22fc706c39eab8ef626dad18f21609425cc8714 Mon Sep 17 00:00:00 2001 From: therealmitchconnors Date: Thu, 5 Sep 2019 11:27:43 -0700 Subject: Expand SliceValue support to all slice and array types. --- string_array_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'string_array_test.go') diff --git a/string_array_test.go b/string_array_test.go index 1ceac8c..21f3633 100644 --- a/string_array_test.go +++ b/string_array_test.go @@ -193,6 +193,29 @@ func TestSAWithSpecialChar(t *testing.T) { } } +func TestSAAsSliceValue(t *testing.T) { + var sa []string + f := setUpSAFlagSet(&sa) + + in := []string{"1ns", "2ns"} + argfmt := "--sa=%s" + arg1 := fmt.Sprintf(argfmt, in[0]) + arg2 := fmt.Sprintf(argfmt, in[1]) + err := f.Parse([]string{arg1, arg2}) + if err != nil { + t.Fatal("expected no error; got", err) + } + + f.VisitAll(func(f *Flag) { + if val, ok := f.Value.(SliceValue); ok { + _ = val.Replace([]string{"3ns"}) + } + }) + if len(sa) != 1 || sa[0]!= "3ns" { + t.Fatalf("Expected ss to be overwritten with '3ns', but got: %v", sa) + } +} + func TestSAWithSquareBrackets(t *testing.T) { var sa []string f := setUpSAFlagSet(&sa) -- cgit v1.2.3