-
Notifications
You must be signed in to change notification settings - Fork 1
/
catdoc_test.go
80 lines (68 loc) · 2.13 KB
/
catdoc_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
73
74
75
76
77
78
79
80
package gocatdoc_test
import (
gocatdoc "github.com/semvis123/go-catdoc"
"io"
"os"
"testing"
)
func TestVersion(t *testing.T) {
version, err := gocatdoc.GetVersion()
if err != nil {
t.Fatalf("expected error to be nil, got %v", err)
}
if version != "Catdoc Version 0.95" {
t.Fatalf("expected version to be \"Catdoc Version 0.95\", got %v", version)
}
}
func testFileFunc(title, expected string, fun func(io.ReadSeeker) (string, error), t *testing.T) {
f, err := os.Open("test.doc")
if err != nil {
t.Fatalf("could not open test document, %v", err)
}
text, err := fun(f)
if err != nil {
t.Fatalf("expected error to be nil, got %v", err)
}
if text != expected {
t.Fatalf("expected %s to be \"%s\", got %v", title, expected, text)
}
}
func testFileFuncArr(title string, expected []string, fun func(io.ReadSeeker) ([]string, error), t *testing.T) {
f, err := os.Open("test.doc")
if err != nil {
t.Fatalf("could not open test document, %v", err)
}
arr, err := fun(f)
if err != nil {
t.Fatalf("expected error to be nil, got %v", err)
}
for i := range expected {
if arr[i] != expected[i] {
t.Fatalf("expected %s to be \"%v\", got %v", title, expected, arr)
}
}
}
func TestGetTextFromFile(t *testing.T) {
testFileFunc("text", "text-inside-doc", gocatdoc.GetTextFromFile, t)
}
func TestGetAuthorFromFile(t *testing.T) {
testFileFunc("author", "H. Potter", gocatdoc.GetAuthorFromFile, t)
}
func TestGetLastAuthorFromFile(t *testing.T) {
testFileFunc("last author", "H. Potter", gocatdoc.GetLastAuthorFromFile, t)
}
func TestGetTitleFromFile(t *testing.T) {
testFileFunc("title", "Title", gocatdoc.GetTitleFromFile, t)
}
func TestGetSubjectFromFile(t *testing.T) {
testFileFunc("subject", "Subject", gocatdoc.GetSubjectFromFile, t)
}
func TestGetKeywordsFromFile(t *testing.T) {
testFileFunc("keywords", "Keywords", gocatdoc.GetKeywordsFromFile, t)
}
func TestGetCommentsFromFile(t *testing.T) {
testFileFunc("comments", "Comments", gocatdoc.GetCommentsFromFile, t)
}
func TestGetAnnotationAuthorsFromFile(t *testing.T) {
testFileFuncArr("annoation_authors", []string{"H. Potter"}, gocatdoc.GetAnnotationAuthorsFromFile, t)
}