-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencoder_test.go
More file actions
41 lines (37 loc) · 941 Bytes
/
Copy pathencoder_test.go
File metadata and controls
41 lines (37 loc) · 941 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
package csv_test
import (
"bytes"
"testing"
"github.com/vincbro/csv"
)
func TestEncodeStrings(t *testing.T) {
buf := bytes.NewBufferString("")
encoder := csv.NewEncoder(buf)
str := "Sesame"
s := &struct {
Name string `csv:"name"`
Email string `csv:"email"`
Age int `csv:"age"`
StreetName *string `csv:"street_name"`
StreetNumber int `csv:"street_number"`
sendEmail bool `csv:"send_email"`
Subscribed bool `csv:"subscribed"`
}{
Name: "John Doe",
Email: "john.doe@example.com",
Age: 21,
StreetName: &str,
StreetNumber: 910,
sendEmail: true,
Subscribed: true,
}
if err := encoder.Encode(s); err != nil {
t.Logf("Failed to encode struct, err:%s\n", err.Error())
t.Fail()
}
if err := encoder.Flush(); err != nil {
t.Logf("Failed to flush writer, err:%s\n", err.Error())
t.Fail()
}
t.Logf("\n%s\n", buf.String())
}