-
Notifications
You must be signed in to change notification settings - Fork 6
/
doc_test.go
107 lines (69 loc) · 1.54 KB
/
doc_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package doc2txt
import (
"bytes"
"os"
"strings"
"testing"
)
func TestParseSimpleDoc(t *testing.T) {
f, _ := os.Open(`testData/simpleDoc.doc`)
buf, err := ParseDoc(f)
if err != nil {
t.Fatal("expected successful parse", err)
}
if s := buf.(*bytes.Buffer).String(); s != "12345\r" {
t.Errorf("expected correct value |%s|", s)
}
}
func TestParseComplicated(t *testing.T) {
f, _ := os.Open(`testData/docFile.doc`)
buf, err := ParseDoc(f)
if err != nil {
t.Fatal("expected to be able to parse document", err)
}
var expected bytes.Buffer
expected.WriteString(strings.Replace(complicatedDoc, "\n", "\r", -1))
actual := buf.(*bytes.Buffer)
count := 0
for aline, err := actual.ReadString('\r'); err == nil; aline, err = actual.ReadString('\r') {
eline, err := expected.ReadString('\r')
if err != nil || eline != aline {
t.Errorf("mismatch at line %d. Expected: %s, Actual: %s\n", count, eline, aline)
}
count++
}
}
const complicatedDoc = `Name Here in Big
Link to something
Summary
Testing out new things
Bullet 1
Bullet 2
Bullet 3
Underlined
Italics
Numbered list
Item 1
Item 2
Item 3
Some Information In a Table Hopefully, we get it
Here is some information with a footnote
Here is some information with an endnote
Here is a table of contents
Contents
Some 1
Information 1
In a 1
Table 1
Hopefully, we 1
get it 1
1
Header 1
Header 2
Header 3
Here is my footnote
Information in the header
Some Footer information current date:8/7/2017 4:16:33 PM pg. 1
My endnote
Some info from inside a text box
`