forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailmerge_test.go
88 lines (86 loc) · 1.96 KB
/
mailmerge_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
77
78
79
80
81
82
83
84
85
86
87
88
package document
import (
"testing"
)
func TestParseMergeField(t *testing.T) {
td := []struct {
instruction string
exp mergeFieldInfo
}{
{
`MERGEFIELD FirstName \f " "`,
mergeFieldInfo{
fieldName: "FirstName",
followText: " ",
},
},
{
`MERGEFIELD FirstName`,
mergeFieldInfo{
fieldName: "FirstName",
},
},
{
`MERGEFIELD FirstName \f "after" \b "before"`,
mergeFieldInfo{
fieldName: "FirstName",
followText: "after",
beforeText: "before",
},
},
{
`MERGEFIELD FirstName \* Upper`,
mergeFieldInfo{
fieldName: "FirstName",
upper: true,
},
},
{
`MERGEFIELD FirstName \* Lower`,
mergeFieldInfo{
fieldName: "FirstName",
lower: true,
},
},
{
`MERGEFIELD FirstName \* Caps`,
mergeFieldInfo{
fieldName: "FirstName",
caps: true,
},
},
{
`MERGEFIELD FirstName \* FirstCap`,
mergeFieldInfo{
fieldName: "FirstName",
firstCap: true,
},
},
}
for _, tc := range td {
t.Run(tc.instruction, func(t *testing.T) {
parsed := parseField(tc.instruction)
if parsed.fieldName != tc.exp.fieldName {
t.Errorf("expected fieldName = %s, got %s", tc.exp.fieldName, parsed.fieldName)
}
if parsed.followText != tc.exp.followText {
t.Errorf("expected followText = %s, got %s", tc.exp.followText, parsed.followText)
}
if parsed.beforeText != tc.exp.beforeText {
t.Errorf("expected beforeText = %s, got %s", tc.exp.beforeText, parsed.beforeText)
}
if parsed.upper != tc.exp.upper {
t.Errorf("expected upper = %v, got %v", tc.exp.upper, parsed.upper)
}
if parsed.lower != tc.exp.lower {
t.Errorf("expected lower = %v, got %v", tc.exp.lower, parsed.lower)
}
if parsed.caps != tc.exp.caps {
t.Errorf("expected caps = %v, got %v", tc.exp.caps, parsed.caps)
}
if parsed.firstCap != tc.exp.firstCap {
t.Errorf("expected firstCap = %v, got %v", tc.exp.firstCap, parsed.firstCap)
}
})
}
}