-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy patht.formatters_test.go
50 lines (40 loc) · 1.22 KB
/
t.formatters_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
package docxplate_test
import (
"fmt"
"strings"
"testing"
"github.com/bobiverse/docxplate"
)
func TestFormatters(t *testing.T) {
filenames := []string{
"formatters.docx",
}
for _, fname := range filenames {
tdoc, _ := docxplate.OpenTemplate("test-data/" + fname)
tdoc.Params(map[string]any{"Name": "Lorem ipsum"})
if err := tdoc.ExportDocx("test-data/~test-" + fname); err != nil {
t.Fatalf("[%s] ExportDocx: %s", fname, err)
}
plaintext := tdoc.Plaintext()
// Default
if !strings.Contains(plaintext, "This is Lorem ipsum.") {
t.Fatalf("[%s] ExportDocx: %s", fname, "no formatter failed")
}
// Lowercase
if !strings.Contains(plaintext, "Lowercase: `lorem ipsum`") {
fmt.Println(tdoc.Plaintext())
t.Fatalf("[%s] ExportDocx: %s", fname, "Lowercase failed")
}
// Capitalize
if !strings.Contains(plaintext, "Capitalize: `Lorem ipsum`") {
fmt.Println(tdoc.Plaintext())
t.Fatalf("[%s] ExportDocx: %s", fname, "Capitalize failed")
}
// Title: `Lorem Ipsum`
if !strings.Contains(plaintext, "Title: `Lorem Ipsum`") {
fmt.Println(tdoc.Plaintext())
t.Fatalf("[%s] ExportDocx: %s", fname, "Title: `Lorem Ipsum` failed")
}
// success: just needs to be parsed without errors
}
}