-
Notifications
You must be signed in to change notification settings - Fork 2
/
ppt_test.go
76 lines (69 loc) · 1.33 KB
/
ppt_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
package goppt_test
import (
"bytes"
"embed"
"errors"
"io"
"strings"
"testing"
"github.com/KSpaceer/goppt"
)
//go:embed testdata
var testdataFS embed.FS
const (
simplePresPath = "testdata/simplepres.ppt"
)
func TestExtractText(t *testing.T) {
type tcase struct {
name string
r io.Reader
expectedText string
expectErr error
}
tcases := []tcase{
{
name: "simple reader at",
r: func() io.Reader {
f, err := testdataFS.Open(simplePresPath)
if err != nil {
panic(err)
}
t.Cleanup(func() {
f.Close()
})
return f
}(),
expectedText: "12345",
},
{
name: "simple no reader at",
r: func() io.Reader {
f, err := testdataFS.Open(simplePresPath)
if err != nil {
panic(err)
}
defer f.Close()
data, err := io.ReadAll(f)
if err != nil {
panic(err)
}
return bytes.NewBuffer(data)
}(),
expectedText: "12345",
},
}
for _, tc := range tcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
text, err := goppt.ExtractText(tc.r)
if !errors.Is(err, tc.expectErr) {
t.Fatalf("expected error %v, but got %v", tc.expectErr, err)
}
text = strings.TrimSpace(text)
expected := strings.TrimSpace(tc.expectedText)
if text != expected {
t.Fatalf("expected text %q, but got %q", expected, text)
}
})
}
}