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
|
// SPDX-License-Identifier: GPL-3.0-or-later
package extract
import (
"os"
"path/filepath"
"strings"
"testing"
)
// TestRealDocuments reads documents made by the programs people use -
// LibreOffice 25.2 (docx, odt, doc, pdf, ods, xlsx, xls) and pandoc (pptx,
// epub) - from invented text, not ones built by hand in a test (triage
// 34s). The zip formats always run; a format that needs an external tool
// runs when that tool is installed and is skipped otherwise.
func TestRealDocuments(t *testing.T) {
e := newWithPath(os.Getenv("PATH"))
found := map[string]bool{}
for _, tool := range e.Tools() {
found[tool.Name] = tool.Path != ""
}
for _, c := range []struct {
file string
tools []string // any one of them will do; none means Go reads it
want string
}{
{"doc.docx", nil, "acme ltd"},
{"doc.odt", nil, "acme ltd"},
{"sheet.ods", nil, "acme ltd"},
{"sheet.xlsx", nil, "acme ltd"},
{"slides.pptx", nil, "acme ltd"},
{"book.epub", nil, "acme ltd"},
{"doc.pdf", []string{"pdftotext"}, "acme ltd"},
{"doc.doc", []string{"antiword", "catdoc"}, "acme ltd"},
{"sheet.xls", []string{"xls2csv"}, "acme ltd"},
} {
t.Run(c.file, func(t *testing.T) {
if len(c.tools) > 0 {
ok := false
for _, tool := range c.tools {
ok = ok || found[tool]
}
if !ok {
t.Skipf("none of %v installed", c.tools)
}
}
got, err := text(t, e, filepath.Join("testdata", "real", c.file), 0)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(got, c.want) {
t.Errorf("text of %s lacks %q:\n%q", c.file, c.want, got)
}
})
}
}
|