aboutsummaryrefslogtreecommitdiff
path: root/internal/extract/real_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/extract/real_test.go')
-rw-r--r--internal/extract/real_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/internal/extract/real_test.go b/internal/extract/real_test.go
new file mode 100644
index 0000000..fd52f81
--- /dev/null
+++ b/internal/extract/real_test.go
@@ -0,0 +1,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)
+ }
+ })
+ }
+}