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 /string_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 'string_slice_test.go')
| -rw-r--r-- | string_slice_test.go | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/string_slice_test.go b/string_slice_test.go index c37a91a..d5c0d03 100644 --- a/string_slice_test.go +++ b/string_slice_test.go @@ -28,17 +28,37 @@ func TestSS(t *testing.T) { } for i, v := range ss { if vals[i] != v { - t.Fatal("expected ss[%d] to be %s but got: %s", i, vals[i], v) + t.Fatalf("expected ss[%d] to be %s but got: %s", i, vals[i], v) } } getSS, err := f.GetStringSlice("ss") if err != nil { - t.Fatal("got an error from GetStringSlice(): %v", err) + t.Fatal("got an error from GetStringSlice():", err) } for i, v := range getSS { if vals[i] != v { - t.Fatal("expected ss[%d] to be %s from GetStringSlice but got: %s", i, vals[i], v) + t.Fatalf("expected ss[%d] to be %s from GetStringSlice but got: %s", i, vals[i], v) + } + } +} + +func TestSSCalledTwice(t *testing.T) { + var ss []string + f := setUpSSFlagSet(&ss) + + in := []string{"one,two", "three"} + expected := []string{"one", "two", "three"} + argfmt := "--ss=%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 ss { + if expected[i] != v { + t.Fatalf("expected ss[%d] to be %s but got: %s", i, expected[i], v) } } } |
