-
Notifications
You must be signed in to change notification settings - Fork 21
/
shared_strings_test.go
53 lines (41 loc) · 1.35 KB
/
shared_strings_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
package xlsxreader
import (
"archive/zip"
"testing"
"github.com/stretchr/testify/require"
)
func TestGetSharedStringsFile(t *testing.T) {
zipFiles := []*zip.File{
{FileHeader: zip.FileHeader{Name: "Bill"}},
{FileHeader: zip.FileHeader{Name: "xl/SharedStrings.xml"}},
{FileHeader: zip.FileHeader{Name: "Bob"}},
}
file, err := getSharedStringsFile(zipFiles)
require.NoError(t, err)
require.Equal(t, zipFiles[1], file)
}
func TestNoErrorReturnedIfNoSharedStringsFile(t *testing.T) {
actual, err := getSharedStrings([]*zip.File{})
require.NoError(t, err)
require.Equal(t, actual, []string{})
}
var sharedStringsTests = map[string]string{
"Simple shared strings": "./test/test-shared-strings.xlsx",
"Shared strings with spurious element location": "./test/test-shared-strings-with-r-element.xlsx",
}
func TestLoadingSharedStrings(t *testing.T) {
for name, filename := range sharedStringsTests {
t.Run(name, func(t *testing.T) {
actual, err := OpenFile(filename)
require.NoError(t, err)
defer actual.Close()
require.Equal(t, []string{"rec_id", "culture", "sex"}, actual.sharedStrings)
})
}
t.Run("bold", func(t *testing.T) {
actual, err := OpenFile("./test/test-bold.xlsx")
require.NoError(t, err)
defer actual.Close()
require.Equal(t, []string{"Contact ID", "Phone Number"}, actual.sharedStrings)
})
}