Skip to content

Commit

Permalink
Support inline tag in Header function
Browse files Browse the repository at this point in the history
  • Loading branch information
jszwec committed Feb 26, 2020
1 parent a47c010 commit d42e876
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion csvutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
30 changes: 30 additions & 0 deletions csvutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d42e876

Please sign in to comment.