From 90b831e61ee0ea159e0d00bb0c1ee3cd0c1dcdcd Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Wed, 5 Aug 2015 12:46:33 -0400 Subject: String and Int slices called twice should append not overwrite This allows users to do things like ``` cmd --filename=file1 --filename=file2 --filename=file3,file4 ``` And internally we will get ``` []string{"file1", "file2", "file3", "file4"} ``` --- int_slice_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'int_slice_test.go') diff --git a/int_slice_test.go b/int_slice_test.go index d162e86..927e7f4 100644 --- a/int_slice_test.go +++ b/int_slice_test.go @@ -47,3 +47,23 @@ func TestIS(t *testing.T) { } } } + +func TestISCalledTwice(t *testing.T) { + var is []int + f := setUpISFlagSet(&is) + + in := []string{"1,2", "3"} + expected := []int{1, 2, 3} + argfmt := "--is=%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) + } + for i, v := range is { + if expected[i] != v { + t.Fatalf("expected ss[%d] to be %s but got: %s", i, expected[i], v) + } + } +} -- cgit v1.2.3