forked from tealeg/xlsx2csv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
72 lines (68 loc) · 1.71 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"testing"
)
func TestGenerateCSVFromXLSXFile(t *testing.T) {
var sheetIndex int
var excelFileName string
var csv []string
var index int
var testOutputer = func(s string) {
csv[index] = s
index++
}
index = 0
csv = make([]string, 2)
sheetIndex = 0
excelFileName = "testfile.xlsx"
error := generateCSVFromXLSXFile(excelFileName, sheetIndex, testOutputer)
if error != nil {
t.Error(error.Error())
}
if len(csv) != 2 {
t.Error("Expected len(csv) == 2")
}
rowString1 := csv[0]
if rowString1 != "\"Foo\";\"Bar\"\n" {
t.Error(`Expected rowString1 == "Foo";"Bar"\n but got `, rowString1)
}
rowString2 := csv[1]
if rowString2 != "\"Baz \";\"Quuk\"\n" {
t.Error(`Expected rowString2 == "Baz ";"Quuk"\n but got `, rowString2)
}
}
func TestGenerateCSVFromXLSXFileWithEmptyCells(t *testing.T) {
var sheetIndex int
var excelFileName string
var csv []string
var csvlen int
var index int
var testOutputer = func(s string) {
csv[index] = s
index++
}
index = 0
csv = make([]string, 3)
sheetIndex = 0
excelFileName = "testfile2.xlsx"
error := generateCSVFromXLSXFile(excelFileName, sheetIndex, testOutputer)
if error != nil {
t.Error(error.Error())
}
csvlen = len(csv)
if csvlen != 3 {
t.Error("Expected len(csv) == 3, but got", csvlen)
}
rowString1 := csv[0]
if rowString1 != "\"Bob\";\"Alice\";\"Sue\"\n" {
t.Error(`Expected rowString1 == "Bob";"Alice";Sue"\n but got `, rowString1)
}
rowString2 := csv[1]
if rowString2 != "\"Yes\";\"No\";\"Yes\"\n" {
t.Error(`Expected rowString2 == "Yes";"No";"Yes"\n but got `, rowString2)
}
rowString3 := csv[2]
if rowString3 != "\"No\";\"\";\"Yes\"\n" {
t.Error(`Expected rowString2 == "No";"";"Yes"\n but got `, rowString3)
}
}