-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcsv4g_test.go
More file actions
62 lines (58 loc) · 1.24 KB
/
csv4g_test.go
File metadata and controls
62 lines (58 loc) · 1.24 KB
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
54
55
56
57
58
59
60
61
62
package csv4g
import (
"fmt"
"testing"
)
type Test struct {
Id int
Name string
Desc string
Go string
Num float32
Foo bool
SliceInt []int
SliceFloat32 []float32 `csv:"sliceFloat32"`
IgnoreField string `csv:"-"`
CustomField string `csv:"custom,omitempty"`
EmptyField string `csv:"omitempty"`
}
func TestParse(t *testing.T) {
testFiles := []string{"test.csv", "test_empty.csv"}
for _, testFile := range testFiles {
csv, err := New(testFile, ',', true, Test{}, 1)
if err != nil {
t.Errorf("Error %v\n", err)
return
}
// fmt.Println(csv)
for i := 0; i < csv.LineLen; i++ {
tt := &Test{}
err = csv.Parse(tt)
if err != nil {
t.Errorf("%v\n", err)
break
}
fmt.Println(tt)
}
}
}
func TestParseWithOptions(t *testing.T) {
testFiles := []string{"test.csv", "test_empty.csv"}
for _, testFile := range testFiles {
csv, err := NewWithOpts(testFile, Test{}, Comma(','), LazyQuotes(true), SkipLine(1))
if err != nil {
t.Errorf("Error %v\n", err)
return
}
// fmt.Println(csv)
for i := 0; i < csv.LineLen; i++ {
tt := &Test{}
err = csv.Parse(tt)
if err != nil {
t.Errorf("%v\n", err)
break
}
fmt.Println(tt)
}
}
}