From 6f2f3b4bf6c3fb40a0d2200ce6affee56cf781d8 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Wed, 18 Apr 2018 21:23:08 -0700 Subject: drop setScalar --- parse_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'parse_test.go') diff --git a/parse_test.go b/parse_test.go index 925a23e..ce3ad34 100644 --- a/parse_test.go +++ b/parse_test.go @@ -599,6 +599,19 @@ 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) +} + type boolUnmarshaler bool func (p *boolUnmarshaler) UnmarshalText(b []byte) error { -- cgit v1.2.3 From 4d71204936cbe2b4d7ebeb5b8a4d25432599eb17 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Wed, 18 Apr 2018 21:54:27 -0700 Subject: add positional test --- parse_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'parse_test.go') diff --git a/parse_test.go b/parse_test.go index ce3ad34..1461c02 100644 --- a/parse_test.go +++ b/parse_test.go @@ -612,6 +612,19 @@ func TestRepeatedTextUnmarshaler(t *testing.T) { 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 { -- cgit v1.2.3