forked from pcarleton/sheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspreadsheet_test.go
40 lines (35 loc) · 874 Bytes
/
spreadsheet_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
package sheets
import (
"strings"
"testing"
)
var tsvTests = []struct {
data string
result [][]string
}{
{"a\tb", [][]string{[]string{"a", "b"}}},
{"a\tb\tc\nd\te\tf", [][]string{
[]string{"a", "b", "c"},
[]string{"d", "e", "f"},
}},
}
func TestTsvToArr(t *testing.T) {
for _, tt := range tsvTests {
got := TsvToArr(strings.NewReader(tt.data), "\t")
if len(got) != len(tt.result) {
t.Errorf("For \n%s\n, mismatched rows. wanted %v, but got %v", tt.data, tt.result, got)
}
for i, row := range got {
wantRow := tt.result[i]
if len(row) != len(wantRow) {
t.Errorf("For \n%s\n row %d, mismatched cols. wanted %v, but got %v", tt.data, i, wantRow, row)
break
}
for j, cell := range row {
if cell != wantRow[j] {
t.Errorf("For \n%s\n [%d][%d], wanted %v, but got %v", tt.data, i, j, wantRow[j], cell)
}
}
}
}
}