-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy pathcsv_test.go
More file actions
37 lines (34 loc) · 1020 Bytes
/
csv_test.go
File metadata and controls
37 lines (34 loc) · 1020 Bytes
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
package parser
import (
"reflect"
"testing"
)
func TestSplitAndTrimCSV(t *testing.T) {
tests := []struct {
name string
input string
want []string
}{
{"empty string", "", nil},
{"only separators", ",,,", []string{}},
{"only whitespace between separators", " , , ,", []string{}},
{"single value", "a", []string{"a"}},
{"trims surrounding whitespace", " a , b ", []string{"a", "b"}},
{"drops empty segments", "a, ,b", []string{"a", "b"}},
{"preserves inner colons", "host1:6379, host2:6379", []string{"host1:6379", "host2:6379"}},
{"trailing comma", "a,b,", []string{"a", "b"}},
{"leading comma", ",a,b", []string{"a", "b"}},
{"tabs and mixed whitespace", "\ta\t,\nb\n", []string{"a", "b"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := SplitAndTrimCSV(tt.input)
if len(got) == 0 && len(tt.want) == 0 {
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("SplitAndTrimCSV(%q) = %#v, want %#v", tt.input, got, tt.want)
}
})
}
}