From cb4e079d13af069a75c6549216c6902a7569f57f Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Fri, 24 Jan 2020 14:42:49 -0800 Subject: [PATCH] add a further test --- parse_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/parse_test.go b/parse_test.go index ff521ae..5cae598 100644 --- a/parse_test.go +++ b/parse_test.go @@ -911,6 +911,25 @@ func TestEmbeddedPtrIgnored(t *testing.T) { } func TestEmbeddedWithDuplicateField(t *testing.T) { + // see https://github.com/alexflint/go-arg/issues/100 + type T struct { + A string `arg:"--cat"` + } + type U struct { + A string `arg:"--dog"` + } + var args struct { + T + U + } + + err := parse("--cat=cat --dog=dog", &args) + require.NoError(t, err) + assert.Equal(t, "cat", args.T.A) + assert.Equal(t, "dog", args.U.A) +} + +func TestEmbeddedWithDuplicateField2(t *testing.T) { // see https://github.com/alexflint/go-arg/issues/100 type T struct { A string @@ -923,8 +942,10 @@ func TestEmbeddedWithDuplicateField(t *testing.T) { U } - err := parse("", &args) + err := parse("--a=xyz", &args) require.NoError(t, err) + assert.Equal(t, "xyz", args.T.A) + assert.Equal(t, "", args.U.A) } func TestEmptyArgs(t *testing.T) {