diff options
| author | Fredrik Wallgren <[email protected]> | 2016-02-29 22:05:26 +0100 |
|---|---|---|
| committer | Fredrik Wallgren <[email protected]> | 2016-02-29 22:05:26 +0100 |
| commit | 1488562b1ebdb57ebdc74e640900153fb624b2e6 (patch) | |
| tree | cce6f609a63555bf11eb0974469ec9f4d01ffab0 /parse_test.go | |
| parent | aaae1550b702cee36c45fdee30a58ba4cc733edd (diff) | |
Allow override of defaults for slice arguments
This commit fixes a bug where if a multiple value argument (slice) has default
values, the submitted values will be appended to the default. Not
overriding them as expected.
Diffstat (limited to 'parse_test.go')
| -rw-r--r-- | parse_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/parse_test.go b/parse_test.go index 964c9a7..8ee6a79 100644 --- a/parse_test.go +++ b/parse_test.go @@ -250,6 +250,19 @@ func TestMultipleWithEq(t *testing.T) { assert.Equal(t, []string{"x"}, args.Bar) } +func TestMultipleWithDefault(t *testing.T) { + var args struct { + Foo []int + Bar []string + } + args.Foo = []int{42} + args.Bar = []string{"foo"} + err := parse("--foo 1 2 3 --bar x y z", &args) + require.NoError(t, err) + assert.Equal(t, []int{1, 2, 3}, args.Foo) + assert.Equal(t, []string{"x", "y", "z"}, args.Bar) +} + func TestExemptField(t *testing.T) { var args struct { Foo string |
