-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions_test.go
More file actions
58 lines (51 loc) · 1.12 KB
/
functions_test.go
File metadata and controls
58 lines (51 loc) · 1.12 KB
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
package docxtpl
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRegisterFunctions(t *testing.T) {
tests := []struct {
name string
fnName string
fn any
expectError bool
}{
{
name: "Valid function",
fnName: "validFunction",
fn: func(text string) string {
return "Hello"
},
expectError: false,
},
{
name: "Invalid function name",
fnName: "",
fn: nil,
expectError: true,
},
{
name: "Invalid function signature",
fnName: "validFunction",
fn: "not a valid function",
expectError: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
doc, err := ParseFromFilename("test_templates/test_basic.docx")
assert.Nil(err)
err = doc.RegisterFunction(tt.fnName, tt.fn)
assert.Equal((err != nil), tt.expectError)
funcMap := doc.GetRegisteredFunctions()
_, foundInFunctionMap := (*funcMap)[tt.fnName]
if !tt.expectError {
assert.True(foundInFunctionMap)
}
if tt.expectError {
assert.False(foundInFunctionMap)
}
})
}
}