From 96b097bef382f73bdd47c1dd30ddaf9fb130aaf5 Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Tue, 20 Nov 2018 12:29:15 +0300 Subject: parse_test: fix formatting Signed-off-by: Pavel Borzenkov --- parse_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'parse_test.go') diff --git a/parse_test.go b/parse_test.go index 0bc97e3..d201b2f 100644 --- a/parse_test.go +++ b/parse_test.go @@ -580,7 +580,7 @@ func TestEnvironmentVariableRequired(t *testing.T) { assert.Equal(t, "bar", args.Foo) } -func TestEnvironmentVariableSliceArgumentString(t *testing.T) { +func TestEnvironmentVariableSliceArgumentString(t *testing.T) { var args struct { Foo []string `arg:"env"` } @@ -589,7 +589,7 @@ func TestEnvironmentVariableSliceArgumentString(t *testing.T) { assert.Equal(t, []string{"bar", "baz, qux"}, args.Foo) } -func TestEnvironmentVariableSliceArgumentInteger(t *testing.T) { +func TestEnvironmentVariableSliceArgumentInteger(t *testing.T) { var args struct { Foo []int `arg:"env"` } @@ -598,7 +598,7 @@ func TestEnvironmentVariableSliceArgumentInteger(t *testing.T) { assert.Equal(t, []int{1, 99}, args.Foo) } -func TestEnvironmentVariableSliceArgumentFloat(t *testing.T) { +func TestEnvironmentVariableSliceArgumentFloat(t *testing.T) { var args struct { Foo []float32 `arg:"env"` } @@ -607,7 +607,7 @@ func TestEnvironmentVariableSliceArgumentFloat(t *testing.T) { assert.Equal(t, []float32{1.1, 99.9}, args.Foo) } -func TestEnvironmentVariableSliceArgumentBool(t *testing.T) { +func TestEnvironmentVariableSliceArgumentBool(t *testing.T) { var args struct { Foo []bool `arg:"env"` } @@ -616,7 +616,7 @@ func TestEnvironmentVariableSliceArgumentBool(t *testing.T) { assert.Equal(t, []bool{true, false, false, true}, args.Foo) } -func TestEnvironmentVariableSliceArgumentWrongCsv(t *testing.T) { +func TestEnvironmentVariableSliceArgumentWrongCsv(t *testing.T) { var args struct { Foo []int `arg:"env"` } @@ -625,7 +625,7 @@ func TestEnvironmentVariableSliceArgumentWrongCsv(t *testing.T) { assert.Error(t, err) } -func TestEnvironmentVariableSliceArgumentWrongType(t *testing.T) { +func TestEnvironmentVariableSliceArgumentWrongType(t *testing.T) { var args struct { Foo []bool `arg:"env"` } -- cgit v1.2.3 From f1aabd5026533b5f61cabc38a5fd8a1af3148342 Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Tue, 20 Nov 2018 12:29:36 +0300 Subject: parse_test: add tests covering new TextUnamarshaler value support Signed-off-by: Pavel Borzenkov --- parse_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'parse_test.go') diff --git a/parse_test.go b/parse_test.go index d201b2f..b72563c 100644 --- a/parse_test.go +++ b/parse_test.go @@ -644,6 +644,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 @@ -654,6 +664,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 @@ -667,6 +690,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"` -- cgit v1.2.3