-
Notifications
You must be signed in to change notification settings - Fork 0
/
size_test.go
67 lines (59 loc) · 1.03 KB
/
size_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package csvutil
import (
"bytes"
"io/ioutil"
"testing"
)
func BenchmarkSize(b *testing.B) {
p, err := ioutil.ReadFile("testdata/bench.csv")
if err != nil {
b.Fatal(err)
}
for i := 0; i < b.N; i++ {
r := bytes.NewBuffer(p)
o := SizeOption{}
Size(r, o)
}
}
func TestSizeWithEmptyCSV(t *testing.T) {
s := ""
r := bytes.NewBufferString(s)
o := SizeOption{}
actual, err := Size(r, o)
if err != nil {
t.Fatal(err)
}
expected := 0
if actual != expected {
t.Fatalf("Expectd: %d, but got %d", expected, actual)
}
}
func TestSizeWithBrokenCSV(t *testing.T) {
s := `a"aa,bbb,ccc
1,2,3
4,5
7,8,9
`
r := bytes.NewBufferString(s)
o := SizeOption{}
if _, err := Size(r, o); err == nil {
t.Fatal("Size with broken csv should raise error.")
}
}
func TestSize(t *testing.T) {
s := `aaa,bbb,ccc
1,2,3
4,5,6
7,8,9
`
r := bytes.NewBufferString(s)
o := SizeOption{}
actual, err := Size(r, o)
if err != nil {
t.Fatal(err)
}
expected := 3
if actual != expected {
t.Fatalf("Expectd: %d, but got %d", expected, actual)
}
}