-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_test.go
57 lines (51 loc) · 1.29 KB
/
csv_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
package csv
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseRGBColor(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
input string
wantErr bool
wantOutput [][]string
}{
{
name: "parsing a single csv line should succeed",
input: "abc,def,ghi\r\n",
wantErr: false,
wantOutput: [][]string{{"abc", "def", "ghi"}},
},
{
name: "parsing multie csv lines should succeed",
input: "abc,def,ghi\r\njkl,mno,pqr\r\n",
wantErr: false,
wantOutput: [][]string{
{"abc", "def", "ghi"},
{"jkl", "mno", "pqr"},
},
},
{
name: "parsing a single csv line of escaped strings should succeed",
input: "\"abc\",\"def\",\"ghi\"\r\n",
wantErr: false,
wantOutput: [][]string{{"abc", "def", "ghi"}},
},
}
for _, tc := range testCases {
tc := tc // this is needed for t.Parallel() to work correctly (or the same test case will be executed N times)
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
gotOutput, gotErr := ParseCSV(tc.input)
if (gotErr != nil) != tc.wantErr {
t.Errorf("got error %v, want error %v", gotErr, tc.wantErr)
}
assert.Equal(t,
tc.wantOutput,
gotOutput,
"got output %v, want output %v", gotOutput, tc.wantOutput,
)
})
}
}