forked from ymotongpoo/goltsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_test.go
59 lines (55 loc) · 1.09 KB
/
reader_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
package goltsv
import (
"bytes"
"io"
"reflect"
"testing"
)
var readTests = []struct {
str string
records interface{}
}{
{
`
hoge:foo bar:baz
perl:5.17.8 ruby:2.0 python:2.6
sushi:寿司 tennpura:天ぷら ramen:ラーメン gyoza:餃子
`,
[]map[string]string{
{"hoge": "foo", "bar": "baz"},
{"perl": "5.17.8", "ruby": "2.0", "python": "2.6"},
{"sushi": "寿司", "tennpura": "天ぷら", "ramen": "ラーメン", "gyoza": "餃子"},
},
},
}
func TestRead(t *testing.T) {
n := 0
reader := NewReader(bytes.NewBufferString(readTests[0].str))
for {
_, e := reader.Read()
if e != nil {
if e != io.EOF {
t.Errorf("expected Read got %v", e)
}
break
}
n++
}
if n != 3 {
t.Errorf("expected 3 records got %v", n)
}
}
func TestReadAll(t *testing.T) {
for _, w := range readTests {
reader := NewReader(bytes.NewBufferString(w.str))
records, e := reader.ReadAll()
if e != nil {
t.Errorf("expected Read got %v", e)
continue
}
if reflect.DeepEqual(records, w.records) == false {
t.Errorf("expected %v but %v", w.records, records)
continue
}
}
}