-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
input_text_test.go
101 lines (98 loc) · 1.98 KB
/
input_text_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package trdsql
import (
"io"
"path/filepath"
"reflect"
"strings"
"testing"
)
func TestNewTextReader(t *testing.T) {
type args struct {
reader io.Reader
opts *ReadOpts
}
tests := []struct {
name string
args args
}{
{
name: "test1",
args: args{
reader: strings.NewReader("a\nb\nc\n"),
opts: NewReadOpts(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewTextReader(tt.args.reader, tt.args.opts)
if err != nil {
t.Fatal(err)
}
names, err := got.Names()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(names, []string{"text"}) {
t.Errorf("TextReader.Names() != text %v", names)
}
types, err := got.Types()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(types, []string{"text"}) {
t.Errorf("TextReader.Types() != text %v", types)
}
})
}
}
func TestTextReaderFile(t *testing.T) {
tests := []struct {
name string
fileName string
opts *ReadOpts
want []any
wantErr bool
}{
{
name: "test.csv",
fileName: "test.csv",
opts: NewReadOpts(),
want: []any{"1,Orange"},
wantErr: false,
},
{
name: "test.csv2",
fileName: "test.csv",
opts: &ReadOpts{InSkip: 1},
want: []any{"2,Melon"},
wantErr: false,
},
{
name: "test.csv3",
fileName: "test.csv",
opts: &ReadOpts{InLimitRead: true, InPreRead: 1},
want: []any{"1,Orange"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
file, err := singleFileOpen(filepath.Join(dataDir, tt.fileName))
if err != nil {
t.Error(err)
}
r, err := NewTextReader(file, tt.opts)
if err != nil {
t.Fatal(err)
}
got, err := r.ReadRow(nil)
if (err != nil) != tt.wantErr {
t.Errorf("TextReader.ReadRow() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("TextReader.ReadRow() = %v, want %v", got, tt.want)
}
})
}
}