Skip to content

Commit

Permalink
add positional test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexflint committed Apr 19, 2018
1 parent b9375a2 commit 4d71204
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4d71204

Please sign in to comment.