Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bobiverse committed Jul 11, 2024
1 parent 2622f51 commit 8471272
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions t.formatters_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
}
Binary file added test-data/formatters.docx
Binary file not shown.

0 comments on commit 8471272

Please sign in to comment.