-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcsv_test.go
More file actions
53 lines (41 loc) · 953 Bytes
/
csv_test.go
File metadata and controls
53 lines (41 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package csv
import (
"fmt"
"reflect"
"testing"
)
type simple struct {
Name string `csv:"FullName"`
Gender string
private int `csv:"-"`
Ignore string `csv:"-"`
Age int
}
func TestHeader(t *testing.T) {
x := reflect.TypeOf(simple{})
// Get the header when defined via a tag
f, _ := x.FieldByName("Name")
h, _ := fieldHeaderName(f)
if h != "FullName" {
t.Error("header does not match")
}
// Use the field FullName when there is no tag
f, _ = x.FieldByName("Gender")
h, _ = fieldHeaderName(f)
if h != "Gender" {
t.Error("Default header FullName not created")
}
// Get the header when defined via a tag
f, _ = x.FieldByName("Ignore")
_, ok := fieldHeaderName(f)
if ok == true {
t.Error("Omitted field returned ok")
}
}
func TestHeaders(t *testing.T) {
x := reflect.TypeOf(simple{})
hh := colNames(x)
if "[FullName Gender Age]" != fmt.Sprintf("%v", hh) {
t.Errorf("Incorrected headers: %v", hh)
}
}