From d42e876eba4300228c39e9323c1df5043c77be98 Mon Sep 17 00:00:00 2001 From: Jacek Szwec Date: Tue, 25 Feb 2020 22:33:58 -0500 Subject: [PATCH] Support inline tag in Header function --- csvutil.go | 2 +- csvutil_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/csvutil.go b/csvutil.go index 023aec5..f86b2a9 100644 --- a/csvutil.go +++ b/csvutil.go @@ -185,7 +185,7 @@ func Header(v interface{}, tag string) ([]string, error) { fields := cachedFields(typeKey{tag, typ}) h := make([]string, len(fields)) for i, f := range fields { - h[i] = f.tag.name + h[i] = f.name } return h, nil } diff --git a/csvutil_test.go b/csvutil_test.go index 1a2b590..fa6de2e 100644 --- a/csvutil_test.go +++ b/csvutil_test.go @@ -661,6 +661,36 @@ func TestHeader(t *testing.T) { tag: "csv", header: []string{"Y"}, }, + { + desc: "inline - simple", + v: &Inline{}, + tag: "csv", + header: []string{ + "int", + "Bool", + "Uint8", + "float", + "prefix-STR", + "prefix-int", + "prefix-Bool", + "prefix-Uint8", + "prefix-float", + "top-string", + "STR", + }, + }, + { + desc: "inline - chain", + v: &Inline5{}, + tag: "csv", + header: []string{"AS", "AAA", "S", "A"}, + }, + { + desc: "inline - top level", + v: &Inline8{}, + tag: "csv", + header: []string{"AA"}, + }, { desc: "nil ptr of TypeF", v: nilPtr,