diff options
| author | Eric Paris <[email protected]> | 2015-08-05 12:46:33 -0400 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-08-05 12:54:03 -0400 |
| commit | 90b831e61ee0ea159e0d00bb0c1ee3cd0c1dcdcd (patch) | |
| tree | 6655dd93a25fe82dfe6362ba8c87f874158834f4 /int_slice_test.go | |
| parent | af83f852cb3533df209ffef0b0f36b65d4594848 (diff) | |
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"}
```
Diffstat (limited to 'int_slice_test.go')
| -rw-r--r-- | int_slice_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
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) + } + } +} |
