diff options
| author | Alex Flint <[email protected]> | 2018-04-20 07:57:08 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-04-20 07:57:08 -0700 |
| commit | 074ee5f759999d103724b5594e33901adeb28e73 (patch) | |
| tree | 150c205cd0c5b285c4ee04482a24f491e1e38342 /parse_test.go | |
| parent | b1eda2c7b64c118d56472c1944054bf9235d6c48 (diff) | |
| parent | 4d71204936cbe2b4d7ebeb5b8a4d25432599eb17 (diff) | |
Merge pull request #64 from alexflint/repeated-unmarshaltext
Fix repeated arguments implementing TextUnmarshaler
Diffstat (limited to 'parse_test.go')
| -rw-r--r-- | parse_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/parse_test.go b/parse_test.go index 925a23e..1461c02 100644 --- a/parse_test.go +++ b/parse_test.go @@ -599,6 +599,32 @@ func TestTextUnmarshaler(t *testing.T) { assert.Equal(t, 3, args.Foo.val) } +func TestRepeatedTextUnmarshaler(t *testing.T) { + // fields that implement TextUnmarshaler should be parsed using that interface + var args struct { + Foo []*textUnmarshaler + } + err := parse("--foo abc d ef", &args) + require.NoError(t, err) + require.Len(t, args.Foo, 3) + assert.Equal(t, 3, args.Foo[0].val) + assert.Equal(t, 1, args.Foo[1].val) + assert.Equal(t, 2, args.Foo[2].val) +} + +func TestPositionalTextUnmarshaler(t *testing.T) { + // fields that implement TextUnmarshaler should be parsed using that interface + var args struct { + Foo []*textUnmarshaler `arg:"positional"` + } + err := parse("abc d ef", &args) + require.NoError(t, err) + require.Len(t, args.Foo, 3) + assert.Equal(t, 3, args.Foo[0].val) + assert.Equal(t, 1, args.Foo[1].val) + assert.Equal(t, 2, args.Foo[2].val) +} + type boolUnmarshaler bool func (p *boolUnmarshaler) UnmarshalText(b []byte) error { |
