summaryrefslogtreecommitdiff
path: root/parse_test.go
diff options
context:
space:
mode:
authorPavel Borzenkov <[email protected]>2018-11-20 12:29:36 +0300
committerPavel Borzenkov <[email protected]>2018-11-20 12:29:36 +0300
commitf1aabd5026533b5f61cabc38a5fd8a1af3148342 (patch)
tree02b347c927e552293f767cbaf4521d95b764017b /parse_test.go
parent96b097bef382f73bdd47c1dd30ddaf9fb130aaf5 (diff)
parse_test: add tests covering new TextUnamarshaler value support
Signed-off-by: Pavel Borzenkov <[email protected]>
Diffstat (limited to 'parse_test.go')
-rw-r--r--parse_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/parse_test.go b/parse_test.go
index d201b2f..b72563c 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -646,6 +646,16 @@ func (f *textUnmarshaler) UnmarshalText(b []byte) error {
func TestTextUnmarshaler(t *testing.T) {
// fields that implement TextUnmarshaler should be parsed using that interface
var args struct {
+ Foo textUnmarshaler
+ }
+ err := parse("--foo abc", &args)
+ require.NoError(t, err)
+ assert.Equal(t, 3, args.Foo.val)
+}
+
+func TestPtrToTextUnmarshaler(t *testing.T) {
+ // fields that implement TextUnmarshaler should be parsed using that interface
+ var args struct {
Foo *textUnmarshaler
}
err := parse("--foo abc", &args)
@@ -656,6 +666,19 @@ func TestTextUnmarshaler(t *testing.T) {
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 TestRepeatedPtrToTextUnmarshaler(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)
@@ -669,6 +692,19 @@ func TestRepeatedTextUnmarshaler(t *testing.T) {
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)
+}
+
+func TestPositionalPtrToTextUnmarshaler(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)