-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathmain_test.go
51 lines (47 loc) · 1.02 KB
/
main_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
// Copyright 2011-2015, The xlsx2csv Authors.
// All rights reserved.
// For details, see the LICENSE file.
package main
import (
"bytes"
"encoding/csv"
"strings"
"testing"
)
func TestGenerateCSVFromXLSXFile(t *testing.T) {
var testOutput bytes.Buffer
for i, tc := range []struct {
excelFileName string
sheetIndex int
await string
}{
{"testdata/testfile.xlsx", 0, `Foo;Bar
Baz ;Quuk
`},
{"testdata/testfile2.xlsx", 0, `Bob;Alice;Sue
Yes;No;Yes
No;;Yes
`},
} {
testOutput.Reset()
if err := generateCSVFromXLSXFile(
&testOutput,
tc.excelFileName,
tc.sheetIndex,
func(cw *csv.Writer) { cw.Comma = ';' },
); err != nil {
t.Error(err)
}
awaited := strings.Split(tc.await, "\n")
got := strings.Split(testOutput.String(), "\n")
if len(got) != len(awaited) {
t.Errorf("%d. Expected len(csv) == %d, got %d.", i, len(awaited), len(got))
continue
}
for j, aw := range awaited {
if aw != got[j] {
t.Errorf(`%d. Expected line %d == %q, but got %q`, i, j, aw, got[j])
}
}
}
}