-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathencode_test.go
44 lines (40 loc) · 989 Bytes
/
encode_test.go
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
package easycsv
import (
"bytes"
"strings"
"testing"
)
func TestConverterInt(t *testing.T) {
r := NewReader(bytes.NewBufferString("10,0xff,017"))
var got []int
ok := r.Read(&got)
if !ok {
t.Fatal("Read returned false unexpectedly")
}
want := []int{10, 255, 15}
noDiff(t, "Read()", got, want)
}
func TestConverterInvalidWithSlice(t *testing.T) {
r := NewReader(bytes.NewBufferString("hello"))
var row []int
ok := r.Read(&row)
if ok {
t.Error("Read returned true unexpectedly")
}
if err := r.Done(); err == nil || !strings.Contains(err.Error(), "parsing \"hello\"") {
t.Errorf("Unexpected error: %v", err)
}
}
func TestConverterInvalidWithStruct(t *testing.T) {
r := NewReader(bytes.NewBufferString("hello"))
var row struct {
Int int `index:"0"`
}
ok := r.Read(&row)
if ok {
t.Error("Read returned true unexpectedly")
}
if err := r.Done(); err == nil || !strings.Contains(err.Error(), "parsing \"hello\"") {
t.Errorf("Unexpected error: %v", err)
}
}