-
Notifications
You must be signed in to change notification settings - Fork 1
/
docx_test.go
50 lines (33 loc) · 1.19 KB
/
docx_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
package textract
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestReadMissingFile(t *testing.T) {
text, err := RetrieveTextFromFile("testdats/thisfiledoesntexist")
assert.Equal(t, "", text, "Reading a non-existent file should return empty string")
assert.NotNil(t, err, "Error expected reading a non-existent file")
}
func TestReadEmptyMSDocx(t *testing.T) {
text, err := RetrieveTextFromFile("testdats/empty.docx")
text = strings.TrimSpace(text)
assert.Equal(t, "", text, "Reading an empty file should return empty string")
assert.Nil(t, err, "Nil error expected")
}
func TestReadMSDocxSample1(t *testing.T) {
const correct = `P1PLAIN-1234567890 EOL
P1PLAIN-abcdefghijklmnopqrstuvwxyz MIDDLE EOL
P1BOLD-1234567890 EOL
P2BOLD-abcdefghijklmnopqrstuvwxyz
P2ITALIC-1234567890
P2ITALIC-abcdefghijklmnopqrstuvwxyz
P3UNDERSCORE-1234567890
P3UNDERSCORE-abcdefghijklmnopqrstuvwxyz
P3BOLD-ITALIC-1234567890
P4BOLD-ITALIC-abcdefghijklmnopqrstuvwxyz`
text, err := RetrieveTextFromFile("testdats/sample1.docx")
text = strings.TrimSpace(text)
assert.Equal(t, correct, text, "Reading an empty file should return empty string")
assert.Nil(t, err, "Nil error expected")
}